Skip to content

Commit

Permalink
improve tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
yutpeng committed Aug 8, 2024
1 parent c4ae168 commit 3fae048
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
31 changes: 16 additions & 15 deletions pkg/cloudprovider/providers/oci/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,31 @@ func (cp *CloudProvider) extractNodeAddresses(ctx context.Context, instanceID st
OpenShiftTagNamesapce := cp.getOpenShiftTagNamespaceByInstance(ctx, instanceID)

if OpenShiftTagNamesapce != "" {
secondaryVnic, err := cp.client.Compute().GetSecondaryVNICForInstance(ctx, compartmentID, instanceID)
secondaryVnics, err := cp.client.Compute().GetSecondaryVNICsForInstance(ctx, compartmentID, instanceID)
if err != nil {
return nil, err
}

if secondaryVnic == nil {
if secondaryVnics == nil || len(secondaryVnics) == 0 {
return addresses, nil
}

if cp.checkOpenShiftISCSIBootVolumeTagByVnic(ctx, secondaryVnic, OpenShiftTagNamesapce) {
if (secondaryVnic.IsPrimary == nil || !*secondaryVnic.IsPrimary) && secondaryVnic.PrivateIp != nil && *secondaryVnic.PrivateIp != "" {
ip := net.ParseIP(*secondaryVnic.PrivateIp)
if ip == nil {
return nil, fmt.Errorf("instance has invalid private address: %q", *secondaryVnic.PrivateIp)
for _, secondaryVnic := range secondaryVnics {
if cp.checkOpenShiftISCSIBootVolumeTagByVnic(ctx, secondaryVnic, OpenShiftTagNamesapce) {
if (secondaryVnic.IsPrimary == nil || !*secondaryVnic.IsPrimary) && secondaryVnic.PrivateIp != nil && *secondaryVnic.PrivateIp != "" {
ip := net.ParseIP(*secondaryVnic.PrivateIp)
if ip == nil {
return nil, fmt.Errorf("instance has invalid private address: %q", *secondaryVnic.PrivateIp)
}
addresses = append(addresses, api.NodeAddress{Type: api.NodeInternalIP, Address: ip.String()})
}
addresses = append(addresses, api.NodeAddress{Type: api.NodeInternalIP, Address: ip.String()})
}

if (secondaryVnic.IsPrimary == nil || !*secondaryVnic.IsPrimary) && secondaryVnic.PublicIp != nil && *secondaryVnic.PublicIp != "" {
ip := net.ParseIP(*secondaryVnic.PublicIp)
if ip == nil {
return nil, errors.Errorf("instance has invalid public address: %q", *secondaryVnic.PublicIp)
if (secondaryVnic.IsPrimary == nil || !*secondaryVnic.IsPrimary) && secondaryVnic.PublicIp != nil && *secondaryVnic.PublicIp != "" {
ip := net.ParseIP(*secondaryVnic.PublicIp)
if ip == nil {
return nil, errors.Errorf("instance has invalid public address: %q", *secondaryVnic.PublicIp)
}
addresses = append(addresses, api.NodeAddress{Type: api.NodeExternalIP, Address: ip.String()})
}
addresses = append(addresses, api.NodeAddress{Type: api.NodeExternalIP, Address: ip.String()})
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/providers/oci/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ func (MockComputeClient) GetPrimaryVNICForInstance(ctx context.Context, compartm
return instanceVnics[instanceID], nil
}

func (c *MockComputeClient) GetSecondaryVNICForInstance(ctx context.Context, compartmentID, instanceID string) (*core.Vnic, error) {
return instanceVnics[instanceID], nil
func (c *MockComputeClient) GetSecondaryVNICsForInstance(ctx context.Context, compartmentID, instanceID string) ([]*core.Vnic, error) {
return []*core.Vnic{instanceVnics[instanceID]}, nil
}

func (MockComputeClient) FindVolumeAttachment(ctx context.Context, compartmentID, volumeID string) (core.VolumeAttachment, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi/driver/bv_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func (c *MockComputeClient) GetPrimaryVNICForInstance(ctx context.Context, compa
return nil, nil
}

func (c *MockComputeClient) GetSecondaryVNICForInstance(ctx context.Context, compartmentID, instanceID string) (*core.Vnic, error) {
func (c *MockComputeClient) GetSecondaryVNICsForInstance(ctx context.Context, compartmentID, instanceID string) ([]*core.Vnic, error) {
return nil, nil
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/oci/client/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ComputeInterface interface {

GetPrimaryVNICForInstance(ctx context.Context, compartmentID, instanceID string) (*core.Vnic, error)

GetSecondaryVNICForInstance(ctx context.Context, compartmentID, instanceID string) (*core.Vnic, error)
GetSecondaryVNICsForInstance(ctx context.Context, compartmentID, instanceID string) ([]*core.Vnic, error)

VolumeAttachmentInterface
}
Expand Down Expand Up @@ -185,9 +185,9 @@ func (c *client) GetPrimaryVNICForInstance(ctx context.Context, compartmentID, i
return nil, errors.WithStack(errNotFound)
}

func (c *client) GetSecondaryVNICForInstance(ctx context.Context, compartmentID, instanceID string) (*core.Vnic, error) {
func (c *client) GetSecondaryVNICsForInstance(ctx context.Context, compartmentID, instanceID string) ([]*core.Vnic, error) {
logger := c.logger.With("instanceID", instanceID, "compartmentID", compartmentID)

secondaryVnics := []*core.Vnic{}
var page *string
for {
resp, err := c.listVNICAttachments(ctx, core.ListVnicAttachmentsRequest{
Expand Down Expand Up @@ -222,7 +222,7 @@ func (c *client) GetSecondaryVNICForInstance(ctx context.Context, compartmentID,
}

if !*vnic.IsPrimary {
return vnic, nil
secondaryVnics = append(secondaryVnics, vnic)
}
}

Expand All @@ -231,7 +231,7 @@ func (c *client) GetSecondaryVNICForInstance(ctx context.Context, compartmentID,
}
}

return nil, nil
return secondaryVnics, nil
}

func (c *client) GetInstanceByNodeName(ctx context.Context, compartmentID, vcnID, nodeName string) (*core.Instance, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/provisioner/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (c *MockComputeClient) GetPrimaryVNICForInstance(ctx context.Context, compa
return nil, nil
}

func (c *MockComputeClient) GetSecondaryVNICForInstance(ctx context.Context, compartmentID, instanceID string) (*core.Vnic, error) {
func (c *MockComputeClient) GetSecondaryVNICsForInstance(ctx context.Context, compartmentID, instanceID string) ([]*core.Vnic, error) {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/volume/provisioner/fss/fss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (c *MockComputeClient) GetPrimaryVNICForInstance(ctx context.Context, compa
return nil, nil
}

func (c *MockComputeClient) GetSecondaryVNICForInstance(ctx context.Context, compartmentID, instanceID string) (*core.Vnic, error) {
func (c *MockComputeClient) GetSecondaryVNICsForInstance(ctx context.Context, compartmentID, instanceID string) ([]*core.Vnic, error) {
return nil, nil
}

Expand Down

0 comments on commit 3fae048

Please sign in to comment.