From a19dd1416e35597541acb4f6cc528aa47c626d90 Mon Sep 17 00:00:00 2001 From: jose luis <2064537+sosan@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:26:40 +0200 Subject: [PATCH 1/3] added \n Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> --- pkg/transformer/utils.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/transformer/utils.go b/pkg/transformer/utils.go index db046662..b5d60d25 100644 --- a/pkg/transformer/utils.go +++ b/pkg/transformer/utils.go @@ -277,9 +277,8 @@ func ConfigAnnotations(service kobject.ServiceConfig) map[string]string { func Print(name, path string, trailing string, data []byte, toStdout, generateJSON bool, f *os.File, provider string) (string, error) { file := "" // TODO: we should refactor / change this hack in the future once we have a better solution - re := regexp.MustCompile(`(?s)status:.*`) + re := regexp.MustCompile(`(?s)status:\n.*`) data = re.ReplaceAll(data, nil) - if generateJSON { file = fmt.Sprintf("%s-%s.json", name, trailing) } else { From 154c6f63c09ee41fca3997f75b71cc9e01e6e5c4 Mon Sep 17 00:00:00 2001 From: jose luis <2064537+sosan@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:59:22 +0200 Subject: [PATCH 2/3] add e2e to check env var with status value Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> --- script/test/cmd/tests_new.sh | 8 ++ .../fixtures/envvars-with-status/compose.yaml | 9 +++ .../envvars-with-status/output-k8s.yaml | 50 ++++++++++++ .../envvars-with-status/output-os.yaml | 78 +++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 script/test/fixtures/envvars-with-status/compose.yaml create mode 100644 script/test/fixtures/envvars-with-status/output-k8s.yaml create mode 100644 script/test/fixtures/envvars-with-status/output-os.yaml diff --git a/script/test/cmd/tests_new.sh b/script/test/cmd/tests_new.sh index 715ad237..0d5c7766 100755 --- a/script/test/cmd/tests_new.sh +++ b/script/test/cmd/tests_new.sh @@ -344,3 +344,11 @@ convert::expect_success "$os_cmd" "$os_output" || exit 1 k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/initcontainer/compose.yaml convert --stdout --with-kompose-annotation=false" k8s_output="$KOMPOSE_ROOT/script/test/fixtures/initcontainer/output-k8s.yaml" convert::expect_success_and_warning "$k8s_cmd" "$k8s_output" || exit 1 + +# Test env var with status +k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/envvars-with-status/compose.yaml convert --stdout --with-kompose-annotation=false" +k8s_output="$KOMPOSE_ROOT/script/test/fixtures/envvars-with-status/output-k8s.yaml" +os_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/envvars-with-status/compose.yaml convert --provider openshift --stdout --with-kompose-annotation=false" +os_output="$KOMPOSE_ROOT/script/test/fixtures/envvars-with-status/output-os.yaml" +convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1 +convert::expect_success "$os_cmd" "$os_output" || exit 1 diff --git a/script/test/fixtures/envvars-with-status/compose.yaml b/script/test/fixtures/envvars-with-status/compose.yaml new file mode 100644 index 00000000..4150c7df --- /dev/null +++ b/script/test/fixtures/envvars-with-status/compose.yaml @@ -0,0 +1,9 @@ +services: + app: + image: node:18-alpine + command: sh -c "yarn install && yarn run dev" + ports: + - 3000:3000 + environment: + TOPICS: foo:1,status:2,bar:3 + OTHER_ENV: example \ No newline at end of file diff --git a/script/test/fixtures/envvars-with-status/output-k8s.yaml b/script/test/fixtures/envvars-with-status/output-k8s.yaml new file mode 100644 index 00000000..dd333ac3 --- /dev/null +++ b/script/test/fixtures/envvars-with-status/output-k8s.yaml @@ -0,0 +1,50 @@ +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: app + name: app +spec: + ports: + - name: "3000" + port: 3000 + targetPort: 3000 + selector: + io.kompose.service: app + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: app + name: app +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: app + template: + metadata: + labels: + io.kompose.network/envvars-with-status-default: "true" + io.kompose.service: app + spec: + containers: + - args: + - sh + - -c + - yarn install && yarn run dev + env: + - name: OTHER_ENV + value: example + - name: TOPICS + value: foo:1,status:2,bar:3 + image: node:18-alpine + name: app + ports: + - containerPort: 3000 + hostPort: 3000 + protocol: TCP + restartPolicy: Always diff --git a/script/test/fixtures/envvars-with-status/output-os.yaml b/script/test/fixtures/envvars-with-status/output-os.yaml new file mode 100644 index 00000000..92ec8b74 --- /dev/null +++ b/script/test/fixtures/envvars-with-status/output-os.yaml @@ -0,0 +1,78 @@ +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: app + name: app +spec: + ports: + - name: "3000" + port: 3000 + targetPort: 3000 + selector: + io.kompose.service: app + +--- +apiVersion: apps.openshift.io/v1 +kind: DeploymentConfig +metadata: + labels: + io.kompose.service: app + name: app +spec: + replicas: 1 + selector: + io.kompose.service: app + template: + metadata: + labels: + io.kompose.network/envvars-with-status-default: "true" + io.kompose.service: app + spec: + containers: + - args: + - sh + - -c + - yarn install && yarn run dev + env: + - name: OTHER_ENV + value: example + - name: TOPICS + value: foo:1,status:2,bar:3 + image: ' ' + name: app + ports: + - containerPort: 3000 + hostPort: 3000 + protocol: TCP + restartPolicy: Always + test: false + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - app + from: + kind: ImageStreamTag + name: app:18-alpine + type: ImageChange + +--- +apiVersion: image.openshift.io/v1 +kind: ImageStream +metadata: + labels: + io.kompose.service: app + name: app +spec: + lookupPolicy: + local: false + tags: + - from: + kind: DockerImage + name: node:18-alpine + name: 18-alpine + referencePolicy: + type: "" From fb364020c2098abd77d40ed1325e5d5ae963c9ce Mon Sep 17 00:00:00 2001 From: jose luis <2064537+sosan@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:54:02 +0200 Subject: [PATCH 3/3] added eof file Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> --- script/test/fixtures/envvars-with-status/compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/test/fixtures/envvars-with-status/compose.yaml b/script/test/fixtures/envvars-with-status/compose.yaml index 4150c7df..aa5cfa02 100644 --- a/script/test/fixtures/envvars-with-status/compose.yaml +++ b/script/test/fixtures/envvars-with-status/compose.yaml @@ -6,4 +6,4 @@ services: - 3000:3000 environment: TOPICS: foo:1,status:2,bar:3 - OTHER_ENV: example \ No newline at end of file + OTHER_ENV: example