Skip to content

Commit

Permalink
cleanup: removes uneeded annotation when not using network policy
Browse files Browse the repository at this point in the history
#### What type of PR is this?

<!--
Add one of the following kinds:
/kind bug
/kind documentation
/kind feature
-->

/kind cleanup

#### What this PR does / why we need it:

Removes the network policy annotation which is not needed (we are not
generating network policy)

#### 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 #1759

#### Special notes for your reviewer:
  • Loading branch information
cdrage committed May 30, 2024
1 parent 3bf9830 commit 86a0ec2
Show file tree
Hide file tree
Showing 71 changed files with 107 additions and 104 deletions.
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
46 changes: 45 additions & 1 deletion script/test/fixtures/configmap-file-configs/output-k8s-3.yaml
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 All @@ -44,4 +43,49 @@ spec:
protocol: TCP
- containerPort: 8025
protocol: TCP
volumeMounts:
- mountPath: /sys
name: busy-claim1
readOnly: true
- mountPath: /var/lib/docker
name: busy-claim2
readOnly: true
restartPolicy: Always
volumes:
- name: busy-claim1
persistentVolumeClaim:
claimName: busy-claim1
readOnly: true
- name: busy-claim2
persistentVolumeClaim:
claimName: busy-claim2
readOnly: true

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
io.kompose.service: busy-claim1
name: busy-claim1
spec:
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 100Mi

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
io.kompose.service: busy-claim2
name: busy-claim2
spec:
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 100Mi

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
46 changes: 45 additions & 1 deletion script/test/fixtures/configmap-file-configs/output-os-3.yaml
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 All @@ -43,7 +42,23 @@ spec:
protocol: TCP
- containerPort: 8025
protocol: TCP
volumeMounts:
- mountPath: /sys
name: busy-claim1
readOnly: true
- mountPath: /var/lib/docker
name: busy-claim2
readOnly: true
restartPolicy: Always
volumes:
- name: busy-claim1
persistentVolumeClaim:
claimName: busy-claim1
readOnly: true
- name: busy-claim2
persistentVolumeClaim:
claimName: busy-claim2
readOnly: true
test: false
triggers:
- type: ConfigChange
Expand Down Expand Up @@ -73,3 +88,32 @@ spec:
name: latest
referencePolicy:
type: ""

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
io.kompose.service: busy-claim1
name: busy-claim1
spec:
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 100Mi

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
io.kompose.service: busy-claim2
name: busy-claim2
spec:
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 100Mi

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
Loading

0 comments on commit 86a0ec2

Please sign in to comment.