forked from LaconicNetwork/kompose
bug: fix annotation bug (#1887)
#### What type of PR is this? <!-- Add one of the following kinds: /kind bug /kind cleanup /kind documentation /kind feature --> #### What this PR does / why we need it: When supplying a label in the compose file, it should stay in the output too. #### Which issue(s) this PR fixes: <!-- *Automatically closes linked issue when PR is merged. Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> Fixes https://github.com/kubernetes/kompose/issues/1885 #### Special notes for your reviewer: Signed-off-by: Charlie Drage <charlie@charliedrage.com>
This commit is contained in:
parent
50ec43d1e0
commit
1f7441845e
@ -249,10 +249,6 @@ func ConfigAllLabels(name string, service *kobject.ServiceConfig) map[string]str
|
|||||||
func ConfigAnnotations(service kobject.ServiceConfig) map[string]string {
|
func ConfigAnnotations(service kobject.ServiceConfig) map[string]string {
|
||||||
annotations := map[string]string{}
|
annotations := map[string]string{}
|
||||||
|
|
||||||
if !service.WithKomposeAnnotation {
|
|
||||||
return annotations
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, value := range service.Annotations {
|
for key, value := range service.Annotations {
|
||||||
annotations[key] = value
|
annotations[key] = value
|
||||||
}
|
}
|
||||||
@ -270,6 +266,15 @@ func ConfigAnnotations(service kobject.ServiceConfig) map[string]string {
|
|||||||
annotations["kompose.version"] = version.VERSION + " (" + version.GITCOMMIT + ")"
|
annotations["kompose.version"] = version.VERSION + " (" + version.GITCOMMIT + ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if service.WithKomposeAnnotation = false, we remove **all** kompose annotations (io.kompose.*)
|
||||||
|
if !service.WithKomposeAnnotation {
|
||||||
|
for key := range annotations {
|
||||||
|
if strings.HasPrefix(key, "kompose.") {
|
||||||
|
delete(annotations, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return annotations
|
return annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -386,3 +386,8 @@ os_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/envvars-with-status/compos
|
|||||||
os_output="$KOMPOSE_ROOT/script/test/fixtures/envvars-with-status/output-os.yaml"
|
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 "$k8s_cmd" "$k8s_output" || exit 1
|
||||||
convert::expect_success "$os_cmd" "$os_output" || exit 1
|
convert::expect_success "$os_cmd" "$os_output" || exit 1
|
||||||
|
|
||||||
|
# Test label in compose.yaml appears in the output annotation
|
||||||
|
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/label/compose.yaml convert --stdout --with-kompose-annotation=false"
|
||||||
|
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/label/output-k8s.yaml"
|
||||||
|
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
|
||||||
@ -5,6 +5,4 @@ services:
|
|||||||
- "8081:8080"
|
- "8081:8080"
|
||||||
- "8026:8025"
|
- "8026:8025"
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
- /tmp:/tmp:ro
|
||||||
- /sys:/sys:ro
|
|
||||||
- /var/lib/docker/:/var/lib/docker:ro
|
|
||||||
@ -45,3 +45,4 @@ spec:
|
|||||||
- containerPort: 8025
|
- containerPort: 8025
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
restartPolicy: Always
|
restartPolicy: Always
|
||||||
|
|
||||||
|
|||||||
@ -73,3 +73,4 @@ spec:
|
|||||||
name: latest
|
name: latest
|
||||||
referencePolicy:
|
referencePolicy:
|
||||||
type: ""
|
type: ""
|
||||||
|
|
||||||
|
|||||||
7
script/test/fixtures/label/compose.yaml
vendored
Normal file
7
script/test/fixtures/label/compose.yaml
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: node:18-alpine
|
||||||
|
ports:
|
||||||
|
- 3000:3000
|
||||||
|
labels:
|
||||||
|
- "com.example.label=foo"
|
||||||
47
script/test/fixtures/label/output-k8s.yaml
vendored
Normal file
47
script/test/fixtures/label/output-k8s.yaml
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
com.example.label: foo
|
||||||
|
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:
|
||||||
|
annotations:
|
||||||
|
com.example.label: foo
|
||||||
|
labels:
|
||||||
|
io.kompose.service: app
|
||||||
|
name: app
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
io.kompose.service: app
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
com.example.label: foo
|
||||||
|
labels:
|
||||||
|
io.kompose.network/label-default: "true"
|
||||||
|
io.kompose.service: app
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: node:18-alpine
|
||||||
|
name: app
|
||||||
|
ports:
|
||||||
|
- containerPort: 3000
|
||||||
|
protocol: TCP
|
||||||
|
restartPolicy: Always
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user