Skip to content

Commit 2ec8f55

Browse files
committed
Add PORTER_INSTALLATION_NAME* env for runtime
Signed-off-by: Jeremy Goss <jeremy.goss@hpe.com>
1 parent 2b5dbe7 commit 2ec8f55

4 files changed

Lines changed: 25 additions & 35 deletions

File tree

pkg/cnab/provider/action.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (r *Runtime) ApplyConfig(args ActionArguments) action.OperationConfigs {
5252
return action.OperationConfigs{
5353
r.SetOutput(),
5454
r.AddFiles(args),
55+
r.AddEnvironment(args),
5556
r.AddRelocation(args),
5657
}
5758
}
@@ -84,6 +85,14 @@ func (r *Runtime) AddFiles(args ActionArguments) action.OperationConfigFunc {
8485
}
8586
}
8687

88+
func (r *Runtime) AddEnvironment(args ActionArguments) action.OperationConfigFunc {
89+
return func(op *driver.Operation) error {
90+
op.Environment[config.EnvPorterInstallationNamespace] = args.Installation.Namespace
91+
op.Environment[config.EnvPorterInstallationName] = args.Installation.Name
92+
return nil
93+
}
94+
}
95+
8796
// AddRelocation operates on an ActionArguments and adds any provided relocation mapping
8897
// to the operation's files.
8998
func (r *Runtime) AddRelocation(args ActionArguments) action.OperationConfigFunc {

pkg/config/config.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const (
3535
// EnvDEBUG is a custom porter parameter that signals that --debug flag has been passed through from the client to the runtime.
3636
EnvDEBUG = "PORTER_DEBUG"
3737

38-
// EnvCORRELATION_ID is the name of the environment variable containing the
38+
// EnvCorrelationID is the name of the environment variable containing the
3939
// id to correlate logs with a workflow.
4040
EnvCorrelationID = "PORTER_CORRELATION_ID"
4141

@@ -49,6 +49,14 @@ const (
4949

5050
// ClaimFilepath is the filepath to the claim.json inside of an invocation image
5151
ClaimFilepath = "/cnab/claim.json"
52+
53+
// EnvPorterInstallationNamespace is the name of the environment variable which is injected into the
54+
// invocation image, containing the namespace of the installation.
55+
EnvPorterInstallationNamespace = "PORTER_INSTALLATION_NAMESPACE"
56+
57+
// EnvPorterInstallationName is the name of the environment variable which is injected into the
58+
// invocation image, containing the name of the installation.
59+
EnvPorterInstallationName = "PORTER_INSTALLATION_NAME"
5260
)
5361

5462
// These are functions that afero doesn't support, so this lets us stub them out for tests to set the

pkg/runtime/runtime-manifest.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,11 @@ func (m *RuntimeManifest) loadBundle() error {
8989
}
9090

9191
func (m *RuntimeManifest) GetInstallationNamespace() string {
92-
before, _, found := strings.Cut(m.Getenv(config.EnvInstallationName), "/")
93-
if found {
94-
return before
95-
}
96-
return ""
92+
return m.Getenv(config.EnvPorterInstallationNamespace)
9793
}
9894

9995
func (m *RuntimeManifest) GetInstallationName() string {
100-
before, after, found := strings.Cut(m.Getenv(config.EnvInstallationName), "/")
101-
if found {
102-
return after
103-
}
104-
return before
96+
return m.Getenv(config.EnvPorterInstallationName)
10597
}
10698

10799
func (m *RuntimeManifest) loadDependencyDefinitions() error {

pkg/runtime/runtime-manifest_test.go

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -993,48 +993,29 @@ func TestResolveStepEncoding(t *testing.T) {
993993
assert.Equal(t, flags["c"], wantValue)
994994
}
995995

996-
func TestResolveInstallationName(t *testing.T) {
996+
func TestResolveInstallation(t *testing.T) {
997997
cxt := portercontext.NewTestContext(t)
998-
cxt.Setenv(config.EnvInstallationName, "mybun")
998+
cxt.Setenv(config.EnvPorterInstallationNamespace, "mynamespace")
999+
cxt.Setenv(config.EnvPorterInstallationName, "mybun")
9991000

10001001
m := &manifest.Manifest{}
10011002
rm := NewRuntimeManifest(cxt.Context, cnab.ActionInstall, m)
10021003

10031004
s := &manifest.Step{
10041005
Data: map[string]interface{}{
10051006
"description": "Do a helm release",
1007+
"ns": "{{ installation.namespace }}",
10061008
"release": "{{ installation.name }}",
10071009
},
10081010
}
10091011

10101012
err := rm.ResolveStep(s)
10111013
require.NoError(t, err, "ResolveStep failed")
10121014

1015+
assert.Equal(t, "mynamespace", s.Data["ns"], "installation.namespace was not rendered")
10131016
assert.Equal(t, "mybun", s.Data["release"], "installation.name was not rendered")
10141017
}
10151018

1016-
func TestResolveInstallationNamespace(t *testing.T) {
1017-
cxt := portercontext.NewTestContext(t)
1018-
cxt.Setenv(config.EnvInstallationName, "mynamespace/mybun")
1019-
1020-
m := &manifest.Manifest{}
1021-
rm := NewRuntimeManifest(cxt.Context, cnab.ActionInstall, m)
1022-
1023-
s := &manifest.Step{
1024-
Data: map[string]interface{}{
1025-
"description": "K8s step",
1026-
"resourcenamespace": "{{ installation.namespace }}",
1027-
"resourcename": "{{ installation.name }}",
1028-
},
1029-
}
1030-
1031-
err := rm.ResolveStep(s)
1032-
require.NoError(t, err, "ResolveStep failed")
1033-
1034-
assert.Equal(t, "mynamespace", s.Data["resourcenamespace"], "installation.namespace was not rendered")
1035-
assert.Equal(t, "mybun", s.Data["resourcename"], "installation.name was not rendered")
1036-
}
1037-
10381019
func TestResolveCustomMetadata(t *testing.T) {
10391020
cxt := portercontext.NewTestContext(t)
10401021
m := &manifest.Manifest{

0 commit comments

Comments
 (0)