Skip to content

Commit

Permalink
Merge pull request vmware-tanzu#461 from TaoZou1/rename
Browse files Browse the repository at this point in the history
Update vpc/tag/subnetset name
  • Loading branch information
TaoZou1 authored Dec 25, 2023
2 parents 8192539 + 3c5374d commit ea99537
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 50 deletions.
10 changes: 4 additions & 6 deletions pkg/controllers/subnetset/vpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@ package subnetset
import (
"context"

"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common"

"sigs.k8s.io/controller-runtime/pkg/predicate"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"github.com/vmware-tanzu/nsx-operator/pkg/apis/v1alpha1"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common"
)

// VPCHandler handles VPC event for SubnetSet:
// - VPC creation: create default SubnetSet for the VPC.
// - VPC deletion: delete all SubnetSets under the VPC.

var defaultSubnetSets = map[string]string{
"default-vm-subnetset": common.LabelDefaultVMSubnetSet,
"default-pod-subnetset": common.LabelDefaultPodSubnetSet,
common.DefaultVMSubnetSet: common.LabelDefaultVMSubnetSet,
common.DefaultPodSubnetSet: common.LabelDefaultPodSubnetSet,
}

type VPCHandler struct {
Expand Down
36 changes: 19 additions & 17 deletions pkg/nsx/services/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const (
TagScopeCluster string = "nsx-op/cluster"
TagScopeNamespace string = "nsx-op/namespace"
TagScopeNamespaceUID string = "nsx-op/namespace_uid"
TagScopeSecurityPolicyCRName string = "nsx-op/security_policy_cr_name"
TagScopeSecurityPolicyCRUID string = "nsx-op/security_policy_cr_uid"
TagScopeStaticRouteCRName string = "nsx-op/static_route_cr_name"
TagScopeStaticRouteCRUID string = "nsx-op/static_route_cr_uid"
TagScopeSecurityPolicyCRName string = "nsx-op/security_policy_name"
TagScopeSecurityPolicyCRUID string = "nsx-op/security_policy_uid"
TagScopeStaticRouteCRName string = "nsx-op/static_route_name"
TagScopeStaticRouteCRUID string = "nsx-op/static_route_uid"
TagScopeRuleID string = "nsx-op/rule_id"
TagScopeGoupID string = "nsx-op/group_id"
TagScopeGroupType string = "nsx-op/group_type"
Expand All @@ -41,24 +41,26 @@ const (
TagScopeNSXServiceAccountCRUID string = "nsx-op/nsx_service_account_uid"
TagScopeNSXProjectID string = "nsx-op/nsx_project_id"
TagScopeProjectGroupShared string = "nsx-op/is_nsx_project_shared"
TagScopeVPCCRName string = "nsx-op/vpc_cr_name"
TagScopeVPCCRUID string = "nsx-op/vpc_cr_uid"
TagScopeSubnetPortCRName string = "nsx-op/subnetport_cr_name"
TagScopeSubnetPortCRUID string = "nsx-op/subnetport_cr_uid"
TagScopeIPPoolCRName string = "nsx-op/ippool_cr_name"
TagScopeIPPoolCRUID string = "nsx-op/ippool_cr_uid"
TagScopeIPPoolCRType string = "nsx-op/ippool_cr_type"
TagScopeIPSubnetName string = "nsx-op/ipsubnet_cr_name"
TagScopeVPCCRName string = "nsx-op/vpc_name"
TagScopeVPCCRUID string = "nsx-op/vpc_uid"
TagScopeSubnetPortCRName string = "nsx-op/subnetport_name"
TagScopeSubnetPortCRUID string = "nsx-op/subnetport_uid"
TagScopeIPPoolCRName string = "nsx-op/ippool_name"
TagScopeIPPoolCRUID string = "nsx-op/ippool_uid"
TagScopeIPPoolCRType string = "nsx-op/ippool_type"
TagScopeIPSubnetName string = "nsx-op/ipsubnet_name"
TagScopeVMNamespaceUID string = "nsx-op/vm_namespace_uid"
TagScopeVMNamespace string = "nsx-op/vm_namespace"
LabelDefaultSubnetSet string = "nsxoperator.vmware.com/default-subnetset-for"
LabelDefaultVMSubnetSet string = "VirtualMachine"
LabelDefaultPodSubnetSet string = "Pod"
TagScopeSubnetCRType string = "nsx-op/subnet_cr_type"
TagScopeSubnetCRUID string = "nsx-op/subnet_cr_uid"
TagScopeSubnetCRName string = "nsx-op/subnet_cr_name"
TagScopeSubnetSetCRName string = "nsx-op/subnetset_cr_name"
TagScopeSubnetSetCRUID string = "nsx-op/subnetset_cr_uid"
DefaultPodSubnetSet string = "pod-default"
DefaultVMSubnetSet string = "vm-default"
TagScopeSubnetCRType string = "nsx-op/subnet_type"
TagScopeSubnetCRUID string = "nsx-op/subnet_uid"
TagScopeSubnetCRName string = "nsx-op/subnet_name"
TagScopeSubnetSetCRName string = "nsx-op/subnetset_name"
TagScopeSubnetSetCRUID string = "nsx-op/subnetset_uid"
TagValueGroupScope string = "scope"
TagValueGroupSrc string = "source"
TagValueGroupDst string = "destination"
Expand Down
12 changes: 6 additions & 6 deletions pkg/nsx/services/ippool/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func TestIPPoolService_BuildIPPool(t *testing.T) {
{Scope: String("nsx-op/cluster"), Tag: String("k8scl-one:test")},
{Scope: String("nsx-op/version"), Tag: String(strings.Join(common.TagValueVersion, "."))},
{Scope: String("nsx-op/namespace"), Tag: String("")},
{Scope: String("nsx-op/ippool_cr_name"), Tag: String("ippool1")},
{Scope: String("nsx-op/ippool_name"), Tag: String("ippool1")},
{
Scope: String("nsx-op/ippool_cr_uid"),
Scope: String("nsx-op/ippool_uid"),
Tag: String("uuid1"),
},
{Scope: String("nsx-op/ippool_cr_type"), Tag: String("public")},
{Scope: String("nsx-op/ippool_type"), Tag: String("public")},
},
}

Expand All @@ -60,9 +60,9 @@ func TestIPPoolService_BuildIPPool(t *testing.T) {
{Scope: String("nsx-op/cluster"), Tag: String("k8scl-one:test")},
{Scope: String("nsx-op/version"), Tag: String(strings.Join(common.TagValueVersion, "."))},
{Scope: String("nsx-op/namespace"), Tag: String("")},
{Scope: String("nsx-op/ippool_cr_name"), Tag: String("ippool1")},
{Scope: String("nsx-op/ippool_cr_uid"), Tag: String("uuid1")},
{Scope: String("nsx-op/ipsubnet_cr_name"), Tag: String("subnet1")},
{Scope: String("nsx-op/ippool_name"), Tag: String("ippool1")},
{Scope: String("nsx-op/ippool_uid"), Tag: String("uuid1")},
{Scope: String("nsx-op/ipsubnet_name"), Tag: String("subnet1")},
},
Size: Int64(256),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/nsx/services/securitypolicy/firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func TestListSecurityPolicyID(t *testing.T) {
}}

group := model.Group{}
scope := "nsx-op/security_policy_cr_uid"
scope := "nsx-op/security_policy_uid"
uuid := "111111111"
id := "1234"
group.Id = &id
Expand Down
4 changes: 2 additions & 2 deletions pkg/nsx/services/securitypolicy/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

func Test_IndexFunc(t *testing.T) {
mId, mTag, mScope := "11111", "11111", "nsx-op/security_policy_cr_uid"
mId, mTag, mScope := "11111", "11111", "nsx-op/security_policy_uid"
m := model.Group{
Id: &mId,
Tags: []model.Tag{{Tag: &mTag, Scope: &mScope}},
Expand Down Expand Up @@ -54,7 +54,7 @@ func Test_IndexFunc(t *testing.T) {
}

func Test_filterTag(t *testing.T) {
mTag, mScope := "11111", "nsx-op/security_policy_cr_uid"
mTag, mScope := "11111", "nsx-op/security_policy_uid"
mTag2, mScope2 := "11111", "nsx"
tags := []model.Tag{{Scope: &mScope, Tag: &mTag}}
tags2 := []model.Tag{{Scope: &mScope2, Tag: &mTag2}}
Expand Down
6 changes: 3 additions & 3 deletions pkg/nsx/services/securitypolicy/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func fakeService() *SecurityPolicyService {
func TestSecurityPolicyService_wrapSecurityPolicy(t *testing.T) {
Converter := bindings.NewTypeConverter()
service := fakeService()
mId, mTag, mScope := "11111", "11111", "nsx-op/security_policy_cr_uid"
mId, mTag, mScope := "11111", "11111", "nsx-op/security_policy_uid"
markDelete := true
s := model.SecurityPolicy{
Id: &mId,
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestSecurityPolicyService_wrapSecurityPolicy(t *testing.T) {
func TestSecurityPolicyService_wrapGroups(t *testing.T) {
Converter := bindings.NewTypeConverter()
service := fakeService()
mId, mTag, mScope := "11111", "11111", "nsx-op/security_policy_cr_uid"
mId, mTag, mScope := "11111", "11111", "nsx-op/security_policy_uid"
markDelete := true
m := model.Group{
Id: &mId,
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestSecurityPolicyService_wrapGroups(t *testing.T) {
func TestSecurityPolicyService_wrapRules(t *testing.T) {
Converter := bindings.NewTypeConverter()
service := fakeService()
mId, mTag, mScope := "11111", "11111", "nsx-op/security_policy_cr_uid"
mId, mTag, mScope := "11111", "11111", "nsx-op/security_policy_uid"
markDelete := true
r := model.Rule{
Id: &mId,
Expand Down
2 changes: 1 addition & 1 deletion pkg/nsx/services/subnet/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func fakeService() *SubnetService {
func TestSubnetService_wrapSubnet(t *testing.T) {
Converter := bindings.NewTypeConverter()
service := fakeService()
mId, mTag, mScope := "11111", "11111", "nsx-op/subnet_cr_uid"
mId, mTag, mScope := "11111", "11111", "nsx-op/subnet_uid"
markDelete := true
s := model.VpcSubnet{
Id: &mId,
Expand Down
3 changes: 1 addition & 2 deletions pkg/nsx/services/vpc/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func buildNSXVPC(obj *v1alpha1.VPC, nc VPCNetworkConfigInfo, cluster string, pat
vpc = nsxVPC
} else {
// for creating vpc case, fill in vpc properties based on networkconfig
suffix := obj.GetNamespace() + "-" + obj.Name
vpcName := util.GenerateDisplayName("vpc", "", suffix, "", cluster)
vpcName := util.GenerateDisplayName(obj.Name, obj.GetNamespace(), cluster, "", "")
vpc.DisplayName = &vpcName
vpc.Id = common.String(string(obj.GetUID()))
vpc.DefaultGatewayPath = &nc.DefaultGatewayPath
Expand Down
4 changes: 2 additions & 2 deletions pkg/nsx/services/vpc/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (qIface *fakeQueryClient) List(_ string, _ *string, _ *string, _ *int64, _
}

func Test_IndexFunc(t *testing.T) {
mId, mTag, mScope := "test_id", "test_tag", "nsx-op/vpc_cr_uid"
mId, mTag, mScope := "test_id", "test_tag", "nsx-op/vpc_uid"
v := model.Vpc{
Id: &mId,
Tags: []model.Tag{{Tag: &mTag, Scope: &mScope}},
Expand All @@ -47,7 +47,7 @@ func Test_IndexFunc(t *testing.T) {
}

func Test_filterTag(t *testing.T) {
mTag, mScope := "test_tag", "nsx-op/vpc_cr_uid"
mTag, mScope := "test_tag", "nsx-op/vpc_uid"
mTag2, mScope2 := "test_tag", "nsx"
tags := []model.Tag{{Scope: &mScope, Tag: &mTag}}
tags2 := []model.Tag{{Scope: &mScope2, Tag: &mTag2}}
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
Expand Up @@ -4,4 +4,4 @@ metadata:
name: port-1
namespace: subnet-e2e
spec:
subnetSet: default-pod-subnetset
subnetSet: pod-default
17 changes: 8 additions & 9 deletions test/e2e/nsx_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common"
)

const (
DefaultPodSubnetSet = "default-pod-subnetset"
DefaultVMSubnetSet = "default-vm-subnetset"
SubnetSetCRType = "subnetsets"
E2ENamespace = "subnet-e2e"
VPCNetworkConfigCRName = "default"
Expand Down Expand Up @@ -50,15 +49,15 @@ func TestDefaultSubnetSet(t *testing.T) {
setupTest(t, E2ENamespace)
defer teardownTest(t, E2ENamespace, SubnetDeletionTimeout)

// 1. Check whether default-vm-subnetset and default-pod-subnetset are created.
err := testData.waitForCRReadyOrDeleted(defaultTimeout, SubnetSetCRType, E2ENamespace, DefaultVMSubnetSet, Ready)
// 1. Check whether vm-default, pod-default are created.
err := testData.waitForCRReadyOrDeleted(defaultTimeout, SubnetSetCRType, E2ENamespace, common.DefaultVMSubnetSet, Ready)
assert_nil(t, err)
err = testData.waitForCRReadyOrDeleted(defaultTimeout, SubnetSetCRType, E2ENamespace, DefaultPodSubnetSet, Ready)
err = testData.waitForCRReadyOrDeleted(defaultTimeout, SubnetSetCRType, E2ENamespace, common.DefaultPodSubnetSet, Ready)
assert_nil(t, err)

// 2. Check `Ipv4SubnetSize` and `AccessMode` should be same with related fields in VPCNetworkConfig.
assert_true(t, verifySubnetSetCR(DefaultVMSubnetSet))
assert_true(t, verifySubnetSetCR(DefaultPodSubnetSet))
assert_true(t, verifySubnetSetCR(common.DefaultVMSubnetSet))
assert_true(t, verifySubnetSetCR(common.DefaultPodSubnetSet))

portPath, _ := filepath.Abs("./manifest/testSubnet/subnetport_1.yaml")
err = applyYAML(portPath, E2ENamespace)
Expand All @@ -67,7 +66,7 @@ func TestDefaultSubnetSet(t *testing.T) {
defer deleteYAML(portPath, E2ENamespace)

// 3. Check SubnetSet CR status should be updated with NSX subnet info.
subnetSet, err := testData.crdClientset.NsxV1alpha1().SubnetSets(E2ENamespace).Get(context.TODO(), DefaultPodSubnetSet, v1.GetOptions{})
subnetSet, err := testData.crdClientset.NsxV1alpha1().SubnetSets(E2ENamespace).Get(context.TODO(), common.DefaultPodSubnetSet, v1.GetOptions{})
assert_nil(t, err)
assert.NotEmpty(t, subnetSet.Status.Subnets, "No Subnet info in SubnetSet")
// 4. Check NSX subnet allocation.
Expand Down

0 comments on commit ea99537

Please sign in to comment.