From e88b5dcd8da6c62b905cd311acf3c93da6623ef9 Mon Sep 17 00:00:00 2001 From: Wenqi Qiu Date: Mon, 8 Jul 2024 07:52:14 +0800 Subject: [PATCH] Add node type Signed-off-by: Wenqi Qiu --- go.mod | 16 ++++++++++------ go.sum | 16 ++++++++-------- pkg/nsx/client.go | 10 ++++++---- pkg/nsx/cluster.go | 3 +++ pkg/nsx/services/nsxserviceaccount/cluster.go | 6 ++++++ .../services/nsxserviceaccount/cluster_test.go | 9 +++++++-- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index bc94941b3..c3041bb04 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,14 @@ replace ( github.com/vmware-tanzu/nsx-operator/pkg/apis/v1alpha1 => ./pkg/apis/v1alpha1 github.com/vmware-tanzu/nsx-operator/pkg/apis/v1alpha2 => ./pkg/apis/v1alpha2 github.com/vmware-tanzu/nsx-operator/pkg/client => ./pkg/client - github.com/vmware/vsphere-automation-sdk-go/lib => github.com/zhengxiexie/vsphere-automation-sdk-go/lib v0.7.3-0.20240628090521-3ad1af047210 - github.com/vmware/vsphere-automation-sdk-go/runtime => github.com/zhengxiexie/vsphere-automation-sdk-go/runtime v0.7.3-0.20240628090521-3ad1af047210 - github.com/vmware/vsphere-automation-sdk-go/services/nsxt => github.com/zhengxiexie/vsphere-automation-sdk-go/services/nsxt v0.12.3-0.20240628090521-3ad1af047210 - github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp => github.com/zhengxiexie/vsphere-automation-sdk-go/services/nsxt-mp v0.6.3-0.20240628090521-3ad1af047210 + //github.com/vmware/vsphere-automation-sdk-go/lib => github.com/zhengxiexie/vsphere-automation-sdk-go/lib v0.7.3-0.20240628090521-3ad1af047210 + //github.com/vmware/vsphere-automation-sdk-go/runtime => github.com/zhengxiexie/vsphere-automation-sdk-go/runtime v0.7.3-0.20240628090521-3ad1af047210 + //github.com/vmware/vsphere-automation-sdk-go/services/nsxt => github.com/zhengxiexie/vsphere-automation-sdk-go/services/nsxt v0.12.3-0.20240628090521-3ad1af047210 + //github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp => github.com/zhengxiexie/vsphere-automation-sdk-go/services/nsxt-mp v0.6.3-0.20240628090521-3ad1af047210 + github.com/vmware/vsphere-automation-sdk-go/lib => github.com/wenqiq/vsphere-automation-sdk-go/lib v0.7.3-0.20240707161013-a8f39aba7c1e + github.com/vmware/vsphere-automation-sdk-go/runtime => github.com/wenqiq/vsphere-automation-sdk-go/runtime v0.7.3-0.20240707161013-a8f39aba7c1e + github.com/vmware/vsphere-automation-sdk-go/services/nsxt => github.com/wenqiq/vsphere-automation-sdk-go/services/nsxt v0.12.3-0.20240707161013-a8f39aba7c1e + github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp => github.com/wenqiq/vsphere-automation-sdk-go/services/nsxt-mp v0.6.3-0.20240707161013-a8f39aba7c1e ) require ( @@ -32,8 +36,8 @@ require ( github.com/vmware-tanzu/nsx-operator/pkg/client v0.0.0-20240102061654-537b080e159f github.com/vmware-tanzu/vm-operator/api v1.8.2 github.com/vmware/govmomi v0.27.4 - github.com/vmware/vsphere-automation-sdk-go/lib v0.7.0 - github.com/vmware/vsphere-automation-sdk-go/runtime v0.7.1-0.20240611083326-25a4e1834c4d + github.com/vmware/vsphere-automation-sdk-go/lib v0.7.1 + github.com/vmware/vsphere-automation-sdk-go/runtime v0.7.1 github.com/vmware/vsphere-automation-sdk-go/services/nsxt v0.12.0 github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp v0.6.0 go.uber.org/automaxprocs v1.5.3 diff --git a/go.sum b/go.sum index d9138e776..20e16b320 100644 --- a/go.sum +++ b/go.sum @@ -182,17 +182,17 @@ github.com/vmware-tanzu/vm-operator/api v1.8.2/go.mod h1:vauVboD3sQxP+pb28TnI9wf github.com/vmware/govmomi v0.27.4 h1:5kY8TAkhB20lsjzrjE073eRb8+HixBI29PVMG5lxq6I= github.com/vmware/govmomi v0.27.4/go.mod h1:daTuJEcQosNMXYJOeku0qdBJP9SOLLWB3Mqz8THtv6o= github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728/go.mod h1:x9oS4Wk2s2u4tS29nEaDLdzvuHdB19CvSGJjPgkZJNk= +github.com/wenqiq/vsphere-automation-sdk-go/lib v0.7.3-0.20240707161013-a8f39aba7c1e h1:ZZaRftnZ4DP+220Ga4U6Y3/Vw5VXJ96xILvY0IOD1Wc= +github.com/wenqiq/vsphere-automation-sdk-go/lib v0.7.3-0.20240707161013-a8f39aba7c1e/go.mod h1:x4s3xpeRcJk6PTx9Xyb3LSDzHMLz9BKsA708vmss7MQ= +github.com/wenqiq/vsphere-automation-sdk-go/runtime v0.7.3-0.20240707161013-a8f39aba7c1e h1:4GPHMUuBv7uPhg0bqwu3B/i1VZiIxOM8qHlEp58HLWk= +github.com/wenqiq/vsphere-automation-sdk-go/runtime v0.7.3-0.20240707161013-a8f39aba7c1e/go.mod h1:DzLetYAmw1+vj7bqElRWEpuy40WYE/woL3alsymYa/c= +github.com/wenqiq/vsphere-automation-sdk-go/services/nsxt v0.12.3-0.20240707161013-a8f39aba7c1e h1:CxFT1A9bYXCj65epb0JYq3p2l4MearOvS0wn89WG0sk= +github.com/wenqiq/vsphere-automation-sdk-go/services/nsxt v0.12.3-0.20240707161013-a8f39aba7c1e/go.mod h1:5svFmx8JLpYUwXiAevMJ3mcu+OmEkBp/t3TlMXXbovw= +github.com/wenqiq/vsphere-automation-sdk-go/services/nsxt-mp v0.6.3-0.20240707161013-a8f39aba7c1e h1:Qh0W4qbqiEOV9+HUxHRPz/uFfC/2g6Zr0LUjJRwIpME= +github.com/wenqiq/vsphere-automation-sdk-go/services/nsxt-mp v0.6.3-0.20240707161013-a8f39aba7c1e/go.mod h1:KAXagEsQzxWVrf/W1FejwoGI0TFqCvtAlTl4skHnpU4= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/zhengxiexie/vsphere-automation-sdk-go/lib v0.7.3-0.20240628090521-3ad1af047210 h1:ZdoS46cHwnmPh4bs6OxlllI6PX92Z4a3qm428s4f93c= -github.com/zhengxiexie/vsphere-automation-sdk-go/lib v0.7.3-0.20240628090521-3ad1af047210/go.mod h1:CNBmjJmN8Mja3FRhLN4q6n9qhiBfxvq3Uij8t7r6370= -github.com/zhengxiexie/vsphere-automation-sdk-go/runtime v0.7.3-0.20240628090521-3ad1af047210 h1:vYtG51i9JqSO06oJlDa23riTvMP2ppnQ72FdhoJVtGQ= -github.com/zhengxiexie/vsphere-automation-sdk-go/runtime v0.7.3-0.20240628090521-3ad1af047210/go.mod h1:DzLetYAmw1+vj7bqElRWEpuy40WYE/woL3alsymYa/c= -github.com/zhengxiexie/vsphere-automation-sdk-go/services/nsxt v0.12.3-0.20240628090521-3ad1af047210 h1:sclbs9AnzZ6gb8apIUQJI5rqx/SixhoCAu5O1mUcxoY= -github.com/zhengxiexie/vsphere-automation-sdk-go/services/nsxt v0.12.3-0.20240628090521-3ad1af047210/go.mod h1:RACl1XoB+anHOOgmYjM72zJAKOtr1gNkx2u+ZLt93D8= -github.com/zhengxiexie/vsphere-automation-sdk-go/services/nsxt-mp v0.6.3-0.20240628090521-3ad1af047210 h1:34H/XVcNwNYrkdcBNrqOC298XL17idkjvp1kr5HWoHc= -github.com/zhengxiexie/vsphere-automation-sdk-go/services/nsxt-mp v0.6.3-0.20240628090521-3ad1af047210/go.mod h1:ur/ob18hNxdaK42eug61vyiq7rbLQJhnOngdQSvgr54= go.etcd.io/etcd/api/v3 v3.5.10 h1:szRajuUUbLyppkhs9K6BRtjY37l66XQQmw7oZRANE4k= go.etcd.io/etcd/api/v3 v3.5.10/go.mod h1:TidfmT4Uycad3NM/o25fG3J07odo4GBB9hoxaodFCtI= go.etcd.io/etcd/client/pkg/v3 v3.5.10 h1:kfYIdQftBnbAq8pUWFXfpuuxFSKzlmM5cSn76JByiT0= diff --git a/pkg/nsx/client.go b/pkg/nsx/client.go index 412b0bd1e..b1d7b54cd 100644 --- a/pkg/nsx/client.go +++ b/pkg/nsx/client.go @@ -18,11 +18,11 @@ import ( "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains/security_policies" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sites/enforcement_points" - projects "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects" - infra "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/realized_state" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs" - nat "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/nat" + "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/nat" vpc_sp "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/security_policies" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/subnets" "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/subnets/ip_pools" @@ -42,10 +42,11 @@ const ( ServiceAccountCertRotation StaticRoute VpcAviRule + NodeType AllFeatures ) -var FeaturesName = [AllFeatures]string{"VPC", "SECURITY_POLICY", "NSX_SERVICE_ACCOUNT", "NSX_SERVICE_ACCOUNT_RESTORE", "NSX_SERVICE_ACCOUNT_CERT_ROTATION", "STATIC_ROUTE", "VPC_AVI_RULE"} +var FeaturesName = [AllFeatures]string{"VPC", "SECURITY_POLICY", "NSX_SERVICE_ACCOUNT", "NSX_SERVICE_ACCOUNT_RESTORE", "NSX_SERVICE_ACCOUNT_CERT_ROTATION", "STATIC_ROUTE", "VPC_AVI_RULE", "NODE_TYPE"} type Client struct { NsxConfig *config.NSXOperatorConfig @@ -95,6 +96,7 @@ var ( nsx411Version = [3]int64{4, 1, 1} nsx412Version = [3]int64{4, 1, 2} nsx413Version = [3]int64{4, 1, 3} + nsx421Version = [3]int64{4, 2, 1} ) type NSXHealthChecker struct { diff --git a/pkg/nsx/cluster.go b/pkg/nsx/cluster.go index ac3f8ab89..6e235a010 100644 --- a/pkg/nsx/cluster.go +++ b/pkg/nsx/cluster.go @@ -437,6 +437,9 @@ func (nsxVersion *NsxVersion) featureSupported(feature int) bool { case VpcAviRule: minVersion = nsx411Version validFeature = true + case NodeType: + minVersion = nsx421Version + validFeature = true } if validFeature { diff --git a/pkg/nsx/services/nsxserviceaccount/cluster.go b/pkg/nsx/services/nsxserviceaccount/cluster.go index d527d1006..122028b9e 100644 --- a/pkg/nsx/services/nsxserviceaccount/cluster.go +++ b/pkg/nsx/services/nsxserviceaccount/cluster.go @@ -55,6 +55,8 @@ var ( revision1 = int64(1) proxyLabels = map[string]string{"mgmt-proxy.antrea-nsx.vmware.com": ""} + + nodeTypeAntrea = "ANTREA_NODE" ) type NSXServiceAccountService struct { @@ -263,6 +265,10 @@ func (s *NSXServiceAccountService) createPIAndCCP(normalizedClusterName string, NodeId: existingClusterId, Tags: s.buildBasicTags(obj), }) + + if s.NSXClient.NSXCheckVersion(nsx.NodeType) { + ccp.NodeType = &nodeTypeAntrea + } err = nsxutil.NSXApiError(err) if err != nil { return "", err diff --git a/pkg/nsx/services/nsxserviceaccount/cluster_test.go b/pkg/nsx/services/nsxserviceaccount/cluster_test.go index 985218534..7828e0bd6 100644 --- a/pkg/nsx/services/nsxserviceaccount/cluster_test.go +++ b/pkg/nsx/services/nsxserviceaccount/cluster_test.go @@ -310,6 +310,7 @@ func TestNSXServiceAccountService_CreateOrUpdateNSXServiceAccount(t *testing.T) ResourceType: &antreaClusterResourceType, Certificate: nil, VhcPath: &vpcPath, + NodeType: &nodeTypeAntrea, Tags: []model.Tag{{ Scope: &tagScopeCluster, Tag: &s.NSXConfig.CoeConfig.Cluster, @@ -328,7 +329,7 @@ func TestNSXServiceAccountService_CreateOrUpdateNSXServiceAccount(t *testing.T) }}) patches.ApplyMethodSeq(s.NSXClient, "NSXCheckVersion", []gomonkey.OutputCell{{ Values: gomonkey.Params{true}, - Times: 1, + Times: 2, }}) return patches }, @@ -446,7 +447,7 @@ func TestNSXServiceAccountService_CreateOrUpdateNSXServiceAccount(t *testing.T) }}) patches.ApplyMethodSeq(s.NSXClient, "NSXCheckVersion", []gomonkey.OutputCell{{ Values: gomonkey.Params{true}, - Times: 1, + Times: 2, }}) return patches }, @@ -888,6 +889,10 @@ func TestNSXServiceAccountService_RestoreRealizedNSXServiceAccount(t *testing.T) }, nil}, Times: 1, }}) + patches.ApplyMethodSeq(s.NSXClient, "NSXCheckVersion", []gomonkey.OutputCell{{ + Values: gomonkey.Params{true}, + Times: 1, + }}) return patches }, args: args{