Skip to content

Commit 76bdbc2

Browse files
committed
Fix issue where IPBlock and NamespaceSelector are mutually exclusive
On upgrade, the IPBlock was already set and then after upgrade it enters the conditional where it tries to add the NamespaceSelector. So, in that case both are set. Instead, when we set one, we should unset the other to ensure they aren't both set. This fixes the error: NetworkPolicy.networking.k8s.io "miq-application-allow-inbound-httpd" is invalid: spec.ingress[0].from[0]: Forbidden: may not specify both ipBlock and another peer CP4AIOPS-22012
1 parent 5648ec4 commit 76bdbc2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

manageiq-operator/api/v1alpha1/helpers/miq-components/network_policies.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package miqtools
22

33
import (
44
"context"
5+
56
miqv1alpha1 "github.com/ManageIQ/manageiq-pods/manageiq-operator/api/v1alpha1"
67
routev1 "github.com/openshift/api/route/v1"
78
corev1 "k8s.io/api/core/v1"
@@ -56,13 +57,15 @@ func NetworkPolicyAllowInboundHttpd(cr *miqv1alpha1.ManageIQ, scheme *runtime.Sc
5657
networkingv1.NetworkPolicyPeer{},
5758
}
5859
}
59-
if openshift == true {
60+
if openshift {
61+
networkPolicy.Spec.Ingress[0].From[0].IPBlock = nil
6062
networkPolicy.Spec.Ingress[0].From[0].NamespaceSelector = &metav1.LabelSelector{
6163
MatchLabels: map[string]string{
6264
"network.openshift.io/policy-group": "ingress",
6365
},
6466
}
6567
} else {
68+
networkPolicy.Spec.Ingress[0].From[0].NamespaceSelector = nil
6669
networkPolicy.Spec.Ingress[0].From[0].IPBlock = &networkingv1.IPBlock{}
6770
networkPolicy.Spec.Ingress[0].From[0].IPBlock.CIDR = "0.0.0.0/0"
6871
}

0 commit comments

Comments
 (0)