From 1dc015ac65e1df33897ad480cef9607670ef1012 Mon Sep 17 00:00:00 2001 From: Wenqi Qiu Date: Thu, 4 Jul 2024 22:18:53 +0800 Subject: [PATCH] rename VPCNetworkConfiguration CR field name Signed-off-by: Wenqi Qiu --- .../nsx.vmware.com_vpcnetworkconfigurations.yaml | 10 +++++----- .../nsx_v1alpha1_vpcnetworkconfigurations.yaml | 2 +- .../v1alpha1/vpcnetworkconfiguration_types.go | 9 ++++----- .../v1alpha1/vpcnetworkconfiguration_types.go | 9 ++++----- .../networkinfo/vpcnetworkconfig_handler.go | 10 +++++----- .../networkinfo/vpcnetworkconfig_handler_test.go | 12 ++++++------ pkg/nsx/services/common/types.go | 4 ++-- pkg/nsx/services/vpc/builder.go | 2 +- pkg/nsx/services/vpc/vpc.go | 16 ++++++++-------- .../testVPC/customize_networkconfig.yaml | 2 +- .../testVPC/customize_networkconfig_updated.yaml | 2 +- .../manifest/testVPC/default_networkconfig.yaml | 2 +- .../manifest/testVPC/system_networkconfig.yaml | 2 +- 13 files changed, 40 insertions(+), 42 deletions(-) diff --git a/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml b/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml index eeef1994a..65ebdd302 100644 --- a/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml +++ b/build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml @@ -16,9 +16,9 @@ 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 @@ -65,7 +65,7 @@ spec: - LARGE - XLARGE type: string - nsxtProject: + nsxProject: description: NSX-T Project the Namespace associated with. type: string podSubnetAccessMode: @@ -87,7 +87,7 @@ spec: maxLength: 8 type: string vpcConnectivityProfile: - description: VPCConnectivityProfile ID. This profile has configuration + description: VpcConnectivityProfile ID. This profile has configuration related to create VPC transit gateway attachment. type: string type: object diff --git a/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml b/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml index 3c3bc68cf..233853e45 100644 --- a/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml +++ b/build/yaml/samples/nsx_v1alpha1_vpcnetworkconfigurations.yaml @@ -6,7 +6,7 @@ spec: defaultGatewayPath: /infra/tier-0s/t0 edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/2d9df59f-6dc6-4911-8865-21fadc23d4da defaultSubnetSize: 26 - nsxtProject: proj-1 + nsxProject: proj-1 externalIPv4Blocks: - block1 privateIPs: diff --git a/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go b/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go index 05f4dac80..1b21bf192 100644 --- a/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go +++ b/pkg/apis/nsx.vmware.com/v1alpha1/vpcnetworkconfiguration_types.go @@ -25,10 +25,10 @@ const ( // in the default VPCNetworkConfiguration. type VPCNetworkConfigurationSpec struct { // NSX-T Project the Namespace associated with. - NSXTProject string `json:"nsxtProject,omitempty"` + NsxProject string `json:"nsxProject,omitempty"` - // VPCConnectivityProfile ID. This profile has configuration related to create VPC transit gateway attachment. - VPCConnectivityProfile string `json:"vpcConnectivityProfile,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"` @@ -74,8 +74,7 @@ type VPCInfo struct { // 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="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"` diff --git a/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go b/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go index 05f4dac80..1b21bf192 100644 --- a/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go +++ b/pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go @@ -25,10 +25,10 @@ const ( // in the default VPCNetworkConfiguration. type VPCNetworkConfigurationSpec struct { // NSX-T Project the Namespace associated with. - NSXTProject string `json:"nsxtProject,omitempty"` + NsxProject string `json:"nsxProject,omitempty"` - // VPCConnectivityProfile ID. This profile has configuration related to create VPC transit gateway attachment. - VPCConnectivityProfile string `json:"vpcConnectivityProfile,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"` @@ -74,8 +74,7 @@ type VPCInfo struct { // 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="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"` diff --git a/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go b/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go index e38826baa..1a6f70dc4 100644 --- a/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go +++ b/pkg/controllers/networkinfo/vpcnetworkconfig_handler.go @@ -99,9 +99,9 @@ var VPCNetworkConfigurationPredicate = predicate.Funcs{ } 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 } @@ -109,9 +109,9 @@ func buildNetworkConfigInfo(vpcConfigCR v1alpha1.VPCNetworkConfiguration) (*comm IsDefault: isDefaultNetworkConfigCR(vpcConfigCR), Org: org, Name: vpcConfigCR.Name, - VPCConnectivityProfile: vpcConfigCR.Spec.VPCConnectivityProfile, + VpcConnectivityProfile: vpcConfigCR.Spec.VpcConnectivityProfile, LbServiceSize: vpcConfigCR.Spec.LbServiceSize, - NsxtProject: project, + NsxProject: project, PrivateIPs: vpcConfigCR.Spec.PrivateIPs, DefaultSubnetSize: vpcConfigCR.Spec.DefaultSubnetSize, PodSubnetAccessMode: vpcConfigCR.Spec.PodSubnetAccessMode, @@ -134,7 +134,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 f98a8ae4f..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) @@ -79,9 +79,9 @@ func TestBuildNetworkConfigInfo(t *testing.T) { PrivateIPs: []string{"private-ipb-1", "private-ipb-2"}, DefaultSubnetSize: 64, // VPCServiceProfile: "test-VpcServiceProfile", - VPCConnectivityProfile: "test-VPCConnectivityProfile", + VpcConnectivityProfile: "test-VpcConnectivityProfile", PodSubnetAccessMode: "Public", - NSXTProject: "/orgs/default/projects/nsx_operator_e2e_test", + NsxProject: "/orgs/default/projects/nsx_operator_e2e_test", } spec2 := v1alpha1.VPCNetworkConfigurationSpec{ // DefaultGatewayPath: "test-gw-path-2", @@ -90,7 +90,7 @@ func TestBuildNetworkConfigInfo(t *testing.T) { PrivateIPs: []string{"private-ipb-1", "private-ipb-2"}, DefaultSubnetSize: 32, PodSubnetAccessMode: "Private", - NSXTProject: "/orgs/anotherOrg/projects/anotherProject", + NsxProject: "/orgs/anotherOrg/projects/anotherProject", } testCRD1 := v1alpha1.VPCNetworkConfiguration{ Spec: spec1, @@ -124,7 +124,7 @@ func TestBuildNetworkConfigInfo(t *testing.T) { vpcConnectivityProfile string }{ {"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-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 { @@ -134,7 +134,7 @@ func TestBuildNetworkConfigInfo(t *testing.T) { // 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.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/nsx/services/common/types.go b/pkg/nsx/services/common/types.go index 68fbeaf4c..5f9e54431 100644 --- a/pkg/nsx/services/common/types.go +++ b/pkg/nsx/services/common/types.go @@ -198,9 +198,9 @@ type VPCNetworkConfigInfo struct { IsDefault bool Org string Name string - VPCConnectivityProfile string + VpcConnectivityProfile string LbServiceSize string - NsxtProject string + NsxProject string ExternalIPv4Blocks []string PrivateIPs []string DefaultSubnetSize int diff --git a/pkg/nsx/services/vpc/builder.go b/pkg/nsx/services/vpc/builder.go index 592d7ac8e..ae26d40ba 100644 --- a/pkg/nsx/services/vpc/builder.go +++ b/pkg/nsx/services/vpc/builder.go @@ -71,7 +71,7 @@ func buildNSXVPC(obj *v1alpha1.NetworkInfo, nsObj *v1.Namespace, nc common.VPCNe vpc.Tags = util.BuildBasicTags(cluster, obj, nsObj.UID) } - vpc.VpcConnectivityProfile = &nc.VPCConnectivityProfile + vpc.VpcConnectivityProfile = &nc.VpcConnectivityProfile // set PrivateIps here will fai, with error:"Error occurred while allocating IPs for VPC Subnet." // vpc.PrivateIps = nc.PrivateIPs diff --git a/pkg/nsx/services/vpc/vpc.go b/pkg/nsx/services/vpc/vpc.go index c41a7869c..6ecc07ced 100644 --- a/pkg/nsx/services/vpc/vpc.go +++ b/pkg/nsx/services/vpc/vpc.go @@ -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 16568117c..76c3dc146 100644 --- a/test/e2e/manifest/testVPC/customize_networkconfig.yaml +++ b/test/e2e/manifest/testVPC/customize_networkconfig.yaml @@ -6,7 +6,7 @@ metadata: name: selfdefinedconfig spec: defaultSubnetSize: 26 - nsxtProject: /orgs/default/projects/nsx_operator_e2e_test + nsxProject: /orgs/default/projects/nsx_operator_e2e_test privateIPs: - 172.29.0.0/16 - 172.39.0.0/16 diff --git a/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml b/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml index a2886d116..8dc565b95 100644 --- a/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml +++ b/test/e2e/manifest/testVPC/customize_networkconfig_updated.yaml @@ -6,7 +6,7 @@ metadata: name: selfdefinedconfig spec: defaultSubnetSize: 26 - nsxtProject: /orgs/default/projects/nsx_operator_e2e_test + nsxProject: /orgs/default/projects/nsx_operator_e2e_test privateIPs: - 172.29.0.0/16 - 172.39.0.0/16 diff --git a/test/e2e/manifest/testVPC/default_networkconfig.yaml b/test/e2e/manifest/testVPC/default_networkconfig.yaml index f2840f2dc..0f1fdf7d0 100644 --- a/test/e2e/manifest/testVPC/default_networkconfig.yaml +++ b/test/e2e/manifest/testVPC/default_networkconfig.yaml @@ -10,7 +10,7 @@ metadata: nsx.vmware.com/default: "true" spec: defaultSubnetSize: 26 - nsxtProject: /orgs/default/projects/nsx_operator_e2e_test + nsxProject: /orgs/default/projects/nsx_operator_e2e_test privateIPs: - 172.28.0.0/16 - 172.38.0.0/16 diff --git a/test/e2e/manifest/testVPC/system_networkconfig.yaml b/test/e2e/manifest/testVPC/system_networkconfig.yaml index 5bac77fb5..3768a0064 100644 --- a/test/e2e/manifest/testVPC/system_networkconfig.yaml +++ b/test/e2e/manifest/testVPC/system_networkconfig.yaml @@ -7,7 +7,7 @@ metadata: name: system spec: defaultSubnetSize: 26 - nsxtProject: /orgs/default/projects/nsx_operator_e2e_test + nsxProject: /orgs/default/projects/nsx_operator_e2e_test privateIPs: - 172.27.0.0/16 - 172.37.0.0/16