Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: removes uneeded annotation when not using network policy #1884

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions pkg/transformer/kubernetes/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,20 @@ func (k *Kubernetes) CreateHeadlessService(name string, service kobject.ServiceC
}

// UpdateKubernetesObjectsMultipleContainers method updates the kubernetes objects with the necessary data
func (k *Kubernetes) UpdateKubernetesObjectsMultipleContainers(name string, service kobject.ServiceConfig, objects *[]runtime.Object, podSpec PodSpec) error {
func (k *Kubernetes) UpdateKubernetesObjectsMultipleContainers(name string, service kobject.ServiceConfig, objects *[]runtime.Object, podSpec PodSpec, opt kobject.ConvertOptions) error {
// Configure annotations
annotations := transformer.ConfigAnnotations(service)

// fillTemplate fills the pod template with the value calculated from config
fillTemplate := func(template *api.PodTemplateSpec) error {
template.ObjectMeta.Labels = transformer.ConfigLabelsWithNetwork(name, service.Network)

// We will ONLY add config labels with network if we actually
// passed in --generate-network-policies to the kompose command
if opt.GenerateNetworkPolicies {
template.ObjectMeta.Labels = transformer.ConfigLabelsWithNetwork(name, service.Network)
} else {
template.ObjectMeta.Labels = transformer.ConfigLabels(name)
}
template.Spec = podSpec.Get()
return nil
}
Expand Down Expand Up @@ -660,7 +667,13 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
template.Spec.SecurityContext = podSecurityContext
}
template.Spec.Containers[0].Ports = ports
template.ObjectMeta.Labels = transformer.ConfigLabelsWithNetwork(name, service.Network)

// Only add network mode if generate-network-policies is set
if opt.GenerateNetworkPolicies {
template.ObjectMeta.Labels = transformer.ConfigLabelsWithNetwork(name, service.Network)
} else {
template.ObjectMeta.Labels = transformer.ConfigLabels(name)
}

// Configure the image pull policy
policy, err := GetImagePullPolicy(name, service.ImagePullPolicy)
Expand Down
2 changes: 1 addition & 1 deletion pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
podSpec.Append(ServiceAccountName(serviceAccountName))
}

err = k.UpdateKubernetesObjectsMultipleContainers(groupName, service, &objects, podSpec)
err = k.UpdateKubernetesObjectsMultipleContainers(groupName, service, &objects, podSpec, opt)
if err != nil {
return nil, errors.Wrap(err, "Error transforming Kubernetes objects")
}
Expand Down
1 change: 0 additions & 1 deletion pkg/transformer/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func newServiceConfig() kobject.ServiceConfig {
WorkingDir: "dir",
Args: []string{"arg1", "arg2"},
VolList: []string{"/tmp/volume"},
Network: []string{"network1", "network2"}, // supported
Labels: nil,
FsGroup: 1001,
Annotations: map[string]string{"abc": "def"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/change-in-volume-default: "true"
io.kompose.service: redis
spec:
containers:
Expand All @@ -69,7 +68,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/change-in-volume-default: "true"
io.kompose.service: web
spec:
containers:
Expand Down
2 changes: 0 additions & 2 deletions script/test/fixtures/change-in-volume/output-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/change-in-volume-default: "true"
io.kompose.service: redis
spec:
containers:
Expand All @@ -69,7 +68,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/change-in-volume-default: "true"
io.kompose.service: web
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/change-in-volume-default: "true"
io.kompose.service: redis
spec:
containers:
Expand Down Expand Up @@ -96,7 +95,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/change-in-volume-default: "true"
io.kompose.service: web
spec:
containers:
Expand Down
2 changes: 0 additions & 2 deletions script/test/fixtures/change-in-volume/output-os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/change-in-volume-default: "true"
io.kompose.service: redis
spec:
containers:
Expand Down Expand Up @@ -96,7 +95,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/change-in-volume-default: "true"
io.kompose.service: web
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/compose-env-interpolation-default: "true"
io.kompose.service: foo
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/compose-file-env-variable-default: "true"
io.kompose.service: alpine
spec:
containers:
Expand All @@ -69,7 +68,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/compose-file-env-variable-default: "true"
io.kompose.service: debian
spec:
containers:
Expand Down
1 change: 0 additions & 1 deletion script/test/fixtures/compose-file-support/output-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/compose-file-support-default: "true"
io.kompose.service: web
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-file-configs-default: "true"
io.kompose.service: busy
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-file-configs-default: "true"
io.kompose.service: busy
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-file-configs-default: "true"
io.kompose.service: busy
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-file-configs-default: "true"
io.kompose.service: busy
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-file-configs-default: "true"
io.kompose.service: busy
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-file-configs-default: "true"
io.kompose.service: busy
spec:
containers:
Expand Down
1 change: 0 additions & 1 deletion script/test/fixtures/configmap-pod/output-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ apiVersion: v1
kind: Pod
metadata:
labels:
io.kompose.network/configmap-pod-default: "true"
io.kompose.service: redis
name: redis
spec:
Expand Down
1 change: 0 additions & 1 deletion script/test/fixtures/configmap-pod/output-os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ apiVersion: v1
kind: Pod
metadata:
labels:
io.kompose.network/configmap-pod-default: "true"
io.kompose.service: redis
name: redis
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-volume-default: "true"
io.kompose.service: db
spec:
containers:
Expand Down Expand Up @@ -63,7 +62,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-volume-default: "true"
io.kompose.service: web
spec:
containers:
Expand Down
2 changes: 0 additions & 2 deletions script/test/fixtures/configmap-volume/output-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-volume-default: "true"
io.kompose.service: db
spec:
containers:
Expand Down Expand Up @@ -64,7 +63,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-volume-default: "true"
io.kompose.service: web
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-volume-default: "true"
io.kompose.service: db
spec:
containers:
Expand Down Expand Up @@ -90,7 +89,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-volume-default: "true"
io.kompose.service: web
spec:
containers:
Expand Down
2 changes: 0 additions & 2 deletions script/test/fixtures/configmap-volume/output-os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-volume-default: "true"
io.kompose.service: db
spec:
containers:
Expand Down Expand Up @@ -91,7 +90,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/configmap-volume-default: "true"
io.kompose.service: web
spec:
containers:
Expand Down
1 change: 0 additions & 1 deletion script/test/fixtures/cronjob/output-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/cronjob-default: "true"
io.kompose.service: challenge
spec:
containers:
Expand Down
1 change: 0 additions & 1 deletion script/test/fixtures/cronjob/output-os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/cronjob-default: "true"
io.kompose.service: challenge
spec:
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/placement-default: "true"
io.kompose.service: redis
spec:
affinity:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/placement-default: "true"
io.kompose.service: redis
spec:
affinity:
Expand Down
2 changes: 0 additions & 2 deletions script/test/fixtures/env-multiple/output-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ spec:
metadata:
creationTimestamp: null
labels:
io.kompose.network/env-default: "true"
io.kompose.service: another-namenode
spec:
containers:
Expand Down Expand Up @@ -117,7 +116,6 @@ spec:
metadata:
creationTimestamp: null
labels:
io.kompose.network/env-default: "true"
io.kompose.service: namenode
spec:
containers:
Expand Down
2 changes: 0 additions & 2 deletions script/test/fixtures/env-multiple/output-os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ spec:
metadata:
creationTimestamp: null
labels:
io.kompose.network/env-default: "true"
io.kompose.service: another-namenode
spec:
containers:
Expand Down Expand Up @@ -151,7 +150,6 @@ spec:
metadata:
creationTimestamp: null
labels:
io.kompose.network/env-default: "true"
io.kompose.service: namenode
spec:
containers:
Expand Down
2 changes: 0 additions & 2 deletions script/test/fixtures/env/output-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/env-default: "true"
io.kompose.service: another-namenode
spec:
containers:
Expand Down Expand Up @@ -100,7 +99,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/env-default: "true"
io.kompose.service: namenode
spec:
containers:
Expand Down
2 changes: 0 additions & 2 deletions script/test/fixtures/env/output-os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/env-default: "true"
io.kompose.service: another-namenode
spec:
containers:
Expand Down Expand Up @@ -126,7 +125,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/env-default: "true"
io.kompose.service: namenode
spec:
containers:
Expand Down
1 change: 0 additions & 1 deletion script/test/fixtures/envvars-interpolation/output-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/envvars-interpolation-default: "true"
io.kompose.service: myservice
spec:
containers:
Expand Down
1 change: 0 additions & 1 deletion script/test/fixtures/envvars-interpolation/output-os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/envvars-interpolation-default: "true"
io.kompose.service: myservice
spec:
containers:
Expand Down
1 change: 0 additions & 1 deletion script/test/fixtures/envvars-with-status/output-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ spec:
template:
metadata:
labels:
io.kompose.network/envvars-with-status-default: "true"
io.kompose.service: app
spec:
containers:
Expand Down
Loading
Loading