Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Not4review]fix e2e #657

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controllers/networkinfo/networkinfo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (r *NetworkInfoReconciler) Reconcile(ctx context.Context, req ctrl.Request)
snatIP, path, cidr := "", "", ""
// currently, auto snat is not exposed, and use default value True
// checking autosnat to support future extension in vpc configuration
if *createdVpc.ServiceGateway.AutoSnat {
if createdVpc.ServiceGateway != nil && createdVpc.ServiceGateway.AutoSnat != nil && *createdVpc.ServiceGateway.AutoSnat {
snatIP, err = r.Service.GetDefaultSNATIP(*createdVpc)
if err != nil {
log.Error(err, "failed to read default SNAT ip from VPC", "VPC", createdVpc.Id)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/networkinfo/vpcnetworkconfig_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func isDefaultNetworkConfigCR(vpcConfigCR v1alpha1.VPCNetworkConfiguration) bool
}

// parse org id and project id from nsxtProject path
// example /orgs/default/projects/nsx_operator_e2e_test
// example /orgs/default/projects/nsx_operator_test
func nsxtProjectPathToId(path string) (string, string, error) {
parts := strings.Split(path, "/")
if len(parts) < 4 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/networkinfo/vpcnetworkconfig_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestNsxtProjectPathToId(t *testing.T) {
project string
err interface{}
}{
{"1", "/orgs/default/projects/nsx_operator_e2e_test", "default", "nsx_operator_e2e_test", nil},
{"1", "/orgs/default/projects/nsx_operator_test", "default", "nsx_operator_test", nil},
{"2", "", "", "", "dummy"},
}
for _, tt := range tests {
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestBuildNetworkConfigInfo(t *testing.T) {
PrivateIPv4CIDRs: []string{"private-ipb-1", "private-ipb-2"},
DefaultIPv4SubnetSize: 64,
DefaultSubnetAccessMode: "Public",
NSXTProject: "/orgs/default/projects/nsx_operator_e2e_test",
NSXTProject: "/orgs/default/projects/nsx_operator_test",
}
spec2 := v1alpha1.VPCNetworkConfigurationSpec{
DefaultGatewayPath: "test-gw-path-2",
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestBuildNetworkConfigInfo(t *testing.T) {
accessMode string
isDefault bool
}{
{"1", testCRD1, "test-gw-path-1", "test-edge-path-1", "default", "nsx_operator_e2e_test", 64, "Public", false},
{"1", testCRD1, "test-gw-path-1", "test-edge-path-1", "default", "nsx_operator_test", 64, "Public", false},
{"2", testCRD2, "test-gw-path-2", "test-edge-path-2", "anotherOrg", "anotherProject", 32, "Private", false},
{"3", testCRD3, "test-gw-path-2", "test-edge-path-2", "anotherOrg", "anotherProject", 32, "Private", true},
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/nsx/services/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ func (service *SubnetService) GetSubnetStatus(subnet *model.VpcSubnet) ([]model.
log.Error(err, "no subnet status found")
return nil, err
}
if statusList.Results[0].NetworkAddress == nil || statusList.Results[0].GatewayAddress == nil {
err := fmt.Errorf("invalid status result: %+v", statusList.Results[0])
log.Error(err, "subnet status does not have network address or gateway address", "subnet.Id", subnet.Id)
return nil, err
}
return statusList.Results, nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/nsx/services/subnetport/subnetport.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package subnetport
import (
"context"
"errors"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -248,6 +249,11 @@ func (service *SubnetPortService) GetGatewayPrefixForSubnetPort(obj *v1alpha1.Su
return "", -1, err
}
status := statusList.Results[0]
if status.GatewayAddress == nil {
err := fmt.Errorf("invalid status result: %+v", status)
log.Error(err, "subnet status does not have gateway address", "nsxSubnetPath", nsxSubnetPath)
return "", -1, err
}
gateway, err := util.RemoveIPPrefix(*status.GatewayAddress)
if err != nil {
return "", -1, err
Expand Down
10 changes: 8 additions & 2 deletions pkg/nsx/services/vpc/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ func InitializeVPC(service common.Service) (*VPCService, error) {
VPCService.VPCNSNetworkConfigStore = VPCNsNetworkConfigStore{
VPCNSNetworkConfigMap: make(map[string]string),
}
//initialize vpc store, lbs store and ip blocks store
// initialize vpc store, lbs store and ip blocks store
go VPCService.InitializeResourceStore(&wg, fatalErrors, common.ResourceTypeVpc, nil, VPCService.VpcStore)
wg.Add(1)
go VPCService.InitializeResourceStore(&wg, fatalErrors, common.ResourceTypeLBService, nil, VPCService.LbsStore)
go VPCService.InitializeResourceStore(&wg, fatalErrors, common.ResourceTypeIPBlock, nil, VPCService.IpblockStore)

//initalize avi rule related store
// initialize avi rule related store
if enableAviAllowRule {
VPCService.RuleStore = &AviRuleStore{ResourceStore: common.ResourceStore{
Indexer: cache.NewIndexer(keyFuncAVI, nil),
Expand Down Expand Up @@ -499,6 +499,12 @@ func (s *VPCService) GetAVISubnetInfo(vpc model.Vpc) (string, string, error) {
return "", "", err
}

if statusList.Results[0].NetworkAddress == nil {
err := fmt.Errorf("invalid status result: %+v", statusList.Results[0])
log.Error(err, "subnet status does not have network address", "Subnet", common.AVISubnetLBID)
return "", "", err
}

cidr := *statusList.Results[0].NetworkAddress
log.Info("read AVI subnet properties", "Path", path, "CIDR", cidr)
return path, cidr, nil
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 @@ -9,7 +9,7 @@ spec:
# nsx-operator-ci would replace '{edge-cluster-id}' with real edge-cluster-id of testbed
edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/{edge-cluster-id}
defaultIPv4SubnetSize: 26
nsxtProject: /orgs/default/projects/nsx_operator_e2e_test
nsxtProject: /orgs/default/projects/nsx_operator_e2e_test_2
externalIPv4Blocks:
- /infra/ip-blocks/e2e_test_external_ip_blk
privateIPv4CIDRs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
# nsx-operator-ci would replace '{edge-cluster-id}' with real edge-cluster-id of testbed
edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/{edge-cluster-id}
defaultIPv4SubnetSize: 26
nsxtProject: /orgs/default/projects/nsx_operator_e2e_test
nsxtProject: /orgs/default/projects/nsx_operator_e2e_test_2
externalIPv4Blocks:
- /infra/ip-blocks/e2e_test_external_ip_blk
privateIPv4CIDRs:
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 @@ -13,7 +13,7 @@ spec:
# nsx-operator-ci would replace '{edge-cluster-id}' with real edge-cluster-id of testbed
edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/{edge-cluster-id}
defaultIPv4SubnetSize: 26
nsxtProject: /orgs/default/projects/nsx_operator_e2e_test
nsxtProject: /orgs/default/projects/nsx_operator_e2e_test_2
externalIPv4Blocks:
- /infra/ip-blocks/e2e_test_external_ip_blk
privateIPv4CIDRs:
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/manifest/testVPC/shared_ns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ kind: Namespace
metadata:
annotations:
nsx.vmware.com/vpc_network_config: selfdefinedconfig
name: shared-vpc-ns-0
name: shared-vpc-ns-9qsg6

---
apiVersion: v1
kind: Namespace
metadata:
annotations:
nsx.vmware.com/vpc_network_config: selfdefinedconfig
nsx.vmware.com/shared_vpc_namespace: shared-vpc-ns-0
name: shared-vpc-ns-1
nsx.vmware.com/shared_vpc_namespace: shared-vpc-ns-9qsg6
name: shared-vpc-ns-8l99n
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 @@ -10,7 +10,7 @@ spec:
# nsx-operator-ci would replace '{edge-cluster-id}' with real edge-cluster-id of testbed
edgeClusterPath: /infra/sites/default/enforcement-points/default/edge-clusters/{edge-cluster-id}
defaultIPv4SubnetSize: 26
nsxtProject: /orgs/default/projects/nsx_operator_e2e_test
nsxtProject: /orgs/default/projects/nsx_operator_e2e_test_2
externalIPv4Blocks:
- /infra/ip-blocks/e2e_test_external_ip_blk
privateIPv4CIDRs:
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/manifest/testVPC/update_ns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Namespace
metadata:
annotations:
nsx.vmware.com/vpc_network_config: selfdefinedconfig
name: update-ns
name: update-ns-lffpb
16 changes: 8 additions & 8 deletions test/e2e/nsx_networkinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -148,8 +148,8 @@ func TestDefaultNetworkInfo(t *testing.T) {

// ns1 share vpc with ns, delete ns1, vpc should not be deleted
func TestSharedNetworkInfo(t *testing.T) {
ns := "shared-vpc-ns-0"
ns1 := "shared-vpc-ns-1"
ns := "shared-vpc-ns-9qsg6"
ns1 := "shared-vpc-ns-8l99n"

nsPath, _ := filepath.Abs("./manifest/testVPC/shared_ns.yaml")
_ = applyYAML(nsPath, "")
Expand All @@ -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

Expand All @@ -191,7 +191,7 @@ func TestSharedNetworkInfo(t *testing.T) {

// update vpcnetworkconfig, and check vpc is updated
func TestUpdateVPCNetworkconfigNetworkInfo(t *testing.T) {
ns := "update-ns"
ns := "update-ns-lffpb"

nsPath, _ := filepath.Abs("./manifest/testVPC/update_ns.yaml")
_ = applyYAML(nsPath, "")
Expand All @@ -210,7 +210,7 @@ func TestUpdateVPCNetworkconfigNetworkInfo(t *testing.T) {
assertTrue(t, strings.Contains(privateIPv4CIDRs, CustomizedPrivateCIDR2), "privateIPv4CIDRs %s should contain %s", privateIPv4CIDRs, 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

Expand Down
Loading