Skip to content

Commit 9ad4c4b

Browse files
committed
use tagging
1 parent d78fac9 commit 9ad4c4b

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

pkg/cloudprovider/providers/oci/instances.go

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020
"net"
21+
"strings"
2122

2223
"github.com/oracle/oci-go-sdk/v65/core"
2324
"k8s.io/apimachinery/pkg/labels"
@@ -97,17 +98,16 @@ func (cp *CloudProvider) extractNodeAddresses(ctx context.Context, instanceID st
9798
addresses = append(addresses, api.NodeAddress{Type: api.NodeExternalIP, Address: ip.String()})
9899
}
99100

100-
useSecondaryVnic, err := cp.checkOpenShiftNodesSecondaryVnicByInstance(instanceID)
101-
if useSecondaryVnic {
102-
secondaryVnic, err := cp.client.Compute().GetSecondaryVNICForInstance(ctx, compartmentID, instanceID)
103-
if err != nil {
104-
return nil, errors.Wrap(err, "GetSecondaryVNICForInstance")
105-
}
101+
secondaryVnic, err := cp.client.Compute().GetSecondaryVNICForInstance(ctx, compartmentID, instanceID)
102+
if err != nil {
103+
return nil, errors.Wrap(err, "GetSecondaryVNICForInstance")
104+
}
106105

107-
if secondaryVnic == nil {
108-
return addresses, nil
109-
}
106+
if secondaryVnic == nil {
107+
return addresses, nil
108+
}
110109

110+
if cp.checkOpenShiftISCSIBootVolumeByVnic(ctx, secondaryVnic) {
111111
if (secondaryVnic.IsPrimary == nil || !*secondaryVnic.IsPrimary) && secondaryVnic.PrivateIp != nil && *secondaryVnic.PrivateIp != "" {
112112
ip := net.ParseIP(*secondaryVnic.PrivateIp)
113113
if ip == nil {
@@ -340,24 +340,13 @@ func (cp *CloudProvider) getCompartmentIDByNodeName(nodeName string) (string, er
340340
return "", errors.New("compartmentID annotation missing in the node. Would retry")
341341
}
342342

343-
func (cp *CloudProvider) checkOpenShiftNodesSecondaryVnicByInstance(instanceID string) (bool, error) {
344-
var SecondaryVnicUsageInstances = []string{"BM.Standard3.64"}
345-
nodeList, err := cp.NodeLister.List(labels.Everything())
346-
if err != nil {
347-
return false, errors.Wrap(err, "error listing all the nodes using node informer")
348-
}
349-
for _, node := range nodeList {
350-
providerID, err := MapProviderIDToResourceID(node.Spec.ProviderID)
351-
if err != nil {
352-
return false, errors.New("Failed to map providerID to instanceID.")
353-
}
354-
if providerID == instanceID {
355-
if _, ok := node.Labels[OpenShiftNodeIdentifierLabel]; ok {
356-
if instanceType, ok := node.Labels[api.LabelInstanceTypeStable]; ok && contains(SecondaryVnicUsageInstances, instanceType) {
357-
return true, nil
358-
}
343+
func (cp *CloudProvider) checkOpenShiftISCSIBootVolumeByVnic(ctx context.Context, vnic *core.Vnic) bool {
344+
for namespace := range vnic.DefinedTags {
345+
if strings.HasPrefix(namespace, "openshift") {
346+
if bootVolume, exist := vnic.DefinedTags[namespace]["boot-volume-type"]; exist && bootVolume == "ISCSI" {
347+
return true
359348
}
360349
}
361350
}
362-
return false, errors.New("Failed to check OpenShift node using node lables. Returning false")
351+
return false
363352
}

0 commit comments

Comments
 (0)