From 99bdedaf16c63dbc43cb4e911e1aa255c3f3c914 Mon Sep 17 00:00:00 2001 From: Wenqi Qiu Date: Thu, 4 Jul 2024 11:03:03 +0800 Subject: [PATCH] update vpcnetworkconfigurations crd Signed-off-by: Wenqi Qiu --- .../yaml/crd/nsx.vmware.com_networkinfos.yaml | 2 +- ...x.vmware.com_vpcnetworkconfigurations.yaml | 32 +++++++++---------- .../samples/nsx_v1alpha1_networkinfo.yaml | 2 +- ...nsx_v1alpha1_vpcnetworkconfigurations.yaml | 6 ++-- .../v1alpha1/networkinfo_types.go | 8 ++--- .../v1alpha1/vpcnetworkconfiguration_types.go | 32 +++++++++---------- .../v1alpha1/zz_generated.deepcopy.go | 8 ++--- pkg/apis/v1alpha1/networkinfo_types.go | 8 ++--- .../v1alpha1/vpcnetworkconfiguration_types.go | 32 +++++++++---------- pkg/apis/v1alpha1/zz_generated.deepcopy.go | 8 ++--- pkg/controllers/ippool/ippool_controller.go | 2 +- .../networkinfo/networkinfo_controller.go | 8 ++--- .../networkinfo/vpcnetworkconfig_handler.go | 20 ++++++------ .../vpcnetworkconfig_handler_test.go | 22 ++++++------- pkg/controllers/subnet/subnet_controller.go | 2 +- .../subnetset/subnetset_controller.go | 2 +- pkg/nsx/services/common/types.go | 24 +++++++------- pkg/nsx/services/vpc/builder.go | 14 +++----- pkg/nsx/services/vpc/compare.go | 2 +- pkg/nsx/services/vpc/vpc.go | 18 +++++------ .../testVPC/customize_networkconfig.yaml | 6 ++-- .../customize_networkconfig_updated.yaml | 6 ++-- .../testVPC/default_networkconfig.yaml | 6 ++-- .../testVPC/system_networkconfig.yaml | 6 ++-- test/e2e/nsx_networkinfo_test.go | 20 ++++++------ test/e2e/nsx_subnet_test.go | 8 ++--- 26 files changed, 148 insertions(+), 156 deletions(-) diff --git a/build/yaml/crd/nsx.vmware.com_networkinfos.yaml b/build/yaml/crd/nsx.vmware.com_networkinfos.yaml index c8aa22ab5..748c008b2 100644 --- a/build/yaml/crd/nsx.vmware.com_networkinfos.yaml +++ b/build/yaml/crd/nsx.vmware.com_networkinfos.yaml @@ -46,7 +46,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_vpcnetworkconfigurations.yaml b/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml index e2a7acdc7..eeef1994a 100644 --- a/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml +++ b/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml @@ -24,9 +24,9 @@ spec: 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: @@ -53,19 +53,11 @@ spec: When a field is not set in a Namespace's VPCNetworkConfiguration, the Namespace will use the value in the default VPCNetworkConfiguration. properties: - defaultIPv4SubnetSize: + defaultSubnetSize: default: 26 description: Default size of Subnet based upon estimated workload count. Defaults to 26. type: integer - defaultPodSubnetAccessMode: - description: DefaultPodSubnetAccessMode defines the access mode of - the default SubnetSet for PodVM. Must be Public or Private. - enum: - - Public - - Private - - Project - type: string lbServiceSize: enum: - SMALL @@ -76,16 +68,22 @@ spec: nsxtProject: description: NSX-T Project the Namespace associated with. type: string - privateIPv4CIDRs: - description: Private IPv4 CIDRs used to allocate Private Subnets. + podSubnetAccessMode: + description: PodSubnetAccessMode defines the access mode of the default + SubnetSet for PodVM. Must be Public or Private. + enum: + - Public + - Private + - Project + type: string + privateIPs: + description: Private IPs. 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. + context in logs. Less than equal to 8 characters. maxLength: 8 type: string vpcConnectivityProfile: 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 04cdb1727..b6e4583c9 100644 --- a/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml +++ b/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml @@ -5,11 +5,11 @@ metadata: spec: defaultGatewayPath: /infra/tier-0s/t0 edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/2d9df59f-6dc6-4911-8865-21fadc23d4da - defaultIPv4SubnetSize: 26 + defaultSubnetSize: 26 nsxtProject: proj-1 externalIPv4Blocks: - block1 - privateIPv4CIDRs: + privateIPs: - 172.26.0.0/16 - 172.36.0.0/16 - defaultPodSubnetAccessMode: Private + podSubnetAccessMode: Private 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/vpcnetworkconfiguration_types.go b/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go index e48336e0c..05f4dac80 100644 --- a/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go +++ b/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go @@ -24,32 +24,32 @@ const ( // in a Namespace's VPCNetworkConfiguration, the Namespace will use the value // in the default VPCNetworkConfiguration. type VPCNetworkConfigurationSpec struct { + // NSX-T Project the Namespace associated with. + NSXTProject string `json:"nsxtProject,omitempty"` + // VPCConnectivityProfile ID. This profile has configuration related to create VPC transit gateway attachment. VPCConnectivityProfile string `json:"vpcConnectivityProfile,omitempty"` + // Private IPs. + PrivateIPs []string `json:"privateIPs,omitempty"` + + // ShortID specifies Identifier to use when displaying VPC context in logs. + // Less than equal to 8 characters. + // +kubebuilder:validation:MaxLength=8 + // +optional + ShortID string `json:"shortID,omitempty"` + // +kubebuilder:validation:Enum=SMALL;MEDIUM;LARGE;XLARGE LbServiceSize string `json:"lbServiceSize,omitempty"` - // NSX-T Project the Namespace associated with. - NSXTProject string `json:"nsxtProject,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"` - // DefaultPodSubnetAccessMode defines the access mode of the default SubnetSet for PodVM. + 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 - DefaultPodSubnetAccessMode string `json:"defaultPodSubnetAccessMode,omitempty"` - // ShortID specifies Identifier to use when displaying VPC context in logs. - // Less than equal to 8 characters. - // +kubebuilder:validation:MaxLength=8 - // +optional - ShortID string `json:"shortID,omitempty"` + PodSubnetAccessMode string `json:"podSubnetAccessMode,omitempty"` } // VPCNetworkConfigurationStatus defines the observed state of VPCNetworkConfiguration @@ -76,7 +76,7 @@ type VPCInfo struct { // +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="PrivateIPs",type=string,JSONPath=`.spec.privateIPs`,description="PrivateIPs assigned to the Namespace" type VPCNetworkConfiguration struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` 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 3b3620558..12361c174 100644 --- a/pkg/apis/nsx.vmware.com/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/nsx.vmware.com/v1alpha1/zz_generated.deepcopy.go @@ -1430,8 +1430,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.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) } @@ -1470,8 +1470,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/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/vpcnetworkconfiguration_types.go b/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go index 714c6c70d..05f4dac80 100644 --- a/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go +++ b/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go @@ -24,32 +24,32 @@ const ( // in a Namespace's VPCNetworkConfiguration, the Namespace will use the value // in the default VPCNetworkConfiguration. type VPCNetworkConfigurationSpec struct { + // NSX-T Project the Namespace associated with. + NSXTProject string `json:"nsxtProject,omitempty"` + // VPCConnectivityProfile ID. This profile has configuration related to create VPC transit gateway attachment. VPCConnectivityProfile string `json:"vpcConnectivityProfile,omitempty"` + // Private IPs. + PrivateIPs []string `json:"privateIPs,omitempty"` + + // ShortID specifies Identifier to use when displaying VPC context in logs. + // Less than equal to 8 characters. + // +kubebuilder:validation:MaxLength=8 + // +optional + ShortID string `json:"shortID,omitempty"` + // +kubebuilder:validation:Enum=SMALL;MEDIUM;LARGE;XLARGE LbServiceSize string `json:"lbServiceSize,omitempty"` - // NSX-T Project the Namespace associated with. - NSXTProject string `json:"nsxtProject,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"` - // DefaultPodSubnetAccessMode defines the access mode of the default SubnetSet for PodVM. + 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 - DefaultPodSubnetAccessMode string `json:"defaultPodSubnetAccessMode,omitempty"` - // ShortID specifies Identifier to use when displaying VPC context in logs. - // Less than or equal to 8 characters. - // +kubebuilder:validation:MaxLength=8 - // +optional - ShortID string `json:"shortID,omitempty"` + PodSubnetAccessMode string `json:"podSubnetAccessMode,omitempty"` } // VPCNetworkConfigurationStatus defines the observed state of VPCNetworkConfiguration @@ -76,7 +76,7 @@ type VPCInfo struct { // +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="PrivateIPs",type=string,JSONPath=`.spec.privateIPs`,description="PrivateIPs assigned to the Namespace" type VPCNetworkConfiguration struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` diff --git a/pkg/apis/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/v1alpha1/zz_generated.deepcopy.go index 3b3620558..12361c174 100644 --- a/pkg/apis/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/v1alpha1/zz_generated.deepcopy.go @@ -1430,8 +1430,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.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) } @@ -1470,8 +1470,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/controllers/ippool/ippool_controller.go b/pkg/controllers/ippool/ippool_controller.go index 4c7450e62..632d0d3de 100644 --- a/pkg/controllers/ippool/ippool_controller.go +++ b/pkg/controllers/ippool/ippool_controller.go @@ -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.DefaultPodSubnetAccessMode + obj.Spec.Type = vpcNetworkConfig.PodSubnetAccessMode } if obj.ObjectMeta.DeletionTimestamp.IsZero() { 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 be5ad2136..e38826baa 100644 --- a/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go +++ b/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go @@ -106,16 +106,16 @@ func buildNetworkConfigInfo(vpcConfigCR v1alpha1.VPCNetworkConfiguration) (*comm } ninfo := &commontypes.VPCNetworkConfigInfo{ - IsDefault: isDefaultNetworkConfigCR(vpcConfigCR), - Org: org, - Name: vpcConfigCR.Name, - VPCConnectivityProfile: vpcConfigCR.Spec.VPCConnectivityProfile, - LbServiceSize: vpcConfigCR.Spec.LbServiceSize, - NsxtProject: project, - PrivateIPv4CIDRs: vpcConfigCR.Spec.PrivateIPv4CIDRs, - DefaultIPv4SubnetSize: vpcConfigCR.Spec.DefaultIPv4SubnetSize, - DefaultPodSubnetAccessMode: vpcConfigCR.Spec.DefaultPodSubnetAccessMode, - ShortID: vpcConfigCR.Spec.ShortID, + IsDefault: isDefaultNetworkConfigCR(vpcConfigCR), + Org: org, + Name: vpcConfigCR.Name, + VPCConnectivityProfile: vpcConfigCR.Spec.VPCConnectivityProfile, + LbServiceSize: vpcConfigCR.Spec.LbServiceSize, + NsxtProject: project, + PrivateIPs: vpcConfigCR.Spec.PrivateIPs, + DefaultSubnetSize: vpcConfigCR.Spec.DefaultSubnetSize, + PodSubnetAccessMode: vpcConfigCR.Spec.PodSubnetAccessMode, + ShortID: vpcConfigCR.Spec.ShortID, } return ninfo, nil } diff --git a/pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go b/pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go index ace8ec528..f98a8ae4f 100644 --- a/pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go +++ b/pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go @@ -76,21 +76,21 @@ func TestBuildNetworkConfigInfo(t *testing.T) { // 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, + PrivateIPs: []string{"private-ipb-1", "private-ipb-2"}, + DefaultSubnetSize: 64, // VPCServiceProfile: "test-VpcServiceProfile", - VPCConnectivityProfile: "test-VPCConnectivityProfile", - DefaultPodSubnetAccessMode: "Public", - NSXTProject: "/orgs/default/projects/nsx_operator_e2e_test", + VPCConnectivityProfile: "test-VPCConnectivityProfile", + PodSubnetAccessMode: "Public", + NSXTProject: "/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, - DefaultPodSubnetAccessMode: "Private", - NSXTProject: "/orgs/anotherOrg/projects/anotherProject", + PrivateIPs: []string{"private-ipb-1", "private-ipb-2"}, + DefaultSubnetSize: 32, + PodSubnetAccessMode: "Private", + NSXTProject: "/orgs/anotherOrg/projects/anotherProject", } testCRD1 := v1alpha1.VPCNetworkConfiguration{ Spec: spec1, @@ -135,8 +135,8 @@ func TestBuildNetworkConfigInfo(t *testing.T) { // 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.DefaultPodSubnetAccessMode) + 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 244596904..4a8a098c7 100644 --- a/pkg/controllers/subnet/subnet_controller.go +++ b/pkg/controllers/subnet/subnet_controller.go @@ -87,7 +87,7 @@ func (r *SubnetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr 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 027cc39a6..d9fcb27e8 100644 --- a/pkg/controllers/subnetset/subnetset_controller.go +++ b/pkg/controllers/subnetset/subnetset_controller.go @@ -78,7 +78,7 @@ func (r *SubnetSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( 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 1676b257a..68fbeaf4c 100644 --- a/pkg/nsx/services/common/types.go +++ b/pkg/nsx/services/common/types.go @@ -195,17 +195,15 @@ type VPCResourceInfo struct { } type VPCNetworkConfigInfo struct { - IsDefault bool - Org string - Name string - DefaultGatewayPath string - VPCConnectivityProfile string - LbServiceSize string - EdgeClusterPath string - NsxtProject string - ExternalIPv4Blocks []string - PrivateIPv4CIDRs []string - DefaultIPv4SubnetSize int - DefaultPodSubnetAccessMode string - ShortID string + IsDefault bool + Org string + Name string + VPCConnectivityProfile string + LbServiceSize string + NsxtProject 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 2623f5213..592d7ac8e 100644 --- a/pkg/nsx/services/vpc/builder.go +++ b/pkg/nsx/services/vpc/builder.go @@ -50,7 +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, 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,20 +67,16 @@ func buildNSXVPC(obj *v1alpha1.NetworkInfo, nsObj *v1.Namespace, nc common.VPCNe vpc.Id = common.String(string(nsObj.GetUID())) 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) } vpc.VpcConnectivityProfile = &nc.VPCConnectivityProfile - // // update private/public blocks - // vpc.PrivateIpv4Blocks = util.GetMapValues(pathMap) + // set PrivateIps here will fai, with error:"Error occurred while allocating IPs for VPC Subnet." + // vpc.PrivateIps = nc.PrivateIPs + // update private/public blocks + 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 971d4b326..c41a7869c 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 @@ -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) @@ -540,11 +540,11 @@ func (s *VPCService) CreateOrUpdateVPC(obj *v1alpha1.NetworkInfo) (*model.Vpc, * log.Info("read network config from store", "NetworkConfig", ncName) - // paths, err := s.CreateOrUpdatePrivateIPBlock(obj, nsObj, nc) - // if err != nil { - // log.Error(err, "failed to process private ip blocks, push event back to queue") - // return nil, nil, err - // } + paths, err := s.CreateOrUpdatePrivateIPBlock(obj, nsObj, nc) + if err != nil { + log.Error(err, "failed to process private ip blocks, push event back to queue") + return nil, nil, err + } // if all private ip blocks are created, then create nsx vpc resource. nsxVPC := &model.Vpc{} @@ -556,7 +556,7 @@ func (s *VPCService) CreateOrUpdateVPC(obj *v1alpha1.NetworkInfo) (*model.Vpc, * nsxVPC = nil } - createdVpc, err := buildNSXVPC(obj, nsObj, nc, s.NSXConfig.Cluster, nsxVPC) + createdVpc, err := buildNSXVPC(obj, nsObj, nc, s.NSXConfig.Cluster, paths, nsxVPC) if err != nil { log.Error(err, "failed to build NSX VPC object") return nil, nil, err diff --git a/test/e2e/manifest/testVPC/customize_networkconfig.yaml b/test/e2e/manifest/testVPC/customize_networkconfig.yaml index f695222b2..c8f291954 100644 --- a/test/e2e/manifest/testVPC/customize_networkconfig.yaml +++ b/test/e2e/manifest/testVPC/customize_networkconfig.yaml @@ -5,11 +5,11 @@ kind: VPCNetworkConfiguration metadata: name: selfdefinedconfig spec: - defaultIPv4SubnetSize: 26 + defaultSubnetSize: 26 nsxtProject: /orgs/default/projects/nsx_operator_e2e_test - privateIPv4CIDRs: + privateIPs: - 172.29.0.0/16 - 172.39.0.0/16 - defaultPodSubnetAccessMode: Public + podSubnetAccessMode: Public vpcConnectivityProfile: "" \ 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 70ed85935..625c5a909 100644 --- a/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml +++ b/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml @@ -5,12 +5,12 @@ kind: VPCNetworkConfiguration metadata: name: selfdefinedconfig spec: - defaultIPv4SubnetSize: 26 + defaultSubnetSize: 26 nsxtProject: /orgs/default/projects/nsx_operator_e2e_test - privateIPv4CIDRs: + privateIPs: - 172.29.0.0/16 - 172.39.0.0/16 - 172.49.0.0/16 - defaultPodSubnetAccessMode: Public + podSubnetAccessMode: Public vpcConnectivityProfile: "" \ 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 9c030c958..1d470daea 100644 --- a/test/e2e/manifest/testVPC/default_networkconfig.yaml +++ b/test/e2e/manifest/testVPC/default_networkconfig.yaml @@ -9,10 +9,10 @@ metadata: annotations: nsx.vmware.com/default: "true" spec: - defaultIPv4SubnetSize: 26 + defaultSubnetSize: 26 nsxtProject: /orgs/default/projects/nsx_operator_e2e_test - privateIPv4CIDRs: + privateIPs: - 172.28.0.0/16 - 172.38.0.0/16 - defaultPodSubnetAccessMode: Public + podSubnetAccessMode: Public vpcConnectivityProfile: "" diff --git a/test/e2e/manifest/testVPC/system_networkconfig.yaml b/test/e2e/manifest/testVPC/system_networkconfig.yaml index 6ea2c0a58..c04afc176 100644 --- a/test/e2e/manifest/testVPC/system_networkconfig.yaml +++ b/test/e2e/manifest/testVPC/system_networkconfig.yaml @@ -6,11 +6,11 @@ kind: VPCNetworkConfiguration metadata: name: system spec: - defaultIPv4SubnetSize: 26 + defaultSubnetSize: 26 nsxtProject: /orgs/default/projects/nsx_operator_e2e_test - privateIPv4CIDRs: + privateIPs: - 172.27.0.0/16 - 172.37.0.0/16 - defaultPodSubnetAccessMode: Public + podSubnetAccessMode: Public vpcConnectivityProfile: "" \ 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 4ac51c6c2..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.DefaultPodSubnetAccessMode { - log.Printf("AccessMode is %s, while it's expected to be %s", subnetSetCR.Spec.AccessMode, vpcNetworkConfig.Spec.DefaultPodSubnetAccessMode) + 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