From d780067bf984f384707b96bbb6e139f3d86909f8 Mon Sep 17 00:00:00 2001 From: Hang Yan Date: Thu, 6 Aug 2020 23:42:58 +0800 Subject: [PATCH] Add missing pod ano (#1303) --- pkg/transformer/kubernetes/kubernetes.go | 5 +++-- script/test/cmd/tests.sh | 22 +++++++++++++++---- .../output-k8s-restart-no.json | 4 ++++ .../output-k8s-restart-onfail.json | 4 ++++ .../restart-options/output-os-restart-no.json | 4 ++++ .../output-os-restart-onfail.json | 4 ++++ .../fixtures/v3/output-k8s-full-example.json | 7 ++++++ .../fixtures/v3/output-os-full-example.json | 7 ++++++ 8 files changed, 51 insertions(+), 6 deletions(-) diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index ed643442..d6682120 100755 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -1085,8 +1085,9 @@ func (k *Kubernetes) InitPod(name string, service kobject.ServiceConfig) *api.Po APIVersion: "v1", }, ObjectMeta: api.ObjectMeta{ - Name: name, - Labels: transformer.ConfigLabels(name), + Name: name, + Labels: transformer.ConfigLabels(name), + Annotations: transformer.ConfigAnnotations(service), }, Spec: k.InitPodSpec(name, service.Image, service.ImagePullSecret), } diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index 4c218abf..ca4157f8 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -295,15 +295,29 @@ convert::expect_success_and_warning "$cmd" "/tmp/output-os.json" "Unsupported de ###### # Test related to restart options in docker-compose # kubernetes test -convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-no.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-k8s-restart-no.json" -convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-k8s-restart-onfail.json" +cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-no.yml convert --stdout -j" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-k8s-restart-no.json" > /tmp/output-k8s.json +convert::expect_success "$cmd" /tmp/output-k8s.json + +cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml convert --stdout -j" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-k8s-restart-onfail.json" > /tmp/output-k8s.json +convert::expect_success "$cmd" /tmp/output-k8s.json + +# convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-no.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-k8s-restart-no.json" +# convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-k8s-restart-onfail.json" cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-unless-stopped.yml convert --stdout -j" sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-k8s-restart-unless-stopped.json" > /tmp/output-k8s.json convert::expect_success_and_warning "$cmd" /tmp/output-k8s.json # openshift test -convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-no.yml --provider openshift convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-no.json" -convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml --provider openshift convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-onfail.json" +cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-no.yml --provider openshift convert --stdout -j" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-no.json" > /tmp/output-os.json +convert::expect_success "$cmd" /tmp/output-os.json + +cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml --provider openshift convert --stdout -j" +sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-onfail.json" > /tmp/output-os.json +convert::expect_success "$cmd" /tmp/output-os.json + cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-unless-stopped.yml --provider openshift convert --stdout -j" sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-unless-stopped.json" > /tmp/output-os.json convert::expect_success_and_warning "$cmd" /tmp/output-os.json diff --git a/script/test/fixtures/restart-options/output-k8s-restart-no.json b/script/test/fixtures/restart-options/output-k8s-restart-no.json index 2966425d..ff832b92 100644 --- a/script/test/fixtures/restart-options/output-k8s-restart-no.json +++ b/script/test/fixtures/restart-options/output-k8s-restart-no.json @@ -11,6 +11,10 @@ "creationTimestamp": null, "labels": { "io.kompose.service": "foo" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" } }, "spec": { diff --git a/script/test/fixtures/restart-options/output-k8s-restart-onfail.json b/script/test/fixtures/restart-options/output-k8s-restart-onfail.json index dc286df6..b472b691 100644 --- a/script/test/fixtures/restart-options/output-k8s-restart-onfail.json +++ b/script/test/fixtures/restart-options/output-k8s-restart-onfail.json @@ -11,6 +11,10 @@ "creationTimestamp": null, "labels": { "io.kompose.service": "foo" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" } }, "spec": { diff --git a/script/test/fixtures/restart-options/output-os-restart-no.json b/script/test/fixtures/restart-options/output-os-restart-no.json index 2966425d..ff832b92 100644 --- a/script/test/fixtures/restart-options/output-os-restart-no.json +++ b/script/test/fixtures/restart-options/output-os-restart-no.json @@ -11,6 +11,10 @@ "creationTimestamp": null, "labels": { "io.kompose.service": "foo" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" } }, "spec": { diff --git a/script/test/fixtures/restart-options/output-os-restart-onfail.json b/script/test/fixtures/restart-options/output-os-restart-onfail.json index dc286df6..b472b691 100644 --- a/script/test/fixtures/restart-options/output-os-restart-onfail.json +++ b/script/test/fixtures/restart-options/output-os-restart-onfail.json @@ -11,6 +11,10 @@ "creationTimestamp": null, "labels": { "io.kompose.service": "foo" + }, + "annotations": { + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" } }, "spec": { diff --git a/script/test/fixtures/v3/output-k8s-full-example.json b/script/test/fixtures/v3/output-k8s-full-example.json index a5066e87..03e8cc89 100644 --- a/script/test/fixtures/v3/output-k8s-full-example.json +++ b/script/test/fixtures/v3/output-k8s-full-example.json @@ -157,6 +157,13 @@ "io.kompose.network/other-other-network": "true", "io.kompose.network/some-network": "true", "io.kompose.service": "foo" + }, + "annotations": { + "com.example.description": "Accounting webapp", + "com.example.empty-label": "", + "com.example.number": "42", + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" } }, "spec": { diff --git a/script/test/fixtures/v3/output-os-full-example.json b/script/test/fixtures/v3/output-os-full-example.json index 97799228..8c2c9294 100644 --- a/script/test/fixtures/v3/output-os-full-example.json +++ b/script/test/fixtures/v3/output-os-full-example.json @@ -157,6 +157,13 @@ "io.kompose.network/other-other-network": "true", "io.kompose.network/some-network": "true", "io.kompose.service": "foo" + }, + "annotations": { + "com.example.description": "Accounting webapp", + "com.example.empty-label": "", + "com.example.number": "42", + "kompose.cmd": "%CMD%", + "kompose.version": "%VERSION%" } }, "spec": {