Skip to content

Commit

Permalink
Parse the InsecureRegistry env variable with comma separated values
Browse files Browse the repository at this point in the history
Signed-off-by: Domenico Luciani <[email protected]>
  • Loading branch information
Domenico Luciani committed Aug 7, 2023
1 parent ea8c5f0 commit 2e00258
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion platform/lifecycle_inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewLifecycleInputs(platformAPI *api.Version) *LifecycleInputs {
PlatformAPI: platformAPI,
ExtendKind: envOrDefault(EnvExtendKind, DefaultExtendKind),
UseDaemon: boolEnv(EnvUseDaemon),
InsecureRegistries: nil,
InsecureRegistries: sliceEnv(EnvInsecureRegistry),
UseLayout: boolEnv(EnvUseLayout),

// Provided by the base image
Expand Down Expand Up @@ -251,6 +251,14 @@ func envOrDefault(key string, defaultVal string) string {
return defaultVal
}

func sliceEnv(k string) str.Slice {
envVal := os.Getenv(k)
if envVal != "" {
return strings.Split(strings.ReplaceAll(envVal, " ", ""), ",")
}
return str.Slice(nil)
}

func intEnv(k string) int {
v := os.Getenv(k)
d, err := strconv.Atoi(v)
Expand Down
8 changes: 6 additions & 2 deletions platform/lifecycle_inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func testLifecycleInputs(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, os.Setenv(platform.EnvUID, "1234"))
h.AssertNil(t, os.Setenv(platform.EnvUseDaemon, "true"))
h.AssertNil(t, os.Setenv(platform.EnvUseLayout, "true"))
h.AssertNil(t, os.Setenv(platform.EnvInsecureRegistry, "some-insecure-registry"))
h.AssertNil(t, os.Setenv(platform.EnvInsecureRegistry, "some-insecure-registry,another-insecure-registry, just-another-registry"))
})

it.After(func() {
Expand Down Expand Up @@ -175,7 +175,11 @@ func testLifecycleInputs(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, inputs.UID, 1234)
h.AssertEq(t, inputs.UseDaemon, true)
h.AssertEq(t, inputs.UseLayout, true)
h.AssertEq(t, inputs.InsecureRegistries, str.Slice(nil))
h.AssertEq(t, inputs.InsecureRegistries, str.Slice{
"some-insecure-registry",
"another-insecure-registry",
"just-another-registry",
})
})
})

Expand Down

0 comments on commit 2e00258

Please sign in to comment.