diff --git a/pkg/nsx/services/mediator/mediator.go b/pkg/nsx/services/mediator/mediator.go index a71d12269..2fc408ded 100644 --- a/pkg/nsx/services/mediator/mediator.go +++ b/pkg/nsx/services/mediator/mediator.go @@ -85,7 +85,7 @@ func (serviceMediator *ServiceMediator) GetAvailableSubnet(subnetSet *v1alpha1.S return serviceMediator.CreateOrUpdateSubnet(subnetSet, tags) } -func (serviceMediator *ServiceMediator) GetPortsOfSubnet(nsxSubnetID string) (ports []model.SegmentPort) { +func (serviceMediator *ServiceMediator) GetPortsOfSubnet(nsxSubnetID string) (ports []model.VpcSubnetPort) { subnetPortList := serviceMediator.SubnetPortStore.GetByIndex(common.IndexKeySubnetID, nsxSubnetID) return subnetPortList } diff --git a/pkg/nsx/services/subnetport/builder.go b/pkg/nsx/services/subnetport/builder.go index b964a951c..0372b1ae3 100644 --- a/pkg/nsx/services/subnetport/builder.go +++ b/pkg/nsx/services/subnetport/builder.go @@ -20,7 +20,7 @@ var ( String = common.String ) -func (service *SubnetPortService) buildSubnetPort(obj interface{}, nsxSubnetPath string, contextID string, labelTags *map[string]string) (*model.SegmentPort, error) { +func (service *SubnetPortService) buildSubnetPort(obj interface{}, nsxSubnetPath string, contextID string, labelTags *map[string]string) (*model.VpcSubnetPort, error) { var objName, objNamespace, uid, appId string switch o := obj.(type) { case *v1alpha1.SubnetPort: @@ -59,7 +59,7 @@ func (service *SubnetPortService) buildSubnetPort(obj interface{}, nsxSubnetPath tags = append(tags, model.Tag{Scope: String(k), Tag: String(v)}) } } - nsxSubnetPort := &model.SegmentPort{ + nsxSubnetPort := &model.VpcSubnetPort{ DisplayName: String(nsxSubnetPortName), Id: String(nsxSubnetPortID), Attachment: &model.PortAttachment{ diff --git a/pkg/nsx/services/subnetport/compare.go b/pkg/nsx/services/subnetport/compare.go index fde134657..d2c43a9b0 100644 --- a/pkg/nsx/services/subnetport/compare.go +++ b/pkg/nsx/services/subnetport/compare.go @@ -8,7 +8,7 @@ import ( ) type ( - SubnetPort model.SegmentPort + SubnetPort model.VpcSubnetPort ) type Comparable = common.Comparable @@ -40,10 +40,10 @@ func (sp *SubnetPort) Value() data.DataValue { return dataValue } -func SubnetPortToComparable(sp *model.SegmentPort) Comparable { +func SubnetPortToComparable(sp *model.VpcSubnetPort) Comparable { return (*SubnetPort)(sp) } -func ComparableToSubnetPort(sp Comparable) *model.SegmentPort { - return (*model.SegmentPort)(sp.(*SubnetPort)) +func ComparableToSubnetPort(sp Comparable) *model.VpcSubnetPort { + return (*model.VpcSubnetPort)(sp.(*SubnetPort)) } diff --git a/pkg/nsx/services/subnetport/store.go b/pkg/nsx/services/subnetport/store.go index adf87ecf0..9f17fb59a 100644 --- a/pkg/nsx/services/subnetport/store.go +++ b/pkg/nsx/services/subnetport/store.go @@ -13,7 +13,7 @@ import ( // keyFunc is used to get the key of a resource, usually, which is the ID of the resource func keyFunc(obj interface{}) (string, error) { switch v := obj.(type) { - case model.SegmentPort: + case model.VpcSubnetPort: return *v.Id, nil case types.UID: return string(v), nil @@ -36,7 +36,7 @@ func filterTag(tags []model.Tag, tagScope string) []string { // index is used to filter out resources which are related to the CR func subnetPortIndexByCRUID(obj interface{}) ([]string, error) { switch o := obj.(type) { - case model.SegmentPort: + case model.VpcSubnetPort: return filterTag(o.Tags, common.TagScopeSubnetPortCRUID), nil default: return nil, errors.New("subnetPortIndexByCRUID doesn't support unknown type") @@ -45,7 +45,7 @@ func subnetPortIndexByCRUID(obj interface{}) ([]string, error) { func subnetPortIndexByPodUID(obj interface{}) ([]string, error) { switch o := obj.(type) { - case model.SegmentPort: + case model.VpcSubnetPort: return filterTag(o.Tags, common.TagScopePodUID), nil default: return nil, errors.New("subnetPortIndexByCRUID doesn't support unknown type") @@ -54,7 +54,7 @@ func subnetPortIndexByPodUID(obj interface{}) ([]string, error) { func subnetPortIndexBySubnetID(obj interface{}) ([]string, error) { switch o := obj.(type) { - case model.SegmentPort: + case model.VpcSubnetPort: vpcInfo, err := common.ParseVPCResourcePath(*o.Path) if err != nil { return nil, err @@ -75,7 +75,7 @@ func (vs *SubnetPortStore) Apply(i interface{}) error { if i == nil { return nil } - subnetPort := i.(*model.SegmentPort) + subnetPort := i.(*model.VpcSubnetPort) if subnetPort.MarkedForDelete != nil && *subnetPort.MarkedForDelete { err := vs.Delete(*subnetPort) log.V(1).Info("delete SubnetPort from store", "subnetport", subnetPort) @@ -92,26 +92,26 @@ func (vs *SubnetPortStore) Apply(i interface{}) error { return nil } -func (subnetPortStore *SubnetPortStore) GetByKey(key string) *model.SegmentPort { - var subnetPort model.SegmentPort +func (subnetPortStore *SubnetPortStore) GetByKey(key string) *model.VpcSubnetPort { + var subnetPort model.VpcSubnetPort obj := subnetPortStore.ResourceStore.GetByKey(key) if obj != nil { - subnetPort = obj.(model.SegmentPort) + subnetPort = obj.(model.VpcSubnetPort) } return &subnetPort } -func (subnetPortStore *SubnetPortStore) GetByIndex(key string, value string) []model.SegmentPort { - segmentPorts := make([]model.SegmentPort, 0) +func (subnetPortStore *SubnetPortStore) GetByIndex(key string, value string) []model.VpcSubnetPort { + subnetPorts := make([]model.VpcSubnetPort, 0) objs := subnetPortStore.ResourceStore.GetByIndex(key, value) for _, subnetPort := range objs { - segmentPorts = append(segmentPorts, subnetPort.(model.SegmentPort)) + subnetPorts = append(subnetPorts, subnetPort.(model.VpcSubnetPort)) } - return segmentPorts + return subnetPorts } -func (vs *SubnetPortStore) GetSubnetPortsByNamespace(ns string) []model.SegmentPort { - var ret []model.SegmentPort +func (vs *SubnetPortStore) GetSubnetPortsByNamespace(ns string) []model.VpcSubnetPort { + var ret []model.VpcSubnetPort subnetPorts := vs.List() if len(subnetPorts) == 0 { log.V(1).Info("No subnet port found in SubnetPort store") @@ -119,7 +119,7 @@ func (vs *SubnetPortStore) GetSubnetPortsByNamespace(ns string) []model.SegmentP } for _, subnetPort := range subnetPorts { - msubnetport := subnetPort.(model.SegmentPort) + msubnetport := subnetPort.(model.VpcSubnetPort) tags := msubnetport.Tags for _, tag := range tags { // TODO: consider to create index for common.TagScopeNamespace like common.TagScopeSubnetPortCRUID, and leverage functions like getByIndex to perform searches. diff --git a/pkg/nsx/services/subnetport/subnetport.go b/pkg/nsx/services/subnetport/subnetport.go index bc4bfa2ac..3ec7c74c9 100644 --- a/pkg/nsx/services/subnetport/subnetport.go +++ b/pkg/nsx/services/subnetport/subnetport.go @@ -52,7 +52,7 @@ func InitializeSubnetPort(service servicecommon.Service) (*SubnetPortService, er servicecommon.TagScopePodUID: subnetPortIndexByPodUID, servicecommon.IndexKeySubnetID: subnetPortIndexBySubnetID, }), - BindingType: model.SegmentPortBindingType(), + BindingType: model.VpcSubnetPortBindingType(), }} go subnetPortService.InitializeResourceStore(&wg, fatalErrors, ResourceTypeSubnetPort, nil, subnetPortService.SubnetPortStore) @@ -82,9 +82,7 @@ func (service *SubnetPortService) CreateOrUpdateSubnetPort(obj interface{}, nsxS uid = string(o.UID) } log.Info("creating or updating subnetport", "nsxSubnetPort.Id", uid, "nsxSubnetPath", nsxSubnetPath) - //nsxSubnetPort, err := service.buildSubnetPort(obj, nsxSubnetPath, contextID, tags) - nsxSubnetPort := &model.VpcSubnetPort{} - var err error + nsxSubnetPort, err := service.buildSubnetPort(obj, nsxSubnetPath, contextID, tags) if err != nil { log.Error(err, "failed to build NSX subnet port", "nsxSubnetPort.Id", uid, "nsxSubnetPath", nsxSubnetPath, "contextID", contextID) return nil, err @@ -95,8 +93,7 @@ func (service *SubnetPortService) CreateOrUpdateSubnetPort(obj interface{}, nsxS return nil, err } existingSubnetPort := service.SubnetPortStore.GetByKey(*nsxSubnetPort.Id) - //isChanged := servicecommon.CompareResource(SubnetPortToComparable(existingSubnetPort), SubnetPortToComparable(nsxSubnetPort)) - isChanged := false + isChanged := servicecommon.CompareResource(SubnetPortToComparable(existingSubnetPort), SubnetPortToComparable(nsxSubnetPort)) if !isChanged { log.Info("NSX subnet port not changed, skipping the update", "nsxSubnetPort.Id", nsxSubnetPort.Id, "nsxSubnetPath", nsxSubnetPath) // We don't need to update it but still need to check realized state. @@ -261,7 +258,7 @@ func (service *SubnetPortService) Cleanup() error { subnetPorts := service.SubnetPortStore.List() log.Info("cleanup subnetports", "count", len(subnetPorts)) for _, subnetPort := range subnetPorts { - subnetPortID := types.UID(*subnetPort.(model.SegmentPort).Id) + subnetPortID := types.UID(*subnetPort.(model.VpcSubnetPort).Id) err := service.DeleteSubnetPort(subnetPortID) if err != nil { log.Error(err, "cleanup subnetport failed", "subnetPortID", subnetPortID)