diff --git a/pkg/app/app.go b/pkg/app/app.go index 4ad3c022c..39f3caf8b 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -225,6 +225,11 @@ func Convert(opt kobject.ConvertOptions) ([]runtime.Object, error) { komposeObject.Namespace = opt.Namespace + // Check if input files are specified + if len(opt.InputFiles) <= 0 { + log.Fatal("No input files specified") + } + // convert env_file from absolute to relative path for _, service := range komposeObject.ServiceConfigs { if len(service.EnvFile) <= 0 { @@ -245,7 +250,7 @@ func Convert(opt kobject.ConvertOptions) ([]runtime.Object, error) { log.Fatalf(err.Error()) } - service.EnvFile[i] = strings.Replace(relPath, "\\", "/", -1) + service.EnvFile[i] = filepath.ToSlash(relPath) } } diff --git a/script/test/cmd/tests_new.sh b/script/test/cmd/tests_new.sh index 933a1920a..c1bdac34b 100755 --- a/script/test/cmd/tests_new.sh +++ b/script/test/cmd/tests_new.sh @@ -142,6 +142,14 @@ os_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-volume/output-os-withlab convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1 convert::expect_success "$os_cmd" "$os_output" || exit 1 +# test configmap pod generation +k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/configmap-pod/docker-compose.yml convert --stdout --with-kompose-annotation=false" +k8s_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-pod/output-k8s.yaml" +os_output="$KOMPOSE_ROOT/script/test/fixtures/configmap-pod/output-os.yaml" +os_cmd="kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/configmap-pod/docker-compose.yml convert --stdout --with-kompose-annotation=false" +convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1 +convert::expect_success "$os_cmd" "$os_output" || exit 1 + # Test that emptyDir works k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml convert --with-kompose-annotation=false --stdout --volumes emptyDir" k8s_output="$KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-k8s-empty-vols-template.yaml" diff --git a/script/test/fixtures/configmap-pod/bar.env b/script/test/fixtures/configmap-pod/bar.env new file mode 100644 index 000000000..8c113bf9d --- /dev/null +++ b/script/test/fixtures/configmap-pod/bar.env @@ -0,0 +1,3 @@ +# Multi-line test +FOO=BAR +BAR=FOO diff --git a/script/test/fixtures/configmap-pod/docker-compose.yml b/script/test/fixtures/configmap-pod/docker-compose.yml new file mode 100644 index 000000000..6b77ab361 --- /dev/null +++ b/script/test/fixtures/configmap-pod/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3' + +services: + redis: + image: 'bitnami/redis:latest' + environment: + - ALLOW_EMPTY_PASSWORD=no + # Env file will override environment / warn! + env_file: + - "foo.env" + - bar.env + labels: + kompose.service.type: nodeport + ports: + - '6379:6379' + restart: "no" diff --git a/script/test/fixtures/configmap-pod/foo.env b/script/test/fixtures/configmap-pod/foo.env new file mode 100644 index 000000000..63b8c81a0 --- /dev/null +++ b/script/test/fixtures/configmap-pod/foo.env @@ -0,0 +1,2 @@ +# Test comment! +ALLOW_EMPTY_PASSWORD=yes diff --git a/script/test/fixtures/configmap-pod/output-k8s.yaml b/script/test/fixtures/configmap-pod/output-k8s.yaml new file mode 100644 index 000000000..edf1039e5 --- /dev/null +++ b/script/test/fixtures/configmap-pod/output-k8s.yaml @@ -0,0 +1,76 @@ +--- +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + labels: + io.kompose.service: redis + name: redis +spec: + ports: + - name: "6379" + port: 6379 + targetPort: 6379 + selector: + io.kompose.service: redis + type: NodePort + +--- +apiVersion: v1 +kind: Pod +metadata: + creationTimestamp: null + labels: + io.kompose.network/configmap-pod-default: "true" + io.kompose.service: redis + name: redis +spec: + containers: + - env: + - name: ALLOW_EMPTY_PASSWORD + valueFrom: + configMapKeyRef: + key: ALLOW_EMPTY_PASSWORD + name: foo-env + - name: BAR + valueFrom: + configMapKeyRef: + key: BAR + name: bar-env + - name: FOO + valueFrom: + configMapKeyRef: + key: FOO + name: bar-env + image: bitnami/redis:latest + name: redis + ports: + - containerPort: 6379 + hostPort: 6379 + protocol: TCP + resources: {} + restartPolicy: Never + +--- +apiVersion: v1 +data: + ALLOW_EMPTY_PASSWORD: "yes" +kind: ConfigMap +metadata: + creationTimestamp: null + labels: + io.kompose.service: redis-foo-env + name: foo-env + +--- +apiVersion: v1 +data: + BAR: FOO + FOO: BAR +kind: ConfigMap +metadata: + creationTimestamp: null + labels: + io.kompose.service: redis-bar-env + name: bar-env + diff --git a/script/test/fixtures/configmap-pod/output-os.yaml b/script/test/fixtures/configmap-pod/output-os.yaml new file mode 100644 index 000000000..eefa4acc9 --- /dev/null +++ b/script/test/fixtures/configmap-pod/output-os.yaml @@ -0,0 +1,53 @@ +--- +apiVersion: v1 +kind: Service +metadata: + creationTimestamp: null + labels: + io.kompose.service: redis + name: redis +spec: + ports: + - name: "6379" + port: 6379 + targetPort: 6379 + selector: + io.kompose.service: redis + type: NodePort + +--- +apiVersion: v1 +kind: Pod +metadata: + creationTimestamp: null + labels: + io.kompose.network/configmap-pod-default: "true" + io.kompose.service: redis + name: redis +spec: + containers: + - env: + - name: ALLOW_EMPTY_PASSWORD + valueFrom: + configMapKeyRef: + key: ALLOW_EMPTY_PASSWORD + name: foo-env + - name: BAR + valueFrom: + configMapKeyRef: + key: BAR + name: bar-env + - name: FOO + valueFrom: + configMapKeyRef: + key: FOO + name: bar-env + image: bitnami/redis:latest + name: redis + ports: + - containerPort: 6379 + hostPort: 6379 + protocol: TCP + resources: {} + restartPolicy: Never +