From 6c7a5ddaf7ba60ff21eb5ab2d6244ad688271009 Mon Sep 17 00:00:00 2001 From: Yanjun Zhou Date: Thu, 7 Nov 2024 15:12:00 +0800 Subject: [PATCH] Fix DHCP validation (#875) Signed-off-by: Yanjun Zhou --- build/yaml/crd/vpc/crd.nsx.vmware.com_subnets.yaml | 2 +- build/yaml/crd/vpc/crd.nsx.vmware.com_subnetsets.yaml | 2 +- pkg/apis/vpc/v1alpha1/subnet_types.go | 2 +- pkg/apis/vpc/v1alpha1/subnetset_types.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/yaml/crd/vpc/crd.nsx.vmware.com_subnets.yaml b/build/yaml/crd/vpc/crd.nsx.vmware.com_subnets.yaml index 6c27c8bc8..5148f66b6 100644 --- a/build/yaml/crd/vpc/crd.nsx.vmware.com_subnets.yaml +++ b/build/yaml/crd/vpc/crd.nsx.vmware.com_subnets.yaml @@ -103,7 +103,7 @@ spec: - message: subnetDHCPConfig cannot switch from DHCPDeactivated to other modes rule: has(oldSelf.subnetDHCPConfig) || !has(self.subnetDHCPConfig) || - self.subnetDHCPConfig.mode=='DHCPDeactivated' + !has(self.subnetDHCPConfig.mode) || self.subnetDHCPConfig.mode=='DHCPDeactivated' - message: ipv4SubnetSize is required once set rule: '!has(oldSelf.ipv4SubnetSize) || has(self.ipv4SubnetSize)' - message: accessMode is required once set diff --git a/build/yaml/crd/vpc/crd.nsx.vmware.com_subnetsets.yaml b/build/yaml/crd/vpc/crd.nsx.vmware.com_subnetsets.yaml index f3218ed1a..283a13da4 100644 --- a/build/yaml/crd/vpc/crd.nsx.vmware.com_subnetsets.yaml +++ b/build/yaml/crd/vpc/crd.nsx.vmware.com_subnetsets.yaml @@ -93,7 +93,7 @@ spec: - message: subnetDHCPConfig cannot switch from DHCPDeactivated to other modes rule: has(oldSelf.subnetDHCPConfig) || !has(self.subnetDHCPConfig) || - self.subnetDHCPConfig.mode=='DHCPDeactivated' + !has(self.subnetDHCPConfig.mode) || self.subnetDHCPConfig.mode=='DHCPDeactivated' - message: accessMode is required once set rule: '!has(oldSelf.accessMode) || has(self.accessMode)' - message: ipv4SubnetSize is required once set diff --git a/pkg/apis/vpc/v1alpha1/subnet_types.go b/pkg/apis/vpc/v1alpha1/subnet_types.go index 85be77b3d..3e6dca957 100644 --- a/pkg/apis/vpc/v1alpha1/subnet_types.go +++ b/pkg/apis/vpc/v1alpha1/subnet_types.go @@ -20,7 +20,7 @@ const ( ) // SubnetSpec defines the desired state of Subnet. -// +kubebuilder:validation:XValidation:rule="has(oldSelf.subnetDHCPConfig) || !has(self.subnetDHCPConfig) || self.subnetDHCPConfig.mode=='DHCPDeactivated'", message="subnetDHCPConfig cannot switch from DHCPDeactivated to other modes" +// +kubebuilder:validation:XValidation:rule="has(oldSelf.subnetDHCPConfig) || !has(self.subnetDHCPConfig) || !has(self.subnetDHCPConfig.mode) || self.subnetDHCPConfig.mode=='DHCPDeactivated'", message="subnetDHCPConfig cannot switch from DHCPDeactivated to other modes" // +kubebuilder:validation:XValidation:rule="!has(oldSelf.ipv4SubnetSize) || has(self.ipv4SubnetSize)", message="ipv4SubnetSize is required once set" // +kubebuilder:validation:XValidation:rule="!has(oldSelf.accessMode) || has(self.accessMode)", message="accessMode is required once set" // +kubebuilder:validation:XValidation:rule="!has(oldSelf.ipAddresses) || has(self.ipAddresses)", message="ipAddresses is required once set" diff --git a/pkg/apis/vpc/v1alpha1/subnetset_types.go b/pkg/apis/vpc/v1alpha1/subnetset_types.go index 0c8212673..2c3910793 100644 --- a/pkg/apis/vpc/v1alpha1/subnetset_types.go +++ b/pkg/apis/vpc/v1alpha1/subnetset_types.go @@ -8,7 +8,7 @@ import ( ) // SubnetSetSpec defines the desired state of SubnetSet. -// +kubebuilder:validation:XValidation:rule="has(oldSelf.subnetDHCPConfig) || !has(self.subnetDHCPConfig) || self.subnetDHCPConfig.mode=='DHCPDeactivated'", message="subnetDHCPConfig cannot switch from DHCPDeactivated to other modes" +// +kubebuilder:validation:XValidation:rule="has(oldSelf.subnetDHCPConfig) || !has(self.subnetDHCPConfig) || !has(self.subnetDHCPConfig.mode) || self.subnetDHCPConfig.mode=='DHCPDeactivated'", message="subnetDHCPConfig cannot switch from DHCPDeactivated to other modes" // +kubebuilder:validation:XValidation:rule="!has(oldSelf.accessMode) || has(self.accessMode)", message="accessMode is required once set" // +kubebuilder:validation:XValidation:rule="!has(oldSelf.ipv4SubnetSize) || has(self.ipv4SubnetSize)", message="ipv4SubnetSize is required once set" type SubnetSetSpec struct {