Skip to content
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
32 changes: 32 additions & 0 deletions bindata/network/ovn-kubernetes/common/udn-admission-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{if .OVN_NETWORK_SEGMENTATION_ENABLE}}
apiVersion: admissionregistration.k8s.io/v1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only apply this if UDN is enabled

kind: ValidatingAdmissionPolicy
metadata:
name: user-defined-networks-namespace-label
spec:
matchConstraints:
resourceRules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["UPDATE"]
resources: ["namespaces"]
failurePolicy: Fail
validations:
- expression: "('k8s.ovn.org/primary-user-defined-network' in oldObject.metadata.labels) == ('k8s.ovn.org/primary-user-defined-network' in object.metadata.labels)"
message: "The 'k8s.ovn.org/primary-user-defined-network' label cannot be added/removed after the namespace was created"

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: user-defined-networks-namespace-label-binding
spec:
policyName: disable-udn-label-change
validationActions: [Deny]
matchResources:
resourceRules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["UPDATE"]
resources: ["namespaces"]
{{end}}
24 changes: 24 additions & 0 deletions pkg/network/ovn_kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3991,6 +3991,19 @@ func Test_renderOVNKubernetes(t *testing.T) {
},
)
}
udnFeatureGate := func() featuregates.FeatureGate {
return featuregates.NewFeatureGate(
[]configv1.FeatureGateName{
apifeatures.FeatureGateNetworkSegmentation,
},
[]configv1.FeatureGateName{
apifeatures.FeatureGateAdminNetworkPolicy,
apifeatures.FeatureGateDNSNameResolver,
apifeatures.FeatureGatePersistentIPsForVirtualization,
apifeatures.FeatureGateOVNObservability,
},
)
}
type args struct {
conf func() *operv1.NetworkSpec
bootstrapResult func() *bootstrap.BootstrapResult
Expand Down Expand Up @@ -4030,6 +4043,17 @@ func Test_renderOVNKubernetes(t *testing.T) {
},
expectNumObjs: 38,
},
{
name: "render with UDN",
args: args{
conf: fakeNetworkConf,
bootstrapResult: fakeBootstrapResultOVN,
manifestDir: manifestDirOvn,
client: cnofake.NewFakeClient(),
featureGates: udnFeatureGate,
},
expectNumObjs: 41,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down