Skip to content

Commit

Permalink
rename VPCNetworkConfiguration CR field name
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <wenqiq@vmware.com>
  • Loading branch information
wenqiq committed Jul 4, 2024
1 parent eb66a4b commit 1dc015a
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 42 deletions.
10 changes: 5 additions & 5 deletions build/yaml/crd/nsx.vmware.com_vpcnetworkconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,7 +65,7 @@ spec:
- LARGE
- XLARGE
type: string
nsxtProject:
nsxProject:
description: NSX-T Project the Namespace associated with.
type: string
podSubnetAccessMode:
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
9 changes: 4 additions & 5 deletions pkg/apis/v1alpha1/vpcnetworkconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
10 changes: 5 additions & 5 deletions pkg/controllers/networkinfo/vpcnetworkconfig_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ 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
}

ninfo := &commontypes.VPCNetworkConfigInfo{
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,
Expand All @@ -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, "/")
Expand Down
12 changes: 6 additions & 6 deletions pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/nsx/services/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/nsx/services/vpc/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions pkg/nsx/services/vpc/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/manifest/testVPC/customize_networkconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/manifest/testVPC/default_networkconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/manifest/testVPC/system_networkconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1dc015a

Please sign in to comment.