Skip to content

Commit 332ac2c

Browse files
committed
fix(clusterapi): HasInstance with namespace prefix
1 parent 4f1c8e6 commit 332ac2c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cluster-autoscaler/cloudprovider/clusterapi/clusterapi_provider.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package clusterapi
1818

1919
import (
2020
"fmt"
21+
"path"
2122
"reflect"
2223

2324
corev1 "k8s.io/api/core/v1"
@@ -86,8 +87,9 @@ func (p *provider) NodeGroupForNode(node *corev1.Node) (cloudprovider.NodeGroup,
8687
// HasInstance returns whether a given node has a corresponding instance in this cloud provider
8788
func (p *provider) HasInstance(node *corev1.Node) (bool, error) {
8889
machineID := node.Annotations[machineAnnotationKey]
90+
ns := node.Annotations[clusterNamespaceAnnotationKey]
8991

90-
machine, err := p.controller.findMachine(machineID)
92+
machine, err := p.controller.findMachine(path.Join(ns, machineID))
9193
if machine != nil {
9294
return true, nil
9395
}

cluster-autoscaler/cloudprovider/clusterapi/clusterapi_utils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ var (
9090
// by the CAPI_GROUP env variable, it is initialized here.
9191
machineAnnotationKey = getMachineAnnotationKey()
9292

93+
// clusterNamespaceAnnotationKey is the annotation used by cluster-api for annotating nodes
94+
// with their cluster namespace.
95+
clusterNamespaceAnnotationKey = getClusterNamespaceAnnotationKey()
96+
9397
// nodeGroupMinSizeAnnotationKey and nodeGroupMaxSizeAnnotationKey are the keys
9498
// used in MachineSet and MachineDeployment annotations to specify the limits
9599
// for the node group. Because the keys can be affected by the CAPI_GROUP env
@@ -308,6 +312,13 @@ func getMachineAnnotationKey() string {
308312
return key
309313
}
310314

315+
// getClusterNamespaceAnnotationKey returns the key that is used by cluster-api for annotating nodes
316+
// with their cluster namespace.
317+
func getClusterNamespaceAnnotationKey() string {
318+
key := fmt.Sprintf("%s/cluster-namespace", getCAPIGroup())
319+
return key
320+
}
321+
311322
// getClusterNameLabel returns the key that is used by cluster-api for labeling
312323
// which cluster an object belongs to. This function is needed because the user can change
313324
// the default group name by using the CAPI_GROUP environment variable.

0 commit comments

Comments
 (0)