@@ -97,29 +97,32 @@ func (cp *CloudProvider) extractNodeAddresses(ctx context.Context, instanceID st
9797 addresses = append (addresses , api.NodeAddress {Type : api .NodeExternalIP , Address : ip .String ()})
9898 }
9999
100- secondaryVnic , err := cp .client .Compute ().GetSecondaryVNICForInstance (ctx , compartmentID , instanceID )
101- if err != nil {
102- return nil , errors .Wrap (err , "GetSecondaryVNICForInstance" )
103- }
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+ }
104106
105- if secondaryVnic == nil {
106- return addresses , nil
107- }
107+ if secondaryVnic == nil {
108+ return addresses , nil
109+ }
108110
109- if (secondaryVnic .IsPrimary == nil || ! * secondaryVnic .IsPrimary ) && secondaryVnic .PrivateIp != nil && * secondaryVnic .PrivateIp != "" {
110- ip := net .ParseIP (* secondaryVnic .PrivateIp )
111- if ip == nil {
112- return nil , fmt .Errorf ("instance has invalid private address: %q" , * secondaryVnic .PrivateIp )
111+ if (secondaryVnic .IsPrimary == nil || ! * secondaryVnic .IsPrimary ) && secondaryVnic .PrivateIp != nil && * secondaryVnic .PrivateIp != "" {
112+ ip := net .ParseIP (* secondaryVnic .PrivateIp )
113+ if ip == nil {
114+ return nil , fmt .Errorf ("instance has invalid private address: %q" , * secondaryVnic .PrivateIp )
115+ }
116+ addresses = append (addresses , api.NodeAddress {Type : api .NodeInternalIP , Address : ip .String ()})
113117 }
114- addresses = append (addresses , api.NodeAddress {Type : api .NodeInternalIP , Address : ip .String ()})
115- }
116118
117- if (secondaryVnic .IsPrimary == nil || ! * secondaryVnic .IsPrimary ) && secondaryVnic .PublicIp != nil && * secondaryVnic .PublicIp != "" {
118- ip := net .ParseIP (* secondaryVnic .PublicIp )
119- if ip == nil {
120- return nil , errors .Errorf ("instance has invalid public address: %q" , * secondaryVnic .PublicIp )
119+ if (secondaryVnic .IsPrimary == nil || ! * secondaryVnic .IsPrimary ) && secondaryVnic .PublicIp != nil && * secondaryVnic .PublicIp != "" {
120+ ip := net .ParseIP (* secondaryVnic .PublicIp )
121+ if ip == nil {
122+ return nil , errors .Errorf ("instance has invalid public address: %q" , * secondaryVnic .PublicIp )
123+ }
124+ addresses = append (addresses , api.NodeAddress {Type : api .NodeExternalIP , Address : ip .String ()})
121125 }
122- addresses = append (addresses , api.NodeAddress {Type : api .NodeExternalIP , Address : ip .String ()})
123126 }
124127 // Changing this can have wide reaching impact.
125128 //
@@ -307,3 +310,35 @@ func (cp *CloudProvider) getCompartmentIDByNodeName(nodeName string) (string, er
307310 cp .logger .Debug ("CompartmentID annotation is not present" )
308311 return "" , errors .New ("compartmentID annotation missing in the node. Would retry" )
309312}
313+
314+ func (cp * CloudProvider ) checkOpenShiftNodesSecondaryVnicByInstance (instanceID string ) (bool , error ) {
315+ var SecondaryVnicUsageInstances = []string {"BM.Standard3.64" }
316+ nodeList , err := cp .NodeLister .List (labels .Everything ())
317+ if err != nil {
318+ return false , errors .Wrap (err , "error listing all the nodes using node informer" )
319+ }
320+ for _ , node := range nodeList {
321+ providerID , err := MapProviderIDToInstanceID (node .Spec .ProviderID )
322+ if err != nil {
323+ return false , errors .New ("Failed to map providerID to instanceID." )
324+ }
325+ if providerID == instanceID {
326+ if _ , ok := node .Labels [OpenShiftNodeIdentifierLabel ]; ok {
327+ if instanceType , ok := node .Labels [api .LabelInstanceTypeStable ]; ok && contains (SecondaryVnicUsageInstances , instanceType ) {
328+ return true , nil
329+ }
330+ }
331+ }
332+ }
333+ return false , errors .New ("Failed to check OpenShift node using node lables. Returning false" )
334+ }
335+
336+ // contains is a utility method to check if a string is part of a slice
337+ func contains (s []string , e string ) bool {
338+ for _ , a := range s {
339+ if a == e {
340+ return true
341+ }
342+ }
343+ return false
344+ }
0 commit comments