From 2e00258216d4fcdd1c50a63adbe3db222c96944e Mon Sep 17 00:00:00 2001 From: Domenico Luciani Date: Mon, 7 Aug 2023 11:54:37 +0200 Subject: [PATCH] Parse the InsecureRegistry env variable with comma separated values Signed-off-by: Domenico Luciani --- platform/lifecycle_inputs.go | 10 +++++++++- platform/lifecycle_inputs_test.go | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/platform/lifecycle_inputs.go b/platform/lifecycle_inputs.go index 9ba95d675..9d00d16b5 100644 --- a/platform/lifecycle_inputs.go +++ b/platform/lifecycle_inputs.go @@ -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 @@ -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) diff --git a/platform/lifecycle_inputs_test.go b/platform/lifecycle_inputs_test.go index cd54d69a0..05e66a5fa 100644 --- a/platform/lifecycle_inputs_test.go +++ b/platform/lifecycle_inputs_test.go @@ -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() { @@ -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", + }) }) })