diff --git a/pkg/transformer/kubernetes/k8sutils.go b/pkg/transformer/kubernetes/k8sutils.go index adf83f06e..76eb214bb 100644 --- a/pkg/transformer/kubernetes/k8sutils.go +++ b/pkg/transformer/kubernetes/k8sutils.go @@ -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) diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index 4e1480e1b..72881833b 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -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") } diff --git a/pkg/transformer/kubernetes/kubernetes_test.go b/pkg/transformer/kubernetes/kubernetes_test.go index 3bf174979..e252073c6 100644 --- a/pkg/transformer/kubernetes/kubernetes_test.go +++ b/pkg/transformer/kubernetes/kubernetes_test.go @@ -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"},