Skip to content

Commit

Permalink
Fix a subnetport ID issue during checking the port state
Browse files Browse the repository at this point in the history
We changed the subnetport ID to `<pod/vm name>-<uid>` but when getting
the NSX port state, the operator still tried to get the resource via
object uid. This patch will fix the issue.
  • Loading branch information
heypnus committed Aug 13, 2024
1 parent cb52545 commit d5423b1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/nsx/services/subnetport/subnetport.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -183,18 +182,18 @@ func (service *SubnetPortService) CheckSubnetPortState(obj interface{}, nsxSubne
}

func (service *SubnetPortService) GetSubnetPortState(obj interface{}, nsxSubnetPath string) (*model.SegmentPortState, error) {
var uid types.UID
var nsxSubnetPortID string
switch o := obj.(type) {
case *v1alpha1.SubnetPort:
uid = o.UID
nsxSubnetPortID = service.BuildSubnetPortId(&o.ObjectMeta)
case *v1.Pod:
uid = o.UID
nsxSubnetPortID = service.BuildSubnetPortId(&o.ObjectMeta)
}
nsxOrgID, nsxProjectID, nsxVPCID, nsxSubnetID := nsxutil.ParseVPCPath(nsxSubnetPath)
nsxSubnetPortState, err := service.NSXClient.PortStateClient.Get(nsxOrgID, nsxProjectID, nsxVPCID, nsxSubnetID, string(uid), nil, nil)
nsxSubnetPortState, err := service.NSXClient.PortStateClient.Get(nsxOrgID, nsxProjectID, nsxVPCID, nsxSubnetID, nsxSubnetPortID, nil, nil)
err = nsxutil.NSXApiError(err)
if err != nil {
log.Error(err, "failed to get subnet port state", "nsxSubnetPortID", uid, "nsxSubnetPath", nsxSubnetPath)
log.Error(err, "failed to get subnet port state", "nsxSubnetPortID", nsxSubnetPortID, "nsxSubnetPath", nsxSubnetPath)
return nil, err
}
return &nsxSubnetPortState, nil
Expand Down

0 comments on commit d5423b1

Please sign in to comment.