Skip to content

Commit 708e515

Browse files
committed
Add validation for allowing only 1 BANP
The KEP says that at a given time, we can have only 1 BANP in the cluster. No use cases for more than one was brough forth so far. So in the v1alpha1 of the API let's stick to this and we can later remove this restriction if more than one BANP is required, but then that will entail confusions since BANP doesn't have a priority set. Since there is no straight forward way to limit Items in the BaselineAdminNetworkPolicyList, we will use the new xvalidation: https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/2876-crd-validation-expression-language/README.md#proposal approach here. See how singleton is expressed. Signed-off-by: Surya Seetharaman <[email protected]>
1 parent 81d5594 commit 708e515

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

apis/v1alpha1/baselineadminnetworkpolicy_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
2828
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
2929
// +kubebuilder:metadata:annotations="api-approved.kubernetes.io=https://github.com/kubernetes/enhancements/pull/2522"
30+
// +kubebuilder:validation:XValidation:rule="self.metadata.name == 'default'",message="Only one baseline admin network policy with metadata.name=\"default\" can be created in the cluster"
3031
// BaselineAdminNetworkPolicy is a cluster level resource that is part of the
3132
// AdminNetworkPolicy API.
3233
type BaselineAdminNetworkPolicy struct {

config/crd/bases/policy.networking.k8s.io_baselineadminnetworkpolicies.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ spec:
977977
- metadata
978978
- spec
979979
type: object
980+
x-kubernetes-validations:
981+
- message: Only one baseline admin network policy with metadata.name="default"
982+
can be created in the cluster
983+
rule: self.metadata.name == 'default'
980984
served: true
981985
storage: true
982986
subresources:

0 commit comments

Comments
 (0)