Skip to content

Commit

Permalink
Truncate VPC display name if it exceeds 80 chars
Browse files Browse the repository at this point in the history
VPC display name needs to be <=80 when VPC in VC is enabled.

Tests:
For a NetworkInfo obj with Name: "test-ns-03a2def3-0087-4077-904e-23e4dd788fb7"
and UID: "ecc6eb9f-92b5-4893-b809-e3ebc1fcf59e",
test that the VPC name created is truncated to ""test-ns-03a2def3-0087-4077-904e-23e4dd788fb7_f4f0080e".
  • Loading branch information
lxiaopei committed Dec 12, 2024
1 parent e6a2c72 commit 2b7b4b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/nsx/services/vpc/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func buildNSXVPC(obj *v1alpha1.NetworkInfo, nsObj *v1.Namespace, nc common.VPCNe
*vpc = *nsxVPC
} else {
// for creating vpc case, fill in vpc properties based on networkconfig
vpcName := util.GenerateIDByObjectByLimit(obj, common.MaxNameLength)
vpcName := util.GenerateIDByObjectByLimit(obj, common.MaxSubnetNameLength)
vpc.DisplayName = &vpcName
vpc.Id = common.String(util.GenerateIDByObject(obj))
vpc.IpAddressType = &DefaultVPCIPAddressType
Expand Down
27 changes: 27 additions & 0 deletions pkg/nsx/services/vpc/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func TestBuildNSXVPC(t *testing.T) {
existingVPC *model.Vpc
ncPrivateIps []string
useAVILB bool
netInfoObj *v1alpha1.NetworkInfo
expVPC *model.Vpc
lbProviderChanged bool
}{
Expand Down Expand Up @@ -159,6 +160,29 @@ func TestBuildNSXVPC(t *testing.T) {
},
},
},
{
name: "create new VPC with 81 chars networkinfo name",
ncPrivateIps: []string{"192.168.3.0/24"},
useAVILB: false,
lbProviderChanged: false,
netInfoObj: &v1alpha1.NetworkInfo{
ObjectMeta: metav1.ObjectMeta{Namespace: "ns1", Name: "test-ns-03a2def3-0087-4077-904e-23e4dd788fb7", UID: "ecc6eb9f-92b5-4893-b809-e3ebc1fcf59e"},
VPCs: nil,
},
expVPC: &model.Vpc{
Id: common.String("test-ns-03a2def3-0087-4077-904e-23e4dd788fb7_ecc6eb9f-92b5-4893-b809-e3ebc1fcf59e"),
DisplayName: common.String("test-ns-03a2def3-0087-4077-904e-23e4dd788fb7_f4f0080e"),
PrivateIps: []string{"192.168.3.0/24"},
IpAddressType: common.String("IPV4"),
Tags: []model.Tag{
{Scope: common.String("nsx-op/cluster"), Tag: common.String("cluster1")},
{Scope: common.String("nsx-op/version"), Tag: common.String("1.0.0")},
{Scope: common.String("nsx-op/namespace"), Tag: common.String("ns1")},
{Scope: common.String("nsx-op/namespace_uid"), Tag: common.String("nsuid1")},
{Scope: common.String("nsx/managed-by"), Tag: common.String("nsx-op")},
},
},
},
{
name: "update VPC with AVI load balancer disabled -> enabled",
ncPrivateIps: []string{"192.168.3.0/24"},
Expand Down Expand Up @@ -199,6 +223,9 @@ func TestBuildNSXVPC(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
nc.PrivateIPs = tc.ncPrivateIps
if tc.netInfoObj != nil {
netInfoObj = tc.netInfoObj
}
got, err := buildNSXVPC(netInfoObj, nsObj, nc, clusterStr, tc.existingVPC, tc.useAVILB, tc.lbProviderChanged)
assert.Nil(t, err)
assert.Equal(t, tc.expVPC, got)
Expand Down

0 comments on commit 2b7b4b4

Please sign in to comment.