Skip to content

Commit

Permalink
Add node type
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Qiu <[email protected]>
  • Loading branch information
wenqiq committed Sep 5, 2024
1 parent 72baaea commit b11a4d1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/nsx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/nsx/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions pkg/nsx/services/nsxserviceaccount/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ var (
revision1 = int64(1)

proxyLabels = map[string]string{"mgmt-proxy.antrea-nsx.vmware.com": ""}

nodeTypeAntrea = "ANTREA_NODE"
)

type NSXServiceAccountService struct {
Expand Down Expand Up @@ -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

Check failure on line 270 in pkg/nsx/services/nsxserviceaccount/cluster.go

View workflow job for this annotation

GitHub Actions / build

modelCCP.NodeType undefined (type "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model".ClusterControlPlane has no field or method NodeType)) (typecheck)

Check failure on line 270 in pkg/nsx/services/nsxserviceaccount/cluster.go

View workflow job for this annotation

GitHub Actions / build

modelCCP.NodeType undefined (type "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model".ClusterControlPlane has no field or method NodeType)) (typecheck)

Check failure on line 270 in pkg/nsx/services/nsxserviceaccount/cluster.go

View workflow job for this annotation

GitHub Actions / build

modelCCP.NodeType undefined (type "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model".ClusterControlPlane has no field or method NodeType)
}

ccp, err := s.NSXClient.ClusterControlPlanesClient.Update(siteId, enforcementpointId, normalizedClusterName, modelCCP)

err = nsxutil.NSXApiError(err)
if err != nil {
return "", err
Expand Down
9 changes: 7 additions & 2 deletions pkg/nsx/services/nsxserviceaccount/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func TestNSXServiceAccountService_CreateOrUpdateNSXServiceAccount(t *testing.T)
ResourceType: &antreaClusterResourceType,
Certificate: nil,
VhcPath: &vpcPath,
NodeType: &nodeTypeAntrea,

Check failure on line 313 in pkg/nsx/services/nsxserviceaccount/cluster_test.go

View workflow job for this annotation

GitHub Actions / build

unknown field NodeType in struct literal of type "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model".ClusterControlPlane (typecheck)
Tags: []model.Tag{{
Scope: &tagScopeCluster,
Tag: &s.NSXConfig.CoeConfig.Cluster,
Expand All @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit b11a4d1

Please sign in to comment.