From b11a4d1503243b76ab17889e974dc6387158329d 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 | 4 ++-- pkg/nsx/client.go | 4 +++- pkg/nsx/cluster.go | 3 +++ pkg/nsx/services/nsxserviceaccount/cluster.go | 13 +++++++++++-- pkg/nsx/services/nsxserviceaccount/cluster_test.go | 9 +++++++-- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index b0b7612d1..7cd2cdcb1 100644 --- a/go.mod +++ b/go.mod @@ -31,8 +31,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/pkg/nsx/client.go b/pkg/nsx/client.go index 3af7aa23f..9a7f09482 100644 --- a/pkg/nsx/client.go +++ b/pkg/nsx/client.go @@ -45,10 +45,11 @@ const ( ServiceAccountRestore ServiceAccountCertRotation StaticRoute + NodeType AllFeatures ) -var FeaturesName = [AllFeatures]string{"VPC", "SECURITY_POLICY", "NSX_SERVICE_ACCOUNT", "NSX_SERVICE_ACCOUNT_RESTORE", "NSX_SERVICE_ACCOUNT_CERT_ROTATION", "STATIC_ROUTE"} +var FeaturesName = [AllFeatures]string{"VPC", "SECURITY_POLICY", "NSX_SERVICE_ACCOUNT", "NSX_SERVICE_ACCOUNT_RESTORE", "NSX_SERVICE_ACCOUNT_CERT_ROTATION", "STATIC_ROUTE", "NODE_TYPE"} type Client struct { NsxConfig *config.NSXOperatorConfig @@ -110,6 +111,7 @@ var ( nsx411Version = [3]int64{4, 1, 1} nsx412Version = [3]int64{4, 1, 2} nsx413Version = [3]int64{4, 1, 3} + nsx900Version = [3]int64{9, 0, 0} ) type NSXHealthChecker struct { diff --git a/pkg/nsx/cluster.go b/pkg/nsx/cluster.go index 4ef866d4c..a1f0b158b 100644 --- a/pkg/nsx/cluster.go +++ b/pkg/nsx/cluster.go @@ -434,6 +434,9 @@ func (nsxVersion *NsxVersion) featureSupported(feature int) bool { case ServiceAccountCertRotation: minVersion = nsx413Version validFeature = true + case NodeType: + minVersion = nsx900Version + validFeature = true } if validFeature { diff --git a/pkg/nsx/services/nsxserviceaccount/cluster.go b/pkg/nsx/services/nsxserviceaccount/cluster.go index 4a933c737..f8d576a51 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 { @@ -255,14 +257,21 @@ func (s *NSXServiceAccountService) createPIAndCCP(normalizedClusterName string, hasCCP := len(s.ClusterControlPlaneStore.GetByIndex(common.TagScopeNSXServiceAccountCRUID, string(obj.UID))) > 0 clusterId := "" if ccpObj := s.ClusterControlPlaneStore.GetByKey(normalizedClusterName); !hasCCP && ccpObj == nil { - ccp, err := s.NSXClient.ClusterControlPlanesClient.Update(siteId, enforcementpointId, normalizedClusterName, model.ClusterControlPlane{ + modelCCP := model.ClusterControlPlane{ Revision: &revision1, ResourceType: &antreaClusterResourceType, Certificate: &cert, VhcPath: &vpcPath, NodeId: existingClusterId, Tags: s.buildBasicTags(obj), - }) + } + + if s.NSXClient.NSXCheckVersion(nsx.NodeType) { + modelCCP.NodeType = &nodeTypeAntrea + } + + ccp, err := s.NSXClient.ClusterControlPlanesClient.Update(siteId, enforcementpointId, normalizedClusterName, modelCCP) + 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 2730280fc..936219d4d 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{