From 3028d3b0805f176c766aaf0145541a70b8c40efd Mon Sep 17 00:00:00 2001 From: Wenqi Qiu Date: Wed, 29 May 2024 11:48:03 +0800 Subject: [PATCH] update NetworkConfiguration CR with new VPC API Signed-off-by: Wenqi Qiu --- build/yaml/crd/nsx.vmware.com_ippools.yaml | 4 +- .../yaml/crd/nsx.vmware.com_networkinfos.yaml | 2 +- build/yaml/crd/nsx.vmware.com_subnets.yaml | 2 + build/yaml/crd/nsx.vmware.com_subnetsets.yaml | 2 + ...x.vmware.com_vpcnetworkconfigurations.yaml | 75 ++++++++++--------- .../samples/nsx_v1alpha1_networkinfo.yaml | 2 +- ...nsx_v1alpha1_vpcnetworkconfigurations.yaml | 12 +-- .../v1alpha1/networkinfo_types.go | 8 +- .../nsx.vmware.com/v1alpha1/subnet_types.go | 11 +-- .../v1alpha1/subnetset_types.go | 11 +-- .../v1alpha1/vpcnetworkconfiguration_types.go | 69 +++++++++-------- .../v1alpha1/zz_generated.deepcopy.go | 13 +--- .../nsx.vmware.com/v1alpha2/ippool_types.go | 12 +-- pkg/apis/v1alpha1/networkinfo_types.go | 8 +- pkg/apis/v1alpha1/subnet_types.go | 11 +-- pkg/apis/v1alpha1/subnetset_types.go | 11 +-- .../v1alpha1/vpcnetworkconfiguration_types.go | 69 +++++++++-------- pkg/apis/v1alpha1/zz_generated.deepcopy.go | 13 +--- pkg/apis/v1alpha2/ippool_types.go | 12 +-- pkg/controllers/ippool/ippool_controller.go | 4 +- .../namespace/namespace_controller.go | 35 +++++---- .../networkinfo/networkinfo_controller.go | 8 +- .../networkinfo/vpcnetworkconfig_handler.go | 43 ++++------- .../vpcnetworkconfig_handler_test.go | 67 +++++++++-------- pkg/controllers/subnet/subnet_controller.go | 5 +- .../subnetset/subnetset_controller.go | 5 +- pkg/nsx/services/common/types.go | 25 ++++--- pkg/nsx/services/vpc/builder.go | 17 ++--- pkg/nsx/services/vpc/compare.go | 2 +- pkg/nsx/services/vpc/vpc.go | 26 +++---- .../testVPC/customize_networkconfig.yaml | 16 ++-- .../customize_networkconfig_updated.yaml | 15 ++-- .../testVPC/default_networkconfig.yaml | 15 ++-- .../testVPC/system_networkconfig.yaml | 15 ++-- test/e2e/nsx_networkinfo_test.go | 20 ++--- test/e2e/nsx_subnet_test.go | 8 +- 36 files changed, 334 insertions(+), 339 deletions(-) diff --git a/build/yaml/crd/nsx.vmware.com_ippools.yaml b/build/yaml/crd/nsx.vmware.com_ippools.yaml index 7656d50b6..6da570865 100644 --- a/build/yaml/crd/nsx.vmware.com_ippools.yaml +++ b/build/yaml/crd/nsx.vmware.com_ippools.yaml @@ -183,10 +183,12 @@ spec: type: object type: array type: - description: Type defines the type of this IPPool, Public or Private. + description: Type defines the type of this IPPool, Public, Private + or Project. enum: - Public - Private + - Project type: string type: object status: diff --git a/build/yaml/crd/nsx.vmware.com_networkinfos.yaml b/build/yaml/crd/nsx.vmware.com_networkinfos.yaml index 165830583..fc4620ecd 100644 --- a/build/yaml/crd/nsx.vmware.com_networkinfos.yaml +++ b/build/yaml/crd/nsx.vmware.com_networkinfos.yaml @@ -50,7 +50,7 @@ spec: name: description: VPC name. type: string - privateIPv4CIDRs: + privateIPs: description: Private CIDRs used for the VPC. items: type: string diff --git a/build/yaml/crd/nsx.vmware.com_subnets.yaml b/build/yaml/crd/nsx.vmware.com_subnets.yaml index 378566315..46a838be1 100644 --- a/build/yaml/crd/nsx.vmware.com_subnets.yaml +++ b/build/yaml/crd/nsx.vmware.com_subnets.yaml @@ -60,11 +60,13 @@ spec: type: boolean type: object accessMode: + default: Private description: Access mode of Subnet, accessible only from within VPC or from outside VPC. enum: - Private - Public + - Project type: string advancedConfig: description: Subnet advanced configuration. diff --git a/build/yaml/crd/nsx.vmware.com_subnetsets.yaml b/build/yaml/crd/nsx.vmware.com_subnetsets.yaml index 19433a202..f6ffc81b7 100644 --- a/build/yaml/crd/nsx.vmware.com_subnetsets.yaml +++ b/build/yaml/crd/nsx.vmware.com_subnetsets.yaml @@ -60,11 +60,13 @@ spec: type: boolean type: object accessMode: + default: Private description: Access mode of Subnet, accessible only from within VPC or from outside VPC. enum: - Private - Public + - Project type: string advancedConfig: description: Subnet advanced configuration. diff --git a/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml b/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml index 4911e9a63..07ecf0e31 100644 --- a/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml +++ b/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml @@ -15,17 +15,13 @@ spec: scope: Cluster versions: - additionalPrinterColumns: - - description: NSXTProject the Namespace associated with - jsonPath: .spec.nsxtProject - name: NSXTProject + - description: NsxProject the Namespace associated with + jsonPath: .spec.nsxProject + name: NsxProject type: string - - description: ExternalIPv4Blocks assigned to the Namespace - jsonPath: .spec.externalIPv4Blocks - name: ExternalIPv4Blocks - type: string - - description: PrivateIPv4CIDRs assigned to the Namespace - jsonPath: .spec.privateIPv4CIDRs - name: PrivateIPv4CIDRs + - description: PrivateIPs assigned to the Namespace + jsonPath: .spec.privateIPs + name: PrivateIPs type: string name: v1alpha1 schema: @@ -58,55 +54,60 @@ spec: in a Namespace's VPCNetworkConfiguration, the Namespace will use the value in the default VPCNetworkConfiguration. properties: - defaultGatewayPath: - description: PolicyPath of Tier0 or Tier0 VRF gateway. - type: string - defaultIPv4SubnetSize: + defaultSubnetSize: default: 26 description: |- Default size of Subnet based upon estimated workload count. Defaults to 26. type: integer - defaultSubnetAccessMode: + lbServiceSize: + enum: + - SMALL + - MEDIUM + - LARGE + - XLARGE + type: string + nsxProject: + description: NSX-T Project the Namespace associated with. + type: string + podSubnetAccessMode: description: |- - DefaultSubnetAccessMode defines the access mode of the default SubnetSet for PodVM and VM. + PodSubnetAccessMode defines the access mode of the default SubnetSet for PodVM. Must be Public or Private. enum: - Public - Private + - Project type: string - edgeClusterPath: - description: Edge cluster path on which the networking elements will - be created. - type: string - externalIPv4Blocks: - description: NSX-T IPv4 Block paths used to allocate external Subnets. + privateIPs: + description: Private IPs. items: type: string - maxItems: 5 - minItems: 0 - type: array - nsxtProject: - description: NSX-T Project the Namespace associated with. - type: string - privateIPv4CIDRs: - description: Private IPv4 CIDRs used to allocate Private Subnets. - items: - type: string - maxItems: 5 - minItems: 0 type: array shortID: description: |- ShortID specifies Identifier to use when displaying VPC context in logs. - Less than or equal to 8 characters. + Less than equal to 8 characters. maxLength: 8 type: string vpc: - description: NSX path of the VPC the Namespace associated with. If - vpc is set, only defaultIPv4SubnetSize and defaultSubnetAccessMode + description: |- + NSX path of the VPC the Namespace associated with. + If vpc is set, only defaultIPv4SubnetSize and defaultSubnetAccessMode take effect, other fields are ignored. type: string + vpcConnectivityProfile: + description: VpcConnectivityProfile ID. This profile has configuration + related to create VPC transit gateway attachment. + type: string + vpcServiceProfile: + description: The path of the configuration profile of the VPC services. + This will be an collection of default dhcp and subnet profiles. + The default vpc service profile will be created as part of new project + create workflow. That will be used as the default for all VPC created + under that project. The default value will be project specific default + VPC profile. + type: string type: object status: description: VPCNetworkConfigurationStatus defines the observed state diff --git a/build/yaml/samples/nsx_v1alpha1_networkinfo.yaml b/build/yaml/samples/nsx_v1alpha1_networkinfo.yaml index a548450cc..18433f78f 100644 --- a/build/yaml/samples/nsx_v1alpha1_networkinfo.yaml +++ b/build/yaml/samples/nsx_v1alpha1_networkinfo.yaml @@ -13,6 +13,6 @@ vpcs: - defaultSNATIP: 192.168.0.0 loadBalancerIPAddresses: 172.26.0.0/26 name: vpc-d110d5aa-006d-4b59-9caf-424a4fba932c--kube-system - privateIPv4CIDRs: + privateIPs: - 172.26.0.0/16 vpcPath: /orgs/default/projects/project-quality/vpcs/19a8a52e-beb0-4396-91ce-5821a15a43db \ No newline at end of file diff --git a/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml b/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml index cba5a787f..c61341f26 100644 --- a/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml +++ b/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml @@ -5,14 +5,14 @@ metadata: spec: defaultGatewayPath: /infra/tier-0s/t0 edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/2d9df59f-6dc6-4911-8865-21fadc23d4da - defaultIPv4SubnetSize: 26 - nsxtProject: proj-1 + defaultSubnetSize: 26 + nsxProject: proj-1 externalIPv4Blocks: - block1 - privateIPv4CIDRs: + privateIPs: - 172.26.0.0/16 - 172.36.0.0/16 - defaultSubnetAccessMode: Private + podSubnetAccessMode: Private --- # Sample to create VPCNetworkConfiguration CR using a pre-created NSX VPC. apiVersion: nsx.vmware.com/v1alpha1 @@ -22,4 +22,6 @@ metadata: spec: vpc: /orgs/default/projects/proj-1/vpcs/vpc-1 defaultIPv4SubnetSize: 28 - defaultSubnetAccessMode: Private + podSubnetAccessMode: Private + vpcConnectivityProfile: /orgs/default/projects/wenqi-test/vpc-connectivity-profiles/default + vpcServiceProfile: /orgs/default/projects/wenqi-test/vpc-service-profiles/default diff --git a/pkg/apis/nsx.vmware.com/v1alpha1/networkinfo_types.go b/pkg/apis/nsx.vmware.com/v1alpha1/networkinfo_types.go index 4785fa7ec..5327cec21 100644 --- a/pkg/apis/nsx.vmware.com/v1alpha1/networkinfo_types.go +++ b/pkg/apis/nsx.vmware.com/v1alpha1/networkinfo_types.go @@ -8,8 +8,8 @@ import ( ) // +genclient -//+kubebuilder:object:root=true -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:storageversion // NetworkInfo is used to report the network information for a namespace. // +kubebuilder:resource:path=networkinfos @@ -20,7 +20,7 @@ type NetworkInfo struct { VPCs []VPCState `json:"vpcs"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // NetworkInfoList contains a list of NetworkInfo. type NetworkInfoList struct { @@ -40,7 +40,7 @@ type VPCState struct { // LoadBalancerIPAddresses (AVI SE Subnet CIDR or NSX LB SNAT IPs). LoadBalancerIPAddresses string `json:"loadBalancerIPAddresses,omitempty"` // Private CIDRs used for the VPC. - PrivateIPv4CIDRs []string `json:"privateIPv4CIDRs,omitempty"` + PrivateIPs []string `json:"privateIPs,omitempty"` } func init() { diff --git a/pkg/apis/nsx.vmware.com/v1alpha1/subnet_types.go b/pkg/apis/nsx.vmware.com/v1alpha1/subnet_types.go index 47553cd10..82ecdb839 100644 --- a/pkg/apis/nsx.vmware.com/v1alpha1/subnet_types.go +++ b/pkg/apis/nsx.vmware.com/v1alpha1/subnet_types.go @@ -16,7 +16,8 @@ type SubnetSpec struct { // +kubebuilder:validation:Minimum:=16 IPv4SubnetSize int `json:"ipv4SubnetSize,omitempty"` // Access mode of Subnet, accessible only from within VPC or from outside VPC. - // +kubebuilder:validation:Enum=Private;Public + // +kubebuilder:default:=Private + // +kubebuilder:validation:Enum=Private;Public;Project AccessMode AccessMode `json:"accessMode,omitempty"` // Subnet CIDRS. // +kubebuilder:validation:MinItems=0 @@ -38,9 +39,9 @@ type SubnetStatus struct { } // +genclient -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion // Subnet is the Schema for the subnets API. // +kubebuilder:printcolumn:name="AccessMode",type=string,JSONPath=`.spec.accessMode`,description="Access mode of Subnet" @@ -54,7 +55,7 @@ type Subnet struct { Status SubnetStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // SubnetList contains a list of Subnet. type SubnetList struct { diff --git a/pkg/apis/nsx.vmware.com/v1alpha1/subnetset_types.go b/pkg/apis/nsx.vmware.com/v1alpha1/subnetset_types.go index 3d8883355..275db8762 100644 --- a/pkg/apis/nsx.vmware.com/v1alpha1/subnetset_types.go +++ b/pkg/apis/nsx.vmware.com/v1alpha1/subnetset_types.go @@ -14,7 +14,8 @@ type SubnetSetSpec struct { // +kubebuilder:validation:Minimum:=16 IPv4SubnetSize int `json:"ipv4SubnetSize,omitempty"` // Access mode of Subnet, accessible only from within VPC or from outside VPC. - // +kubebuilder:validation:Enum=Private;Public + // +kubebuilder:default:=Private + // +kubebuilder:validation:Enum=Private;Public;Project AccessMode AccessMode `json:"accessMode,omitempty"` // Subnet advanced configuration. AdvancedConfig AdvancedConfig `json:"advancedConfig,omitempty"` @@ -37,9 +38,9 @@ type SubnetSetStatus struct { } // +genclient -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion // SubnetSet is the Schema for the subnetsets API. // +kubebuilder:printcolumn:name="AccessMode",type=string,JSONPath=`.spec.accessMode`,description="Access mode of Subnet" @@ -53,7 +54,7 @@ type SubnetSet struct { Status SubnetSetStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // SubnetSetList contains a list of SubnetSet. type SubnetSetList struct { diff --git a/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go b/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go index 23355f5f9..e17d46e06 100644 --- a/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go +++ b/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go @@ -9,8 +9,13 @@ import ( ) const ( - AccessModePublic string = "Public" - AccessModePrivate string = "Private" + AccessModePublic string = "Public" + AccessModePrivate string = "Private" + AccessModeProject string = "Project" + LbServiceSizeSmall string = "SMALL" + LbServiceSizeMedium string = "MEDIUM" + LbServiceSizeLarge string = "LARGE" + LbServiceSizeXlarge string = "XLARGE" ) // VPCNetworkConfigurationSpec defines the desired state of VPCNetworkConfiguration. @@ -19,38 +24,41 @@ const ( // in a Namespace's VPCNetworkConfiguration, the Namespace will use the value // in the default VPCNetworkConfiguration. type VPCNetworkConfigurationSpec struct { - // PolicyPath of Tier0 or Tier0 VRF gateway. - DefaultGatewayPath string `json:"defaultGatewayPath,omitempty"` - // Edge cluster path on which the networking elements will be created. - EdgeClusterPath string `json:"edgeClusterPath,omitempty"` // NSX-T Project the Namespace associated with. - NSXTProject string `json:"nsxtProject,omitempty"` - // NSX-T IPv4 Block paths used to allocate external Subnets. - // +kubebuilder:validation:MinItems=0 - // +kubebuilder:validation:MaxItems=5 - ExternalIPv4Blocks []string `json:"externalIPv4Blocks,omitempty"` - // Private IPv4 CIDRs used to allocate Private Subnets. - // +kubebuilder:validation:MinItems=0 - // +kubebuilder:validation:MaxItems=5 - PrivateIPv4CIDRs []string `json:"privateIPv4CIDRs,omitempty"` - // Default size of Subnet based upon estimated workload count. - // Defaults to 26. - // +kubebuilder:default=26 - DefaultIPv4SubnetSize int `json:"defaultIPv4SubnetSize,omitempty"` - // DefaultSubnetAccessMode defines the access mode of the default SubnetSet for PodVM and VM. - // Must be Public or Private. - // +kubebuilder:validation:Enum=Public;Private - DefaultSubnetAccessMode string `json:"defaultSubnetAccessMode,omitempty"` + NsxProject string `json:"nsxProject,omitempty"` + + // VpcConnectivityProfile ID. This profile has configuration related to create VPC transit gateway attachment. + VpcConnectivityProfile string `json:"vpcConnectivityProfile,omitempty"` + + // The path of the configuration profile of the VPC services. This will be an collection of default dhcp and subnet profiles. The default vpc service profile will be created as part of new project create workflow. That will be used as the default for all VPC created under that project. The default value will be project specific default VPC profile. + VpcServiceProfile string `json:"vpcServiceProfile,omitempty"` + + // Private IPs. + PrivateIPs []string `json:"privateIPs,omitempty"` + // ShortID specifies Identifier to use when displaying VPC context in logs. - // Less than or equal to 8 characters. + // Less than equal to 8 characters. // +kubebuilder:validation:MaxLength=8 // +optional ShortID string `json:"shortID,omitempty"` + // NSX path of the VPC the Namespace associated with. // If vpc is set, only defaultIPv4SubnetSize and defaultSubnetAccessMode // take effect, other fields are ignored. // +optional VPC string `json:"vpc,omitempty"` + + // +kubebuilder:validation:Enum=SMALL;MEDIUM;LARGE;XLARGE + LbServiceSize string `json:"lbServiceSize,omitempty"` + + // Default size of Subnet based upon estimated workload count. + // Defaults to 26. + // +kubebuilder:default=26 + DefaultSubnetSize int `json:"defaultSubnetSize,omitempty"` + // PodSubnetAccessMode defines the access mode of the default SubnetSet for PodVM. + // Must be Public or Private. + // +kubebuilder:validation:Enum=Public;Private;Project + PodSubnetAccessMode string `json:"podSubnetAccessMode,omitempty"` } // VPCNetworkConfigurationStatus defines the observed state of VPCNetworkConfiguration @@ -69,15 +77,14 @@ type VPCInfo struct { // +genclient // +genclient:nonNamespaced -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion // VPCNetworkConfiguration is the Schema for the vpcnetworkconfigurations API. // +kubebuilder:resource:scope="Cluster" -// +kubebuilder:printcolumn:name="NSXTProject",type=string,JSONPath=`.spec.nsxtProject`,description="NSXTProject the Namespace associated with" -// +kubebuilder:printcolumn:name="ExternalIPv4Blocks",type=string,JSONPath=`.spec.externalIPv4Blocks`,description="ExternalIPv4Blocks assigned to the Namespace" -// +kubebuilder:printcolumn:name="PrivateIPv4CIDRs",type=string,JSONPath=`.spec.privateIPv4CIDRs`,description="PrivateIPv4CIDRs assigned to the Namespace" +// +kubebuilder:printcolumn:name="NsxProject",type=string,JSONPath=`.spec.nsxProject`,description="NsxProject the Namespace associated with" +// +kubebuilder:printcolumn:name="PrivateIPs",type=string,JSONPath=`.spec.privateIPs`,description="PrivateIPs assigned to the Namespace" type VPCNetworkConfiguration struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -86,7 +93,7 @@ type VPCNetworkConfiguration struct { Status VPCNetworkConfigurationStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // VPCNetworkConfigurationList contains a list of VPCNetworkConfiguration. type VPCNetworkConfigurationList struct { diff --git a/pkg/apis/nsx.vmware.com/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/nsx.vmware.com/v1alpha1/zz_generated.deepcopy.go index 63704edcd..bad151d02 100644 --- a/pkg/apis/nsx.vmware.com/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/nsx.vmware.com/v1alpha1/zz_generated.deepcopy.go @@ -1429,13 +1429,8 @@ func (in *VPCNetworkConfigurationList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VPCNetworkConfigurationSpec) DeepCopyInto(out *VPCNetworkConfigurationSpec) { *out = *in - if in.ExternalIPv4Blocks != nil { - in, out := &in.ExternalIPv4Blocks, &out.ExternalIPv4Blocks - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.PrivateIPv4CIDRs != nil { - in, out := &in.PrivateIPv4CIDRs, &out.PrivateIPv4CIDRs + if in.PrivateIPs != nil { + in, out := &in.PrivateIPs, &out.PrivateIPs *out = make([]string, len(*in)) copy(*out, *in) } @@ -1474,8 +1469,8 @@ func (in *VPCNetworkConfigurationStatus) DeepCopy() *VPCNetworkConfigurationStat // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VPCState) DeepCopyInto(out *VPCState) { *out = *in - if in.PrivateIPv4CIDRs != nil { - in, out := &in.PrivateIPv4CIDRs, &out.PrivateIPv4CIDRs + if in.PrivateIPs != nil { + in, out := &in.PrivateIPs, &out.PrivateIPs *out = make([]string, len(*in)) copy(*out, *in) } diff --git a/pkg/apis/nsx.vmware.com/v1alpha2/ippool_types.go b/pkg/apis/nsx.vmware.com/v1alpha2/ippool_types.go index 469dc43ef..a6d995d7c 100644 --- a/pkg/apis/nsx.vmware.com/v1alpha2/ippool_types.go +++ b/pkg/apis/nsx.vmware.com/v1alpha2/ippool_types.go @@ -10,9 +10,9 @@ import ( ) // +genclient -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion // IPPool is the Schema for the ippools API. // +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type`,description="Type of IPPool" @@ -25,7 +25,7 @@ type IPPool struct { Status IPPoolStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // IPPoolList contains a list of IPPool. type IPPoolList struct { @@ -36,8 +36,8 @@ type IPPoolList struct { // IPPoolSpec defines the desired state of IPPool. type IPPoolSpec struct { - // Type defines the type of this IPPool, Public or Private. - // +kubebuilder:validation:Enum=Public;Private + // Type defines the type of this IPPool, Public, Private or Project. + // +kubebuilder:validation:Enum=Public;Private;Project // +optional Type string `json:"type,omitempty"` // Subnets defines set of subnets need to be allocated. diff --git a/pkg/apis/v1alpha1/networkinfo_types.go b/pkg/apis/v1alpha1/networkinfo_types.go index 4785fa7ec..5327cec21 100644 --- a/pkg/apis/v1alpha1/networkinfo_types.go +++ b/pkg/apis/v1alpha1/networkinfo_types.go @@ -8,8 +8,8 @@ import ( ) // +genclient -//+kubebuilder:object:root=true -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:storageversion // NetworkInfo is used to report the network information for a namespace. // +kubebuilder:resource:path=networkinfos @@ -20,7 +20,7 @@ type NetworkInfo struct { VPCs []VPCState `json:"vpcs"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // NetworkInfoList contains a list of NetworkInfo. type NetworkInfoList struct { @@ -40,7 +40,7 @@ type VPCState struct { // LoadBalancerIPAddresses (AVI SE Subnet CIDR or NSX LB SNAT IPs). LoadBalancerIPAddresses string `json:"loadBalancerIPAddresses,omitempty"` // Private CIDRs used for the VPC. - PrivateIPv4CIDRs []string `json:"privateIPv4CIDRs,omitempty"` + PrivateIPs []string `json:"privateIPs,omitempty"` } func init() { diff --git a/pkg/apis/v1alpha1/subnet_types.go b/pkg/apis/v1alpha1/subnet_types.go index 47553cd10..82ecdb839 100644 --- a/pkg/apis/v1alpha1/subnet_types.go +++ b/pkg/apis/v1alpha1/subnet_types.go @@ -16,7 +16,8 @@ type SubnetSpec struct { // +kubebuilder:validation:Minimum:=16 IPv4SubnetSize int `json:"ipv4SubnetSize,omitempty"` // Access mode of Subnet, accessible only from within VPC or from outside VPC. - // +kubebuilder:validation:Enum=Private;Public + // +kubebuilder:default:=Private + // +kubebuilder:validation:Enum=Private;Public;Project AccessMode AccessMode `json:"accessMode,omitempty"` // Subnet CIDRS. // +kubebuilder:validation:MinItems=0 @@ -38,9 +39,9 @@ type SubnetStatus struct { } // +genclient -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion // Subnet is the Schema for the subnets API. // +kubebuilder:printcolumn:name="AccessMode",type=string,JSONPath=`.spec.accessMode`,description="Access mode of Subnet" @@ -54,7 +55,7 @@ type Subnet struct { Status SubnetStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // SubnetList contains a list of Subnet. type SubnetList struct { diff --git a/pkg/apis/v1alpha1/subnetset_types.go b/pkg/apis/v1alpha1/subnetset_types.go index 3d8883355..275db8762 100644 --- a/pkg/apis/v1alpha1/subnetset_types.go +++ b/pkg/apis/v1alpha1/subnetset_types.go @@ -14,7 +14,8 @@ type SubnetSetSpec struct { // +kubebuilder:validation:Minimum:=16 IPv4SubnetSize int `json:"ipv4SubnetSize,omitempty"` // Access mode of Subnet, accessible only from within VPC or from outside VPC. - // +kubebuilder:validation:Enum=Private;Public + // +kubebuilder:default:=Private + // +kubebuilder:validation:Enum=Private;Public;Project AccessMode AccessMode `json:"accessMode,omitempty"` // Subnet advanced configuration. AdvancedConfig AdvancedConfig `json:"advancedConfig,omitempty"` @@ -37,9 +38,9 @@ type SubnetSetStatus struct { } // +genclient -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion // SubnetSet is the Schema for the subnetsets API. // +kubebuilder:printcolumn:name="AccessMode",type=string,JSONPath=`.spec.accessMode`,description="Access mode of Subnet" @@ -53,7 +54,7 @@ type SubnetSet struct { Status SubnetSetStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // SubnetSetList contains a list of SubnetSet. type SubnetSetList struct { diff --git a/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go b/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go index 23355f5f9..e17d46e06 100644 --- a/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go +++ b/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go @@ -9,8 +9,13 @@ import ( ) const ( - AccessModePublic string = "Public" - AccessModePrivate string = "Private" + AccessModePublic string = "Public" + AccessModePrivate string = "Private" + AccessModeProject string = "Project" + LbServiceSizeSmall string = "SMALL" + LbServiceSizeMedium string = "MEDIUM" + LbServiceSizeLarge string = "LARGE" + LbServiceSizeXlarge string = "XLARGE" ) // VPCNetworkConfigurationSpec defines the desired state of VPCNetworkConfiguration. @@ -19,38 +24,41 @@ const ( // in a Namespace's VPCNetworkConfiguration, the Namespace will use the value // in the default VPCNetworkConfiguration. type VPCNetworkConfigurationSpec struct { - // PolicyPath of Tier0 or Tier0 VRF gateway. - DefaultGatewayPath string `json:"defaultGatewayPath,omitempty"` - // Edge cluster path on which the networking elements will be created. - EdgeClusterPath string `json:"edgeClusterPath,omitempty"` // NSX-T Project the Namespace associated with. - NSXTProject string `json:"nsxtProject,omitempty"` - // NSX-T IPv4 Block paths used to allocate external Subnets. - // +kubebuilder:validation:MinItems=0 - // +kubebuilder:validation:MaxItems=5 - ExternalIPv4Blocks []string `json:"externalIPv4Blocks,omitempty"` - // Private IPv4 CIDRs used to allocate Private Subnets. - // +kubebuilder:validation:MinItems=0 - // +kubebuilder:validation:MaxItems=5 - PrivateIPv4CIDRs []string `json:"privateIPv4CIDRs,omitempty"` - // Default size of Subnet based upon estimated workload count. - // Defaults to 26. - // +kubebuilder:default=26 - DefaultIPv4SubnetSize int `json:"defaultIPv4SubnetSize,omitempty"` - // DefaultSubnetAccessMode defines the access mode of the default SubnetSet for PodVM and VM. - // Must be Public or Private. - // +kubebuilder:validation:Enum=Public;Private - DefaultSubnetAccessMode string `json:"defaultSubnetAccessMode,omitempty"` + NsxProject string `json:"nsxProject,omitempty"` + + // VpcConnectivityProfile ID. This profile has configuration related to create VPC transit gateway attachment. + VpcConnectivityProfile string `json:"vpcConnectivityProfile,omitempty"` + + // The path of the configuration profile of the VPC services. This will be an collection of default dhcp and subnet profiles. The default vpc service profile will be created as part of new project create workflow. That will be used as the default for all VPC created under that project. The default value will be project specific default VPC profile. + VpcServiceProfile string `json:"vpcServiceProfile,omitempty"` + + // Private IPs. + PrivateIPs []string `json:"privateIPs,omitempty"` + // ShortID specifies Identifier to use when displaying VPC context in logs. - // Less than or equal to 8 characters. + // Less than equal to 8 characters. // +kubebuilder:validation:MaxLength=8 // +optional ShortID string `json:"shortID,omitempty"` + // NSX path of the VPC the Namespace associated with. // If vpc is set, only defaultIPv4SubnetSize and defaultSubnetAccessMode // take effect, other fields are ignored. // +optional VPC string `json:"vpc,omitempty"` + + // +kubebuilder:validation:Enum=SMALL;MEDIUM;LARGE;XLARGE + LbServiceSize string `json:"lbServiceSize,omitempty"` + + // Default size of Subnet based upon estimated workload count. + // Defaults to 26. + // +kubebuilder:default=26 + DefaultSubnetSize int `json:"defaultSubnetSize,omitempty"` + // PodSubnetAccessMode defines the access mode of the default SubnetSet for PodVM. + // Must be Public or Private. + // +kubebuilder:validation:Enum=Public;Private;Project + PodSubnetAccessMode string `json:"podSubnetAccessMode,omitempty"` } // VPCNetworkConfigurationStatus defines the observed state of VPCNetworkConfiguration @@ -69,15 +77,14 @@ type VPCInfo struct { // +genclient // +genclient:nonNamespaced -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion // VPCNetworkConfiguration is the Schema for the vpcnetworkconfigurations API. // +kubebuilder:resource:scope="Cluster" -// +kubebuilder:printcolumn:name="NSXTProject",type=string,JSONPath=`.spec.nsxtProject`,description="NSXTProject the Namespace associated with" -// +kubebuilder:printcolumn:name="ExternalIPv4Blocks",type=string,JSONPath=`.spec.externalIPv4Blocks`,description="ExternalIPv4Blocks assigned to the Namespace" -// +kubebuilder:printcolumn:name="PrivateIPv4CIDRs",type=string,JSONPath=`.spec.privateIPv4CIDRs`,description="PrivateIPv4CIDRs assigned to the Namespace" +// +kubebuilder:printcolumn:name="NsxProject",type=string,JSONPath=`.spec.nsxProject`,description="NsxProject the Namespace associated with" +// +kubebuilder:printcolumn:name="PrivateIPs",type=string,JSONPath=`.spec.privateIPs`,description="PrivateIPs assigned to the Namespace" type VPCNetworkConfiguration struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -86,7 +93,7 @@ type VPCNetworkConfiguration struct { Status VPCNetworkConfigurationStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // VPCNetworkConfigurationList contains a list of VPCNetworkConfiguration. type VPCNetworkConfigurationList struct { diff --git a/pkg/apis/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/v1alpha1/zz_generated.deepcopy.go index 63704edcd..bad151d02 100644 --- a/pkg/apis/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/v1alpha1/zz_generated.deepcopy.go @@ -1429,13 +1429,8 @@ func (in *VPCNetworkConfigurationList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VPCNetworkConfigurationSpec) DeepCopyInto(out *VPCNetworkConfigurationSpec) { *out = *in - if in.ExternalIPv4Blocks != nil { - in, out := &in.ExternalIPv4Blocks, &out.ExternalIPv4Blocks - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.PrivateIPv4CIDRs != nil { - in, out := &in.PrivateIPv4CIDRs, &out.PrivateIPv4CIDRs + if in.PrivateIPs != nil { + in, out := &in.PrivateIPs, &out.PrivateIPs *out = make([]string, len(*in)) copy(*out, *in) } @@ -1474,8 +1469,8 @@ func (in *VPCNetworkConfigurationStatus) DeepCopy() *VPCNetworkConfigurationStat // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VPCState) DeepCopyInto(out *VPCState) { *out = *in - if in.PrivateIPv4CIDRs != nil { - in, out := &in.PrivateIPv4CIDRs, &out.PrivateIPv4CIDRs + if in.PrivateIPs != nil { + in, out := &in.PrivateIPs, &out.PrivateIPs *out = make([]string, len(*in)) copy(*out, *in) } diff --git a/pkg/apis/v1alpha2/ippool_types.go b/pkg/apis/v1alpha2/ippool_types.go index 469dc43ef..a6d995d7c 100644 --- a/pkg/apis/v1alpha2/ippool_types.go +++ b/pkg/apis/v1alpha2/ippool_types.go @@ -10,9 +10,9 @@ import ( ) // +genclient -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status -//+kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion // IPPool is the Schema for the ippools API. // +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type`,description="Type of IPPool" @@ -25,7 +25,7 @@ type IPPool struct { Status IPPoolStatus `json:"status,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // IPPoolList contains a list of IPPool. type IPPoolList struct { @@ -36,8 +36,8 @@ type IPPoolList struct { // IPPoolSpec defines the desired state of IPPool. type IPPoolSpec struct { - // Type defines the type of this IPPool, Public or Private. - // +kubebuilder:validation:Enum=Public;Private + // Type defines the type of this IPPool, Public, Private or Project. + // +kubebuilder:validation:Enum=Public;Private;Project // +optional Type string `json:"type,omitempty"` // Subnets defines set of subnets need to be allocated. diff --git a/pkg/controllers/ippool/ippool_controller.go b/pkg/controllers/ippool/ippool_controller.go index 85e0c9722..632d0d3de 100644 --- a/pkg/controllers/ippool/ippool_controller.go +++ b/pkg/controllers/ippool/ippool_controller.go @@ -127,7 +127,7 @@ func (r *IPPoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr } // TODO: As we do not have base controller in Go, we need to take care of NSX exceptions in each controller separately. - //I agree we should not do infinite retry for all errors, but it's ok to add error handling in a following patch + // I agree we should not do infinite retry for all errors, but it's ok to add error handling in a following patch // TODO: Since only the cloud provider creates it, we can take all the validation logic into consideration later. @@ -145,7 +145,7 @@ func (r *IPPoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr updateFail(r, &ctx, obj, &err) return resultRequeue, err } - obj.Spec.Type = vpcNetworkConfig.DefaultSubnetAccessMode + obj.Spec.Type = vpcNetworkConfig.PodSubnetAccessMode } if obj.ObjectMeta.DeletionTimestamp.IsZero() { diff --git a/pkg/controllers/namespace/namespace_controller.go b/pkg/controllers/namespace/namespace_controller.go index 44c14309a..87d5e0cc8 100644 --- a/pkg/controllers/namespace/namespace_controller.go +++ b/pkg/controllers/namespace/namespace_controller.go @@ -57,18 +57,6 @@ func (r *NamespaceReconciler) createNetworkInfoCR(ctx *context.Context, obj clie log.Info("networkInfo already exists", "networkInfo", networkInfos.Items[0].Name, "Namespace", ns) return &networkInfos.Items[0], nil } - nc, ncExist := r.VPCService.GetVPCNetworkConfig(ncName) - if !ncExist { - message := fmt.Sprintf("missing network config %s for namespace %s", ncName, ns) - r.namespaceError(ctx, obj, message, nil) - return nil, errors.New(message) - } - if !r.VPCService.ValidateNetworkConfig(nc) { - // if network config is not valid, no need to retry, skip processing - message := fmt.Sprintf("invalid network config %s for namespace %s, missing private cidr", ncName, ns) - r.namespaceError(ctx, obj, message, nil) - return nil, errors.New(message) - } // create networkInfo cr with existing vpc network config log.V(2).Info("building networkInfo", "ns", ns) @@ -96,7 +84,7 @@ func (r *NamespaceReconciler) createNetworkInfoCR(ctx *context.Context, obj clie return networkInfoCR, nil } -func (r *NamespaceReconciler) createDefaultSubnetSet(ns string) error { +func (r *NamespaceReconciler) createDefaultSubnetSet(ns string, defaultPodAccessMode string) error { defaultSubnetSets := map[string]string{ types.DefaultVMSubnetSet: types.LabelDefaultVMSubnetSet, types.DefaultPodSubnetSet: types.LabelDefaultPodSubnetSet, @@ -132,6 +120,12 @@ func (r *NamespaceReconciler) createDefaultSubnetSet(ns string) error { }, }, } + if name == types.DefaultVMSubnetSet { + // use "Private" type for VM + obj.Spec.AccessMode = v1alpha1.AccessMode("Private") + } else if name == types.DefaultPodSubnetSet { + obj.Spec.AccessMode = v1alpha1.AccessMode(defaultPodAccessMode) + } if err := r.Client.Create(context.Background(), obj); err != nil { return err } @@ -229,10 +223,23 @@ func (r *NamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } } + nc, ncExist := r.VPCService.GetVPCNetworkConfig(ncName) + if !ncExist { + message := fmt.Sprintf("missing network config %s for namespace %s", ncName, ns) + r.namespaceError(&ctx, obj, message, nil) + return common.ResultRequeueAfter10sec, nil + } + if !r.VPCService.ValidateNetworkConfig(nc) { + // if network config is not valid, no need to retry, skip processing + message := fmt.Sprintf("invalid network config %s for namespace %s, missing private cidr", ncName, ns) + r.namespaceError(&ctx, obj, message, nil) + return common.ResultRequeueAfter10sec, nil + } + if _, err := r.createNetworkInfoCR(&ctx, obj, ns, ncName); err != nil { return common.ResultRequeueAfter10sec, nil } - if err := r.createDefaultSubnetSet(ns); err != nil { + if err := r.createDefaultSubnetSet(ns, nc.PodSubnetAccessMode); err != nil { return common.ResultRequeueAfter10sec, nil } return common.ResultNormal, nil diff --git a/pkg/controllers/networkinfo/networkinfo_controller.go b/pkg/controllers/networkinfo/networkinfo_controller.go index 06e62de74..197860a99 100644 --- a/pkg/controllers/networkinfo/networkinfo_controller.go +++ b/pkg/controllers/networkinfo/networkinfo_controller.go @@ -86,7 +86,7 @@ func (r *NetworkInfoReconciler) Reconcile(ctx context.Context, req ctrl.Request) VPCPath: *createdVpc.Path, DefaultSNATIP: "", LoadBalancerIPAddresses: "", - PrivateIPv4CIDRs: nc.PrivateIPv4CIDRs, + PrivateIPs: nc.PrivateIPs, } log.Error(err, "update avi rule failed, would retry exponentially", "NetworkInfo", req.NamespacedName) updateFail(r, &ctx, obj, &err, r.Client, state) @@ -106,7 +106,7 @@ func (r *NetworkInfoReconciler) Reconcile(ctx context.Context, req ctrl.Request) VPCPath: *createdVpc.Path, DefaultSNATIP: "", LoadBalancerIPAddresses: "", - PrivateIPv4CIDRs: nc.PrivateIPv4CIDRs, + PrivateIPs: nc.PrivateIPs, } updateFail(r, &ctx, obj, &err, r.Client, state) return common.ResultRequeueAfter10sec, err @@ -125,7 +125,7 @@ func (r *NetworkInfoReconciler) Reconcile(ctx context.Context, req ctrl.Request) VPCPath: *createdVpc.Path, DefaultSNATIP: snatIP, LoadBalancerIPAddresses: "", - PrivateIPv4CIDRs: nc.PrivateIPv4CIDRs, + PrivateIPs: nc.PrivateIPs, } updateFail(r, &ctx, obj, &err, r.Client, state) return common.ResultRequeueAfter10sec, err @@ -137,7 +137,7 @@ func (r *NetworkInfoReconciler) Reconcile(ctx context.Context, req ctrl.Request) VPCPath: *createdVpc.Path, DefaultSNATIP: snatIP, LoadBalancerIPAddresses: cidr, - PrivateIPv4CIDRs: nc.PrivateIPv4CIDRs, + PrivateIPs: nc.PrivateIPs, } updateSuccess(r, &ctx, obj, r.Client, state, nc.Name, path) } else { diff --git a/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go b/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go index e580dbf2a..cb7a78b9f 100644 --- a/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go +++ b/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go @@ -52,15 +52,8 @@ func (h *VPCNetworkConfigurationHandler) Generic(_ context.Context, _ event.Gene func (h *VPCNetworkConfigurationHandler) Update(ctx context.Context, e event.UpdateEvent, q workqueue.RateLimitingInterface) { log.V(1).Info("start processing VPC network config update event") - oldNc := e.ObjectOld.(*v1alpha1.VPCNetworkConfiguration) newNc := e.ObjectNew.(*v1alpha1.VPCNetworkConfiguration) - if getListSize(oldNc.Spec.ExternalIPv4Blocks) == getListSize(newNc.Spec.ExternalIPv4Blocks) && - getListSize(oldNc.Spec.PrivateIPv4CIDRs) == getListSize(newNc.Spec.PrivateIPv4CIDRs) { - log.V(1).Info("only support updating external/private ipv4 cidr, no change") - return - } - // update network config info in store info, err := buildNetworkConfigInfo(*newNc) if err != nil { @@ -105,33 +98,25 @@ var VPCNetworkConfigurationPredicate = predicate.Funcs{ }, } -func getListSize(s []string) int { - if s == nil { - return 0 - } else { - return len(s) - } -} - func buildNetworkConfigInfo(vpcConfigCR v1alpha1.VPCNetworkConfiguration) (*commontypes.VPCNetworkConfigInfo, error) { - org, project, err := nsxtProjectPathToId(vpcConfigCR.Spec.NSXTProject) + org, project, err := nsxtProjectPathToId(vpcConfigCR.Spec.NsxProject) if err != nil { - log.Error(err, "failed to parse nsx-t project in network config", "Project Path", vpcConfigCR.Spec.NSXTProject) + log.Error(err, "failed to parse nsx-t project in network config", "Project Path", vpcConfigCR.Spec.NsxProject) return nil, err } ninfo := &commontypes.VPCNetworkConfigInfo{ - IsDefault: isDefaultNetworkConfigCR(vpcConfigCR), - Org: org, - Name: vpcConfigCR.Name, - DefaultGatewayPath: vpcConfigCR.Spec.DefaultGatewayPath, - EdgeClusterPath: vpcConfigCR.Spec.EdgeClusterPath, - NsxtProject: project, - ExternalIPv4Blocks: vpcConfigCR.Spec.ExternalIPv4Blocks, - PrivateIPv4CIDRs: vpcConfigCR.Spec.PrivateIPv4CIDRs, - DefaultIPv4SubnetSize: vpcConfigCR.Spec.DefaultIPv4SubnetSize, - DefaultSubnetAccessMode: vpcConfigCR.Spec.DefaultSubnetAccessMode, - ShortID: vpcConfigCR.Spec.ShortID, + IsDefault: isDefaultNetworkConfigCR(vpcConfigCR), + Org: org, + Name: vpcConfigCR.Name, + VpcConnectivityProfile: vpcConfigCR.Spec.VpcConnectivityProfile, + VpcServiceProfile: vpcConfigCR.Spec.VpcServiceProfile, + LbServiceSize: vpcConfigCR.Spec.LbServiceSize, + NsxProject: project, + PrivateIPs: vpcConfigCR.Spec.PrivateIPs, + DefaultSubnetSize: vpcConfigCR.Spec.DefaultSubnetSize, + PodSubnetAccessMode: vpcConfigCR.Spec.PodSubnetAccessMode, + ShortID: vpcConfigCR.Spec.ShortID, } return ninfo, nil } @@ -150,7 +135,7 @@ func isDefaultNetworkConfigCR(vpcConfigCR v1alpha1.VPCNetworkConfiguration) bool return false } -// parse org id and project id from nsxtProject path +// parse org id and project id from nsxProject path // example /orgs/default/projects/nsx_operator_e2e_test func nsxtProjectPathToId(path string) (string, string, error) { parts := strings.Split(path, "/") diff --git a/pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go b/pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go index 85a464933..b4ca96f64 100644 --- a/pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go +++ b/pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go @@ -64,7 +64,7 @@ func TestBuildNetworkConfigInfo(t *testing.T) { emptyCRD := &v1alpha1.VPCNetworkConfiguration{} emptyCRD2 := &v1alpha1.VPCNetworkConfiguration{ Spec: v1alpha1.VPCNetworkConfigurationSpec{ - NSXTProject: "/invalid/path", + NsxProject: "/invalid/path", }, } _, e := buildNetworkConfigInfo(*emptyCRD) @@ -73,22 +73,24 @@ func TestBuildNetworkConfigInfo(t *testing.T) { assert.NotNil(t, e) spec1 := v1alpha1.VPCNetworkConfigurationSpec{ - DefaultGatewayPath: "test-gw-path-1", - EdgeClusterPath: "test-edge-path-1", - ExternalIPv4Blocks: []string{"external-ipb-1", "external-ipb-2"}, - PrivateIPv4CIDRs: []string{"private-ipb-1", "private-ipb-2"}, - DefaultIPv4SubnetSize: 64, - DefaultSubnetAccessMode: "Public", - NSXTProject: "/orgs/default/projects/nsx_operator_e2e_test", + // DefaultGatewayPath: "test-gw-path-1", + // EdgeClusterPath: "test-edge-path-1", + // ExternalIPv4Blocks: []string{"external-ipb-1", "external-ipb-2"}, + PrivateIPs: []string{"private-ipb-1", "private-ipb-2"}, + DefaultSubnetSize: 64, + // VPCServiceProfile: "test-VpcServiceProfile", + VpcConnectivityProfile: "test-VpcConnectivityProfile", + PodSubnetAccessMode: "Public", + NsxProject: "/orgs/default/projects/nsx_operator_e2e_test", } spec2 := v1alpha1.VPCNetworkConfigurationSpec{ - DefaultGatewayPath: "test-gw-path-2", - EdgeClusterPath: "test-edge-path-2", - ExternalIPv4Blocks: []string{"external-ipb-1", "external-ipb-2"}, - PrivateIPv4CIDRs: []string{"private-ipb-1", "private-ipb-2"}, - DefaultIPv4SubnetSize: 32, - DefaultSubnetAccessMode: "Private", - NSXTProject: "/orgs/anotherOrg/projects/anotherProject", + // DefaultGatewayPath: "test-gw-path-2", + // EdgeClusterPath: "test-edge-path-2", + // ExternalIPv4Blocks: []string{"external-ipb-1", "external-ipb-2"}, + PrivateIPs: []string{"private-ipb-1", "private-ipb-2"}, + DefaultSubnetSize: 32, + PodSubnetAccessMode: "Private", + NsxProject: "/orgs/anotherOrg/projects/anotherProject", } testCRD1 := v1alpha1.VPCNetworkConfiguration{ Spec: spec1, @@ -110,30 +112,31 @@ func TestBuildNetworkConfigInfo(t *testing.T) { testCRD3.Name = "test-3" tests := []struct { - name string - nc v1alpha1.VPCNetworkConfiguration - gw string - edge string - org string - project string - subnetSize int - accessMode string - isDefault bool + name string + nc v1alpha1.VPCNetworkConfiguration + gw string + edge string + org string + project string + subnetSize int + accessMode string + isDefault bool + vpcConnectivityProfile string }{ - {"1", testCRD1, "test-gw-path-1", "test-edge-path-1", "default", "nsx_operator_e2e_test", 64, "Public", false}, - {"2", testCRD2, "test-gw-path-2", "test-edge-path-2", "anotherOrg", "anotherProject", 32, "Private", false}, - {"3", testCRD3, "test-gw-path-2", "test-edge-path-2", "anotherOrg", "anotherProject", 32, "Private", true}, + {"test-nsxtProjectPathToId", testCRD1, "test-gw-path-1", "test-edge-path-1", "default", "nsx_operator_e2e_test", 64, "Public", false, ""}, + {"with-VpcConnectivityProfile", testCRD2, "test-gw-path-2", "test-edge-path-2", "anotherOrg", "anotherProject", 32, "Private", false, "test-VpcConnectivityProfile"}, + {"with-defaultNetworkConfig", testCRD3, "test-gw-path-2", "test-edge-path-2", "anotherOrg", "anotherProject", 32, "Private", true, ""}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { nc, e := buildNetworkConfigInfo(tt.nc) assert.Nil(t, e) - assert.Equal(t, tt.gw, nc.DefaultGatewayPath) - assert.Equal(t, tt.edge, nc.EdgeClusterPath) + // assert.Equal(t, tt.gw, nc.DefaultGatewayPath) + // assert.Equal(t, tt.edge, nc.EdgeClusterPath) assert.Equal(t, tt.org, nc.Org) - assert.Equal(t, tt.project, nc.NsxtProject) - assert.Equal(t, tt.subnetSize, nc.DefaultIPv4SubnetSize) - assert.Equal(t, tt.accessMode, nc.DefaultSubnetAccessMode) + assert.Equal(t, tt.project, nc.NsxProject) + assert.Equal(t, tt.subnetSize, nc.DefaultSubnetSize) + assert.Equal(t, tt.accessMode, nc.PodSubnetAccessMode) assert.Equal(t, tt.isDefault, nc.IsDefault) }) } diff --git a/pkg/controllers/subnet/subnet_controller.go b/pkg/controllers/subnet/subnet_controller.go index d2de63968..cd8261b32 100644 --- a/pkg/controllers/subnet/subnet_controller.go +++ b/pkg/controllers/subnet/subnet_controller.go @@ -83,11 +83,12 @@ func (r *SubnetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr updateFail(r, &ctx, obj, "") return ResultRequeue, err } + if obj.Spec.AccessMode == "" { - obj.Spec.AccessMode = v1alpha1.AccessMode(vpcNetworkConfig.DefaultSubnetAccessMode) + obj.Spec.AccessMode = v1alpha1.AccessMode(v1alpha1.AccessModePrivate) } if obj.Spec.IPv4SubnetSize == 0 { - obj.Spec.IPv4SubnetSize = vpcNetworkConfig.DefaultIPv4SubnetSize + obj.Spec.IPv4SubnetSize = vpcNetworkConfig.DefaultSubnetSize } } tags := r.SubnetService.GenerateSubnetNSTags(obj, obj.Namespace) diff --git a/pkg/controllers/subnetset/subnetset_controller.go b/pkg/controllers/subnetset/subnetset_controller.go index b50fa42b6..72640a025 100644 --- a/pkg/controllers/subnetset/subnetset_controller.go +++ b/pkg/controllers/subnetset/subnetset_controller.go @@ -74,11 +74,12 @@ func (r *SubnetSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( updateFail(r, &ctx, obj, "") return ResultRequeue, err } + if obj.Spec.AccessMode == "" { - obj.Spec.AccessMode = v1alpha1.AccessMode(vpcNetworkConfig.DefaultSubnetAccessMode) + obj.Spec.AccessMode = v1alpha1.AccessMode(v1alpha1.AccessModePrivate) } if obj.Spec.IPv4SubnetSize == 0 { - obj.Spec.IPv4SubnetSize = vpcNetworkConfig.DefaultIPv4SubnetSize + obj.Spec.IPv4SubnetSize = vpcNetworkConfig.DefaultSubnetSize } } if err := r.Client.Update(ctx, obj); err != nil { diff --git a/pkg/nsx/services/common/types.go b/pkg/nsx/services/common/types.go index 08d671dff..9f9b7ed62 100644 --- a/pkg/nsx/services/common/types.go +++ b/pkg/nsx/services/common/types.go @@ -191,19 +191,20 @@ type VPCResourceInfo struct { ID string ParentID string PrivateIpv4Blocks []string - ExternalIPv4Blocks []string + ExternalIPv4Blocks []string // deprecated, existing field } type VPCNetworkConfigInfo struct { - IsDefault bool - Org string - Name string - DefaultGatewayPath string - EdgeClusterPath string - NsxtProject string - ExternalIPv4Blocks []string - PrivateIPv4CIDRs []string - DefaultIPv4SubnetSize int - DefaultSubnetAccessMode string - ShortID string + IsDefault bool + Org string + Name string + VpcConnectivityProfile string + VpcServiceProfile string + LbServiceSize string + NsxProject string + ExternalIPv4Blocks []string + PrivateIPs []string + DefaultSubnetSize int + PodSubnetAccessMode string + ShortID string } diff --git a/pkg/nsx/services/vpc/builder.go b/pkg/nsx/services/vpc/builder.go index 5189ac73e..5dc71fa11 100644 --- a/pkg/nsx/services/vpc/builder.go +++ b/pkg/nsx/services/vpc/builder.go @@ -50,9 +50,7 @@ func buildPrivateIpBlock(networkInfo *v1alpha1.NetworkInfo, nsObj *v1.Namespace, return block } -func buildNSXVPC(obj *v1alpha1.NetworkInfo, nsObj *v1.Namespace, nc common.VPCNetworkConfigInfo, cluster string, pathMap map[string]string, - nsxVPC *model.Vpc) (*model.Vpc, - error) { +func buildNSXVPC(obj *v1alpha1.NetworkInfo, nsObj *v1.Namespace, nc common.VPCNetworkConfigInfo, cluster string, pathMap map[string]string, nsxVPC *model.Vpc) (*model.Vpc, error) { vpc := &model.Vpc{} if nsxVPC != nil { // for upgrade case, only check public/private ip block size changing @@ -67,21 +65,16 @@ func buildNSXVPC(obj *v1alpha1.NetworkInfo, nsObj *v1.Namespace, nc common.VPCNe vpcName := util.GenerateDisplayName("", "vpc", obj.GetNamespace(), "", cluster) vpc.DisplayName = &vpcName vpc.Id = common.String(string(nsObj.GetUID())) - vpc.DefaultGatewayPath = &nc.DefaultGatewayPath vpc.IpAddressType = &DefaultVPCIPAddressType - siteInfos := []model.SiteInfo{ - { - EdgeClusterPaths: []string{nc.EdgeClusterPath}, - }, - } - vpc.SiteInfos = siteInfos vpc.LoadBalancerVpcEndpoint = &model.LoadBalancerVPCEndpoint{Enabled: &DefaultLoadBalancerVPCEndpointEnabled} vpc.Tags = util.BuildBasicTags(cluster, obj, nsObj.UID) } - // update private/public blocks - vpc.ExternalIpv4Blocks = nc.ExternalIPv4Blocks + vpc.VpcConnectivityProfile = &nc.VpcConnectivityProfile + vpc.VpcServiceProfile = &nc.VpcServiceProfile + + // vpc.PrivateIps = nc.PrivateIPs vpc.PrivateIpv4Blocks = util.GetMapValues(pathMap) if nc.ShortID != "" { vpc.ShortId = &nc.ShortID diff --git a/pkg/nsx/services/vpc/compare.go b/pkg/nsx/services/vpc/compare.go index f41ccb66c..78b08f1e8 100644 --- a/pkg/nsx/services/vpc/compare.go +++ b/pkg/nsx/services/vpc/compare.go @@ -13,7 +13,7 @@ func IsVPCChanged(nc common.VPCNetworkConfigInfo, vpc *model.Vpc) bool { return true } - if len(nc.PrivateIPv4CIDRs) != len(vpc.PrivateIpv4Blocks) { + if len(nc.PrivateIPs) != len(vpc.PrivateIpv4Blocks) { return true } diff --git a/pkg/nsx/services/vpc/vpc.go b/pkg/nsx/services/vpc/vpc.go index 415b92773..6ecc07ced 100644 --- a/pkg/nsx/services/vpc/vpc.go +++ b/pkg/nsx/services/vpc/vpc.go @@ -139,7 +139,7 @@ func (s *VPCService) GetVPCNetworkConfigByNamespace(ns string) *common.VPCNetwor // TBD: for now, if network config info do not contains private cidr, we consider this is // incorrect configuration, and skip creating this VPC CR func (s *VPCService) ValidateNetworkConfig(nc common.VPCNetworkConfigInfo) bool { - return nc.PrivateIPv4CIDRs != nil && len(nc.PrivateIPv4CIDRs) != 0 + return nc.PrivateIPs != nil && len(nc.PrivateIPs) != 0 } // InitializeVPC sync NSX resources @@ -173,11 +173,11 @@ func InitializeVPC(service common.Service) (*VPCService, error) { VPCService.VPCNSNetworkConfigStore = VPCNsNetworkConfigStore{ VPCNSNetworkConfigMap: make(map[string]string), } - //initialize vpc store and ip blocks store + // initialize vpc store and ip blocks store go VPCService.InitializeResourceStore(&wg, fatalErrors, common.ResourceTypeVpc, nil, VPCService.VpcStore) go VPCService.InitializeResourceStore(&wg, fatalErrors, common.ResourceTypeIPBlock, nil, VPCService.IpblockStore) - //initalize avi rule related store + // initialize avi rule related store if enableAviAllowRule { VPCService.RuleStore = &AviRuleStore{ResourceStore: common.ResourceStore{ Indexer: cache.NewIndexer(keyFuncAVI, nil), @@ -306,8 +306,8 @@ func (s *VPCService) CreateOrUpdatePrivateIPBlock(obj *v1alpha1.NetworkInfo, nsO error) { // if network config contains PrivateIPV4CIDRs section, create private ip block for each cidr path := map[string]string{} - if nc.PrivateIPv4CIDRs != nil { - for _, pCidr := range nc.PrivateIPv4CIDRs { + if nc.PrivateIPs != nil { + for _, pCidr := range nc.PrivateIPs { log.Info("start processing private cidr", "cidr", pCidr) // if parse success, then check if private cidr exist, here we suppose it must be a cidr format string ip, _, err := net.ParseCIDR(pCidr) @@ -324,10 +324,10 @@ func (s *VPCService) CreateOrUpdatePrivateIPBlock(obj *v1alpha1.NetworkInfo, nsO block := s.IpblockStore.GetByKey(key) if block == nil { log.Info("no ip block found in store for cidr", "CIDR", pCidr) - block := buildPrivateIpBlock(obj, nsObj, pCidr, ip.String(), nc.NsxtProject, s.NSXConfig.Cluster) + block := buildPrivateIpBlock(obj, nsObj, pCidr, ip.String(), nc.NsxProject, s.NSXConfig.Cluster) log.Info("creating ip block", "IPBlock", block.Id, "VPC", obj.Name) // can not find private ip block from store, create one - _err := s.NSXClient.IPBlockClient.Patch(nc.Org, nc.NsxtProject, *block.Id, block) + _err := s.NSXClient.IPBlockClient.Patch(nc.Org, nc.NsxProject, *block.Id, block) _err = nsxutil.NSXApiError(_err) if _err != nil { message := fmt.Sprintf("failed to create private ip block for cidr %s for VPC %s", pCidr, obj.Name) @@ -336,11 +336,11 @@ func (s *VPCService) CreateOrUpdatePrivateIPBlock(obj *v1alpha1.NetworkInfo, nsO return nil, ipblockError } ignoreIpblockUsage := true - createdBlock, err := s.NSXClient.IPBlockClient.Get(nc.Org, nc.NsxtProject, *block.Id, &ignoreIpblockUsage) + createdBlock, err := s.NSXClient.IPBlockClient.Get(nc.Org, nc.NsxProject, *block.Id, &ignoreIpblockUsage) err = nsxutil.NSXApiError(err) if err != nil { // created by can not get, ignore this error - log.Info("failed to read ip blocks from NSX", "Project", nc.NsxtProject, "IPBlock", block.Id) + log.Info("failed to read ip blocks from NSX", "Project", nc.NsxProject, "IPBlock", block.Id) continue } // update ip block store @@ -569,13 +569,13 @@ func (s *VPCService) CreateOrUpdateVPC(obj *v1alpha1.NetworkInfo) (*model.Vpc, * } log.Info("creating NSX VPC", "VPC", *createdVpc.Id) - err = s.NSXClient.VPCClient.Patch(nc.Org, nc.NsxtProject, *createdVpc.Id, *createdVpc) + err = s.NSXClient.VPCClient.Patch(nc.Org, nc.NsxProject, *createdVpc.Id, *createdVpc) err = nsxutil.NSXApiError(err) if err != nil { - log.Error(err, "failed to create VPC", "Project", nc.NsxtProject, "Namespace", obj.Namespace) + log.Error(err, "failed to create VPC", "Project", nc.NsxProject, "Namespace", obj.Namespace) // TODO: this seems to be a nsx bug, in some case, even if nsx returns failed but the object is still created. log.Info("try to read VPC although VPC creation failed", "VPC", *createdVpc.Id) - failedVpc, rErr := s.NSXClient.VPCClient.Get(nc.Org, nc.NsxtProject, *createdVpc.Id) + failedVpc, rErr := s.NSXClient.VPCClient.Get(nc.Org, nc.NsxProject, *createdVpc.Id) rErr = nsxutil.NSXApiError(rErr) if rErr != nil { // failed to read, but already created, we consider this scenario as success, but store may not sync with nsx @@ -588,7 +588,7 @@ func (s *VPCService) CreateOrUpdateVPC(obj *v1alpha1.NetworkInfo) (*model.Vpc, * } // get the created vpc from nsx, it contains the path of the resources - newVpc, err := s.NSXClient.VPCClient.Get(nc.Org, nc.NsxtProject, *createdVpc.Id) + newVpc, err := s.NSXClient.VPCClient.Get(nc.Org, nc.NsxProject, *createdVpc.Id) err = nsxutil.NSXApiError(err) if err != nil { // failed to read, but already created, we consider this scenario as success, but store may not sync with nsx diff --git a/test/e2e/manifest/testVPC/customize_networkconfig.yaml b/test/e2e/manifest/testVPC/customize_networkconfig.yaml index 913c8e46d..bc53320b8 100644 --- a/test/e2e/manifest/testVPC/customize_networkconfig.yaml +++ b/test/e2e/manifest/testVPC/customize_networkconfig.yaml @@ -5,15 +5,11 @@ kind: VPCNetworkConfiguration metadata: name: selfdefinedconfig spec: - defaultGatewayPath: /infra/tier-0s/PLR - # nsx-operator-ci would replace '{edge-cluster-id}' with real edge-cluster-id of testbed - edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/{edge-cluster-id} - defaultIPv4SubnetSize: 26 - nsxtProject: /orgs/default/projects/nsx_operator_e2e_test - externalIPv4Blocks: - - /infra/ip-blocks/e2e_test_external_ip_blk - privateIPv4CIDRs: + defaultSubnetSize: 26 + nsxProject: /orgs/default/projects/nsx_operator_e2e_test + privateIPs: - 172.29.0.0/16 - 172.39.0.0/16 - defaultSubnetAccessMode: Public - \ No newline at end of file + podSubnetAccessMode: Public + vpcConnectivityProfile: /orgs/default/projects/nsx_operator_e2e_test/vpc-connectivity-profiles/default + vpcServiceProfile: /orgs/default/projects/nsx_operator_e2e_test/vpc-service-profiles/default \ No newline at end of file diff --git a/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml b/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml index a718cd518..063d4c933 100644 --- a/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml +++ b/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml @@ -5,16 +5,13 @@ kind: VPCNetworkConfiguration metadata: name: selfdefinedconfig spec: - defaultGatewayPath: /infra/tier-0s/PLR - # nsx-operator-ci would replace '{edge-cluster-id}' with real edge-cluster-id of testbed - edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/{edge-cluster-id} - defaultIPv4SubnetSize: 26 - nsxtProject: /orgs/default/projects/nsx_operator_e2e_test - externalIPv4Blocks: - - /infra/ip-blocks/e2e_test_external_ip_blk - privateIPv4CIDRs: + defaultSubnetSize: 26 + nsxProject: /orgs/default/projects/nsx_operator_e2e_test + privateIPs: - 172.29.0.0/16 - 172.39.0.0/16 - 172.49.0.0/16 - defaultSubnetAccessMode: Public + podSubnetAccessMode: Public + vpcConnectivityProfile: /orgs/default/projects/nsx_operator_e2e_test/vpc-connectivity-profiles/default + vpcServiceProfile: /orgs/default/projects/nsx_operator_e2e_test/vpc-service-profiles/default \ No newline at end of file diff --git a/test/e2e/manifest/testVPC/default_networkconfig.yaml b/test/e2e/manifest/testVPC/default_networkconfig.yaml index dbfb2edb3..7b807006b 100644 --- a/test/e2e/manifest/testVPC/default_networkconfig.yaml +++ b/test/e2e/manifest/testVPC/default_networkconfig.yaml @@ -9,14 +9,11 @@ metadata: annotations: nsx.vmware.com/default: "true" spec: - defaultGatewayPath: /infra/tier-0s/PLR - # nsx-operator-ci would replace '{edge-cluster-id}' with real edge-cluster-id of testbed - edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/{edge-cluster-id} - defaultIPv4SubnetSize: 26 - nsxtProject: /orgs/default/projects/nsx_operator_e2e_test - externalIPv4Blocks: - - /infra/ip-blocks/e2e_test_external_ip_blk - privateIPv4CIDRs: + defaultSubnetSize: 26 + nsxProject: /orgs/default/projects/nsx_operator_e2e_test + privateIPs: - 172.28.0.0/16 - 172.38.0.0/16 - defaultSubnetAccessMode: Public + podSubnetAccessMode: Public + vpcConnectivityProfile: /orgs/default/projects/nsx_operator_e2e_test/vpc-connectivity-profiles/default + vpcServiceProfile: /orgs/default/projects/nsx_operator_e2e_test/vpc-service-profiles/default diff --git a/test/e2e/manifest/testVPC/system_networkconfig.yaml b/test/e2e/manifest/testVPC/system_networkconfig.yaml index 843f7b5d0..e4bfcb982 100644 --- a/test/e2e/manifest/testVPC/system_networkconfig.yaml +++ b/test/e2e/manifest/testVPC/system_networkconfig.yaml @@ -6,15 +6,12 @@ kind: VPCNetworkConfiguration metadata: name: system spec: - defaultGatewayPath: /infra/tier-0s/PLR - # nsx-operator-ci would replace '{edge-cluster-id}' with real edge-cluster-id of testbed - edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/{edge-cluster-id} - defaultIPv4SubnetSize: 26 - nsxtProject: /orgs/default/projects/nsx_operator_e2e_test - externalIPv4Blocks: - - /infra/ip-blocks/e2e_test_external_ip_blk - privateIPv4CIDRs: + defaultSubnetSize: 26 + nsxProject: /orgs/default/projects/nsx_operator_e2e_test + privateIPs: - 172.27.0.0/16 - 172.37.0.0/16 - defaultSubnetAccessMode: Public + podSubnetAccessMode: Public + vpcConnectivityProfile: /orgs/default/projects/nsx_operator_e2e_test/vpc-connectivity-profiles/default + vpcServiceProfile: /orgs/default/projects/nsx_operator_e2e_test/vpc-service-profiles/default \ No newline at end of file diff --git a/test/e2e/nsx_networkinfo_test.go b/test/e2e/nsx_networkinfo_test.go index de628682e..ec99df325 100644 --- a/test/e2e/nsx_networkinfo_test.go +++ b/test/e2e/nsx_networkinfo_test.go @@ -78,7 +78,7 @@ func TestCustomizedNetworkInfo(t *testing.T) { err := testData.waitForResourceExistByPath(vpcPath, true) assertNil(t, err) - //verify private ipblocks created for vpc + // verify private ipblocks created for vpc p_ipb_id1 := ns_uid + "_" + CustomizedPrivateCIDR1 p_ipb_id2 := ns_uid + "_" + CustomizedPrivateCIDR2 @@ -97,7 +97,7 @@ func TestInfraNetworkInfo(t *testing.T) { err := testData.waitForResourceExistByPath(vpcPath, true) assertNil(t, err) - //verify private ipblocks created for vpc + // verify private ipblocks created for vpc p_ipb_id1 := ns_uid + "_" + InfraPrivateCIDR1 p_ipb_id2 := ns_uid + "_" + InfraPrivateCIDR2 @@ -128,7 +128,7 @@ func TestDefaultNetworkInfo(t *testing.T) { err := testData.waitForResourceExistByPath(vpcPath, true) assertNil(t, err) - //verify private ipblocks created for vpc, id is nsuid + cidr + // verify private ipblocks created for vpc, id is nsuid + cidr p_ipb_id1 := ns_uid + "_" + DefaultPrivateCIDR1 p_ipb_id2 := ns_uid + "_" + DefaultPrivateCIDR2 @@ -171,7 +171,7 @@ func TestSharedNetworkInfo(t *testing.T) { assertTrue(t, vpcPath == vpcPath1, "vpcPath %s should be the same as vpcPath2 %s", vpcPath, vpcPath1) - //verify private ipblocks created for vpc, id is nsuid + cidr + // verify private ipblocks created for vpc, id is nsuid + cidr p_ipb_id1 := ns_uid + "_" + CustomizedPrivateCIDR1 p_ipb_id2 := ns_uid + "_" + CustomizedPrivateCIDR2 @@ -205,12 +205,12 @@ func TestUpdateVPCNetworkconfigNetworkInfo(t *testing.T) { // Check networkinfo cr existence networkinfo_name, _ := verifyCRCreated(t, NetworkInfoCRType, ns, 1) - privateIPv4CIDRs, err := testData.getCRPropertiesByJson(defaultTimeout, NetworkInfoCRType, networkinfo_name, ns, ".vpcs[0].privateIPv4CIDRs") - assertTrue(t, strings.Contains(privateIPv4CIDRs, CustomizedPrivateCIDR1), "privateIPv4CIDRs %s should contain %s", privateIPv4CIDRs, CustomizedPrivateCIDR1) - assertTrue(t, strings.Contains(privateIPv4CIDRs, CustomizedPrivateCIDR2), "privateIPv4CIDRs %s should contain %s", privateIPv4CIDRs, CustomizedPrivateCIDR1) + privateIPs, err := testData.getCRPropertiesByJson(defaultTimeout, NetworkInfoCRType, networkinfo_name, ns, ".vpcs[0].privateIPs") + assertTrue(t, strings.Contains(privateIPs, CustomizedPrivateCIDR1), "privateIPs %s should contain %s", privateIPs, CustomizedPrivateCIDR1) + assertTrue(t, strings.Contains(privateIPs, CustomizedPrivateCIDR2), "privateIPs %s should contain %s", privateIPs, CustomizedPrivateCIDR1) assertNil(t, err) - //verify private ipblocks created for vpc, id is nsuid + cidr + // verify private ipblocks created for vpc, id is nsuid + cidr p_ipb_id1 := ns_uid + "_" + CustomizedPrivateCIDR1 p_ipb_id2 := ns_uid + "_" + CustomizedPrivateCIDR2 @@ -220,8 +220,8 @@ func TestUpdateVPCNetworkconfigNetworkInfo(t *testing.T) { vncPath, _ := filepath.Abs("./manifest/testVPC/customize_networkconfig_updated.yaml") _ = applyYAML(vncPath, "") - privateIPv4CIDRs, err = testData.getCRPropertiesByJson(defaultTimeout, NetworkInfoCRType, networkinfo_name, ns, ".vpcs[0].privateIPv4CIDRs") - assertTrue(t, strings.Contains(privateIPv4CIDRs, CustomizedPrivateCIDR3), "privateIPv4CIDRs %s should contain %s", privateIPv4CIDRs, CustomizedPrivateCIDR3) + privateIPs, err = testData.getCRPropertiesByJson(defaultTimeout, NetworkInfoCRType, networkinfo_name, ns, ".vpcs[0].privateIPs") + assertTrue(t, strings.Contains(privateIPs, CustomizedPrivateCIDR3), "privateIPs %s should contain %s", privateIPs, CustomizedPrivateCIDR3) assertNil(t, err) p_ipb_id3 := ns_uid + "_" + CustomizedPrivateCIDR3 verifyPrivateIPBlockCreated(t, ns, p_ipb_id3) diff --git a/test/e2e/nsx_subnet_test.go b/test/e2e/nsx_subnet_test.go index f89b56408..6fb1bb2c2 100644 --- a/test/e2e/nsx_subnet_test.go +++ b/test/e2e/nsx_subnet_test.go @@ -41,12 +41,12 @@ func verifySubnetSetCR(subnetSet string) bool { log.Printf("Failed to get %s/%s: %s", E2ENamespace, subnetSet, err) return false } - if string(subnetSetCR.Spec.AccessMode) != vpcNetworkConfig.Spec.DefaultSubnetAccessMode { - log.Printf("AccessMode is %s, while it's expected to be %s", subnetSetCR.Spec.AccessMode, vpcNetworkConfig.Spec.DefaultSubnetAccessMode) + if string(subnetSetCR.Spec.AccessMode) != vpcNetworkConfig.Spec.PodSubnetAccessMode { + log.Printf("AccessMode is %s, while it's expected to be %s", subnetSetCR.Spec.AccessMode, vpcNetworkConfig.Spec.PodSubnetAccessMode) return false } - if subnetSetCR.Spec.IPv4SubnetSize != vpcNetworkConfig.Spec.DefaultIPv4SubnetSize { - log.Printf("IPv4SubnetSize is %d, while it's expected to be %d", subnetSetCR.Spec.IPv4SubnetSize, vpcNetworkConfig.Spec.DefaultIPv4SubnetSize) + if subnetSetCR.Spec.IPv4SubnetSize != vpcNetworkConfig.Spec.DefaultSubnetSize { + log.Printf("IPv4SubnetSize is %d, while it's expected to be %d", subnetSetCR.Spec.IPv4SubnetSize, vpcNetworkConfig.Spec.DefaultSubnetSize) return false } return true