diff --git a/internal/prechecks.go b/internal/prechecks.go index 80e31ae..f7cfa3e 100644 --- a/internal/prechecks.go +++ b/internal/prechecks.go @@ -1,9 +1,10 @@ package internal import ( - "github.com/vshn/k8ify/pkg/util" "os" + "github.com/vshn/k8ify/pkg/util" + "github.com/sirupsen/logrus" "github.com/vshn/k8ify/pkg/ir" ) @@ -33,14 +34,20 @@ func ComposeServicePrecheck(inputs *ir.Inputs) { for _, part := range service.GetParts() { partSingleton := util.IsSingleton(part.AsCompose().Labels) if partSingleton && !parentSingleton { - logrus.Errorf("Singleton compose service %s can't be part of non-singleton compose service %s", part.Name, service.Name) + logrus.Errorf("Singleton compose service '%s' can't be part of non-singleton compose service '%s'", part.Name, service.Name) os.Exit(1) } if !partSingleton && parentSingleton { - logrus.Errorf("Non-singleton compose service %s can't be part of singleton compose service %s", part.Name, service.Name) + logrus.Errorf("Non-singleton compose service '%s' can't be part of singleton compose service '%s'", part.Name, service.Name) os.Exit(1) } } + environmentValues := service.AsCompose().Environment + for key, value := range environmentValues { + if value == nil { + logrus.Warnf("Service '%s' has environment variable '%s' with value nil. There may be a problem with your compose file(s). Please use empty string \"\" values instead.", service.Name, key) + } + } } } diff --git a/pkg/converter/converter.go b/pkg/converter/converter.go index 7048f53..60aab58 100644 --- a/pkg/converter/converter.go +++ b/pkg/converter/converter.go @@ -99,7 +99,11 @@ func composeServiceToSecret(workload *ir.Service, refSlug string, labels map[str } stringData := make(map[string]string) for key, value := range workload.AsCompose().Environment { - stringData[key] = *value + if value == nil { + stringData[key] = "" + } else { + stringData[key] = *value + } } secret := core.Secret{} secret.APIVersion = "v1" diff --git a/tests/golden/empty-env-vars-list.yml b/tests/golden/empty-env-vars-list.yml new file mode 100644 index 0000000..5054d27 --- /dev/null +++ b/tests/golden/empty-env-vars-list.yml @@ -0,0 +1,7 @@ +--- +environments: + prod: + vars: + foo: + bar: "" + baz: asdf diff --git a/tests/golden/empty-env-vars-list/compose.yml b/tests/golden/empty-env-vars-list/compose.yml new file mode 100644 index 0000000..30876b2 --- /dev/null +++ b/tests/golden/empty-env-vars-list/compose.yml @@ -0,0 +1,10 @@ +version: '3.4' +services: + pinger: + image: pinger:4.0 + environment: + - testempty1= + - testempty2=$foo + - testempty3=$bar + - testnotempty=$baz + diff --git a/tests/golden/empty-env-vars-list/manifests/pinger-oasp-deployment.yaml b/tests/golden/empty-env-vars-list/manifests/pinger-oasp-deployment.yaml new file mode 100644 index 0000000..d1e7974 --- /dev/null +++ b/tests/golden/empty-env-vars-list/manifests/pinger-oasp-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + creationTimestamp: null + labels: + k8ify.ref-slug: oasp + k8ify.service: pinger + name: pinger-oasp +spec: + selector: + matchLabels: + k8ify.ref-slug: oasp + k8ify.service: pinger + strategy: + type: Recreate + template: + metadata: + creationTimestamp: null + labels: + k8ify.ref-slug: oasp + k8ify.service: pinger + spec: + containers: + - envFrom: + - secretRef: + name: pinger-oasp-env + image: pinger:4.0 + imagePullPolicy: Always + name: pinger-oasp + resources: {} + restartPolicy: Always +status: {} diff --git a/tests/golden/empty-env-vars-list/manifests/pinger-oasp-env-secret.yaml b/tests/golden/empty-env-vars-list/manifests/pinger-oasp-env-secret.yaml new file mode 100644 index 0000000..8ad6664 --- /dev/null +++ b/tests/golden/empty-env-vars-list/manifests/pinger-oasp-env-secret.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Secret +metadata: + creationTimestamp: null + labels: + k8ify.ref-slug: oasp + k8ify.service: pinger + name: pinger-oasp-env +stringData: + testempty1: "" + testempty2: "" + testempty3: "" + testnotempty: asdf diff --git a/tests/golden/empty-env-vars-map.yml b/tests/golden/empty-env-vars-map.yml new file mode 100644 index 0000000..5054d27 --- /dev/null +++ b/tests/golden/empty-env-vars-map.yml @@ -0,0 +1,7 @@ +--- +environments: + prod: + vars: + foo: + bar: "" + baz: asdf diff --git a/tests/golden/empty-env-vars-map/compose.yml b/tests/golden/empty-env-vars-map/compose.yml new file mode 100644 index 0000000..04914a0 --- /dev/null +++ b/tests/golden/empty-env-vars-map/compose.yml @@ -0,0 +1,12 @@ +version: '3.4' +services: + pinger: + image: pinger:4.0 + environment: + testempty1: "" + testempty2: $foo + testempty3: $bar + testempty4: + testempty5: null + testnotempty: $baz + diff --git a/tests/golden/empty-env-vars-map/manifests/pinger-oasp-deployment.yaml b/tests/golden/empty-env-vars-map/manifests/pinger-oasp-deployment.yaml new file mode 100644 index 0000000..d1e7974 --- /dev/null +++ b/tests/golden/empty-env-vars-map/manifests/pinger-oasp-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + creationTimestamp: null + labels: + k8ify.ref-slug: oasp + k8ify.service: pinger + name: pinger-oasp +spec: + selector: + matchLabels: + k8ify.ref-slug: oasp + k8ify.service: pinger + strategy: + type: Recreate + template: + metadata: + creationTimestamp: null + labels: + k8ify.ref-slug: oasp + k8ify.service: pinger + spec: + containers: + - envFrom: + - secretRef: + name: pinger-oasp-env + image: pinger:4.0 + imagePullPolicy: Always + name: pinger-oasp + resources: {} + restartPolicy: Always +status: {} diff --git a/tests/golden/empty-env-vars-map/manifests/pinger-oasp-env-secret.yaml b/tests/golden/empty-env-vars-map/manifests/pinger-oasp-env-secret.yaml new file mode 100644 index 0000000..450e87e --- /dev/null +++ b/tests/golden/empty-env-vars-map/manifests/pinger-oasp-env-secret.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Secret +metadata: + creationTimestamp: null + labels: + k8ify.ref-slug: oasp + k8ify.service: pinger + name: pinger-oasp-env +stringData: + testempty1: "" + testempty2: "" + testempty3: "" + testempty4: "" + testempty5: "" + testnotempty: asdf