Skip to content

Commit b15850e

Browse files
committed
feat: validate prefixblocklength check to be 0 or 28 based on subnetallocationmode
1 parent b75f3a2 commit b15850e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

crd/multitenancy/api/v1alpha1/podnetwork.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
// PodNetwork is the Schema for the PodNetworks API
1515
// +kubebuilder:resource:shortName=pn,scope=Cluster
1616
// +kubebuilder:subresource:status
17+
// +kubebuilder:validation:XValidation:rule="!has(self.status.prefixBlockCIDRLength) || self.spec.subnetAllocationMode != 'PrefixBlock' || self.status.prefixBlockCIDRLength == 28",message="prefixBlockCIDRLength must be 28 when subnetAllocationMode is PrefixBlock"
18+
// +kubebuilder:validation:XValidation:rule="!has(self.status.prefixBlockCIDRLength) || self.spec.subnetAllocationMode != 'Single' || self.status.prefixBlockCIDRLength == 0",message="prefixBlockCIDRLength must be 0 when subnetAllocationMode is Single"
1719
// +kubebuilder:printcolumn:name="Status",type=string,priority=1,JSONPath=`.status.status`
1820
// +kubebuilder:printcolumn:name="Address Prefixes",type=string,priority=1,JSONPath=`.status.addressPrefixes`
1921
// +kubebuilder:printcolumn:name="Network",type=string,priority=1,JSONPath=`.spec.networkID`
@@ -93,7 +95,7 @@ type PodNetworkStatus struct {
9395
Status Status `json:"status,omitempty"`
9496
AddressPrefixes []string `json:"addressPrefixes,omitempty"`
9597
// PrefixBlockCIDRLength indicates the prefix length of IP block allocated to the subnet
96-
// +kubebuilder:default=28
98+
// +kubebuilder:default=0
9799
PrefixBlockCIDRLength int `json:"prefixBlockCIDRLength,omitempty"`
98100
}
99101

crd/multitenancy/manifests/multitenancy.acn.azure.com_podnetworks.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ spec:
103103
type: string
104104
type: array
105105
prefixBlockCIDRLength:
106-
default: 28
106+
default: 0
107107
description: PrefixBlockCIDRLength indicates the prefix length of
108108
IP block allocated to the subnet
109109
type: integer
@@ -117,6 +117,13 @@ spec:
117117
type: string
118118
type: object
119119
type: object
120+
x-kubernetes-validations:
121+
- message: prefixBlockCIDRLength must be 28 when subnetAllocationMode is PrefixBlock
122+
rule: '!has(self.status.prefixBlockCIDRLength) || self.spec.subnetAllocationMode
123+
!= ''PrefixBlock'' || self.status.prefixBlockCIDRLength == 28'
124+
- message: prefixBlockCIDRLength must be 0 when subnetAllocationMode is Single
125+
rule: '!has(self.status.prefixBlockCIDRLength) || self.spec.subnetAllocationMode
126+
!= ''Single'' || self.status.prefixBlockCIDRLength == 0'
120127
served: true
121128
storage: true
122129
subresources:

0 commit comments

Comments
 (0)