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

#### 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 https://github.com/kubernetes/kompose/issues/1759

#### Special notes for your reviewer:
This commit is contained in:
Charlie Drage
2024-06-02 20:46:57 +02:00
committed by GitHub
parent 1f7441845e
commit 55b077ab04
71 changed files with 17 additions and 110 deletions
+16 -3
View File
@@ -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
}
@@ -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)
+1 -1
View File
@@ -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")
}
@@ -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"},