Skip to content

Commit

Permalink
Fix AccessMode name in NSX request body (#693)
Browse files Browse the repository at this point in the history
Rename AccessMode `PrivateTGW` to `Private_TGW` in the NSX request body and fix the subnet e2e test

Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq authored Aug 16, 2024
1 parent ca8ea47 commit 8081971
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 14 deletions.
6 changes: 6 additions & 0 deletions pkg/apis/vpc/v1alpha1/subnet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (

type AccessMode string

const (
AccessModePublic string = "Public"
AccessModePrivate string = "Private"
AccessModeProject string = "PrivateTGW"
)

// SubnetSpec defines the desired state of Subnet.
type SubnetSpec struct {
// Size of Subnet based upon estimated workload count.
Expand Down
6 changes: 0 additions & 6 deletions pkg/apis/vpc/v1alpha1/vpcnetworkconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
AccessModePublic string = "Public"
AccessModePrivate string = "Private"
AccessModeProject string = "PrivateTGW"
)

// VPCNetworkConfigurationSpec defines the desired state of VPCNetworkConfiguration.
// There is a default VPCNetworkConfiguration that applies to Namespaces
// do not have a VPCNetworkConfiguration assigned. When a field is not set
Expand Down
13 changes: 11 additions & 2 deletions pkg/nsx/services/subnet/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/vmware-tanzu/nsx-operator/pkg/util"
)

const AccessModeProjectInNSX string = "Private_TGW"

var (
String = common.String
Int64 = common.Int64
Expand Down Expand Up @@ -44,6 +46,13 @@ func (service *SubnetService) buildSubnetSetName(subnetset *v1alpha1.SubnetSet,
return util.GenerateTruncName(common.MaxSubnetNameLength, resName, "", index, "", "")
}

func convertAccessMode(accessMode string) string {
if accessMode == v1alpha1.AccessModeProject {
return AccessModeProjectInNSX
}
return accessMode
}

func (service *SubnetService) buildSubnet(obj client.Object, tags []model.Tag) (*model.VpcSubnet, error) {
tags = append(service.buildBasicTags(obj), tags...)
var nsxSubnet *model.VpcSubnet
Expand All @@ -52,7 +61,7 @@ func (service *SubnetService) buildSubnet(obj client.Object, tags []model.Tag) (
case *v1alpha1.Subnet:
nsxSubnet = &model.VpcSubnet{
Id: String(service.BuildSubnetID(o)),
AccessMode: String(util.Capitalize(string(o.Spec.AccessMode))),
AccessMode: String(convertAccessMode(util.Capitalize(string(o.Spec.AccessMode)))),
Ipv4SubnetSize: Int64(int64(o.Spec.IPv4SubnetSize)),
DhcpConfig: service.buildDHCPConfig(o.Spec.DHCPConfig.EnableDHCP, int64(o.Spec.IPv4SubnetSize-4)),
DisplayName: String(service.buildSubnetName(o)),
Expand All @@ -65,7 +74,7 @@ func (service *SubnetService) buildSubnet(obj client.Object, tags []model.Tag) (
index := util.GetRandomIndexString()
nsxSubnet = &model.VpcSubnet{
Id: String(service.buildSubnetSetID(o, index)),
AccessMode: String(util.Capitalize(string(o.Spec.AccessMode))),
AccessMode: String(convertAccessMode(util.Capitalize(string(o.Spec.AccessMode)))),
Ipv4SubnetSize: Int64(int64(o.Spec.IPv4SubnetSize)),
DhcpConfig: service.buildDHCPConfig(o.Spec.DHCPConfig.EnableDHCP, int64(o.Spec.IPv4SubnetSize-4)),
DisplayName: String(service.buildSubnetSetName(o, index)),
Expand Down
2 changes: 2 additions & 0 deletions pkg/nsx/services/subnetport/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func keyFunc(obj interface{}) (string, error) {
return *v.Id, nil
case types.UID:
return string(v), nil
case string:
return v, nil
default:
return "", errors.New("keyFunc doesn't support unknown type")
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/manifest/testSubnet/subnetport_1.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: crd.nsx.vmware.com/v1alpha1
kind: SubnetPort
metadata:
name: port-1
name: port-e2e-test-1
namespace: subnet-e2e
spec:
subnetSet: pod-default
2 changes: 1 addition & 1 deletion test/e2e/manifest/testSubnet/subnetport_3.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: crd.nsx.vmware.com/v1alpha1
kind: SubnetPort
metadata:
name: port-3
name: port-e2e-test-3
namespace: subnet-e2e-shared
spec:
1 change: 1 addition & 0 deletions test/e2e/manifest/testSubnet/subnetset-dhcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ metadata:
name: user-pod-subnetset-dhcp
namespace: subnet-e2e
spec:
accessMode: PrivateTGW
DHCPConfig:
enableDHCP: true
1 change: 1 addition & 0 deletions test/e2e/manifest/testSubnet/subnetset-static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: user-pod-subnetset-static
namespace: subnet-e2e
spec:
accessMode: Private
advancedConfig:
staticIPAllocation:
enable: true
7 changes: 3 additions & 4 deletions test/e2e/nsx_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func TestSubnetSet(t *testing.T) {
teardownTest(t, E2ENamespaceTarget, SubnetDeletionTimeout)
})

t.Skip("Skip test")
t.Run("case=DefaultSubnetSet", defaultSubnetSet)
t.Run("case=UserSubnetSet", UserSubnetSet)
t.Run("case=SharedSubnetSet", sharedSubnetSet)
Expand All @@ -90,7 +89,7 @@ func defaultSubnetSet(t *testing.T) {
portPath, _ := filepath.Abs("./manifest/testSubnet/subnetport_1.yaml")
err = applyYAML(portPath, E2ENamespace)
assertNil(t, err)
err = testData.waitForCRReadyOrDeleted(defaultTimeout, SubnetPortCRType, E2ENamespace, "port-1", Ready)
err = testData.waitForCRReadyOrDeleted(defaultTimeout, SubnetPortCRType, E2ENamespace, "port-e2e-test-1", Ready)
assertNil(t, err)
defer deleteYAML(portPath, E2ENamespace)

Expand Down Expand Up @@ -233,7 +232,7 @@ func sharedSubnetSet(t *testing.T) {
portPath, _ := filepath.Abs("./manifest/testSubnet/subnetport_3.yaml")
err = applyYAML(portPath, E2ENamespaceShared)
assertNil(t, err)
err = testData.waitForCRReadyOrDeleted(defaultTimeout, SubnetPortCRType, E2ENamespaceShared, "port-3", Ready)
err = testData.waitForCRReadyOrDeleted(defaultTimeout, SubnetPortCRType, E2ENamespaceShared, "port-e2e-test-3", Ready)
assertNil(t, err)
defer deleteYAML(portPath, E2ENamespaceShared)

Expand All @@ -243,7 +242,7 @@ func sharedSubnetSet(t *testing.T) {
assert.NotEmpty(t, subnetSet.Status.Subnets, "No Subnet info in SubnetSet")

// 4. Check IP address is allocated to SubnetPort.
port, err := testData.crdClientset.CrdV1alpha1().SubnetPorts(E2ENamespaceShared).Get(context.TODO(), "port-3", v1.GetOptions{})
port, err := testData.crdClientset.CrdV1alpha1().SubnetPorts(E2ENamespaceShared).Get(context.TODO(), "port-e2e-test-3", v1.GetOptions{})
assertNil(t, err)
assert.NotEmpty(t, port.Status.NetworkInterfaceConfig.IPAddresses[0].IPAddress, "No IP address in SubnetPort")

Expand Down

0 comments on commit 8081971

Please sign in to comment.