Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: egressip-update-validation
spec:
failurePolicy: Fail
matchConditions:
- expression: '("k8s.ovn.org/egressip-mark" in object.metadata.annotations) && (!has(oldObject.metadata.annotations) ||
!("k8s.ovn.org/egressip-mark" in oldObject.metadata.annotations))'
name: egressip-mark-annotation-update
matchConstraints:
resourceRules:
- apiGroups: ["k8s.ovn.org"]
apiVersions: ["v1"]
operations: ["UPDATE"]
resources: ["egressips"]
validations:
- expression: '(request.userInfo.username == "system:serviceaccount:openshift-ovn-kubernetes:ovn-kubernetes-control-plane")'
message: 'A regular user must not add "k8s.ovn.org/egressip-mark" annotation to an EgressIP custom resource.'
reason: Invalid

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: egressip-create-validation
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: ["k8s.ovn.org"]
apiVersions: ["v1"]
operations: ["CREATE"]
resources: ["egressips"]
validations:
- expression: '!has(object.metadata.annotations) || !("k8s.ovn.org/egressip-mark" in object.metadata.annotations)'
message: 'EgressIP resources cannot be created with the "k8s.ovn.org/egressip-mark" annotation. This annotation is managed by the system.'
reason: Invalid

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: egressip-update-validation-binding
spec:
policyName: egressip-update-validation
validationActions: [Deny]

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: egressip-create-validation-binding
spec:
policyName: egressip-create-validation
validationActions: [Deny]
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing newline at end of file.

8 changes: 4 additions & 4 deletions pkg/network/ovn_kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4153,7 +4153,7 @@ func Test_renderOVNKubernetes(t *testing.T) {
client: cnofake.NewFakeClient(),
featureGates: noFeatureGates,
},
expectNumObjs: 38,
expectNumObjs: 42,
},
{
name: "render routeadvertisements",
Expand All @@ -4168,7 +4168,7 @@ func Test_renderOVNKubernetes(t *testing.T) {
client: cnofake.NewFakeClient(),
featureGates: noFeatureGates,
},
expectNumObjs: 39,
expectNumObjs: 43,
},
{
name: "render with UDN",
Expand All @@ -4179,7 +4179,7 @@ func Test_renderOVNKubernetes(t *testing.T) {
client: cnofake.NewFakeClient(),
featureGates: udnFeatureGate,
},
expectNumObjs: 44,
expectNumObjs: 48,
},
{
name: "render with PreconfiguredUDNAddresses, UDN, persistent-IP, and RA",
Expand All @@ -4193,7 +4193,7 @@ func Test_renderOVNKubernetes(t *testing.T) {
client: cnofake.NewFakeClient(),
featureGates: preDefUDNFeatureGates,
},
expectNumObjs: 47,
expectNumObjs: 51,
},
}
for _, tt := range tests {
Expand Down