Skip to content

Commit d17351e

Browse files
committed
Match instance by IPs
1 parent c2b5bee commit d17351e

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

serverscom/instances.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (i *instances) InstanceID(ctx context.Context, nodeName types.NodeName) (st
108108
}
109109

110110
for _, instance := range cloudInstances {
111-
if instance.Name == string(nodeName) {
111+
if instance.Name == string(nodeName) || anyMatch(string(nodeName), instance.PrivateIPv4Address, instance.PublicIPv4Address) {
112112
return buildExternalID(cloudInstanceType, instance.ID), nil
113113
}
114114
}
@@ -123,7 +123,7 @@ func (i *instances) InstanceID(ctx context.Context, nodeName types.NodeName) (st
123123
}
124124

125125
for _, host := range hosts {
126-
if host.Title == string(nodeName) {
126+
if host.Title == string(nodeName) || anyMatch(string(nodeName), host.PrivateIPv4Address, host.PublicIPv4Address) {
127127
switch host.Type {
128128
case "dedicated_server":
129129
return buildExternalID(dedicatedServerType, host.ID), nil

serverscom/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,17 @@ func getLoadBalancerName(srv *v1.Service, clusterName string) string {
120120
}
121121
return fmt.Sprintf("service-%s-%s", clusterName, ret)
122122
}
123+
124+
func anyMatch(str string, matches ...*string) bool {
125+
for _, m := range matches {
126+
if m == nil {
127+
continue
128+
}
129+
130+
if *m == str {
131+
return true
132+
}
133+
}
134+
135+
return false
136+
}

0 commit comments

Comments
 (0)