Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,26 @@ type AwsInstanceRef struct {
Name string
}

var validAwsRefIdRegex = regexp.MustCompile(fmt.Sprintf(`^aws\:\/\/\/[-0-9a-z]*\/[-0-9a-z]*(\/[-0-9a-z\.]*)?$|aws\:\/\/\/[-0-9a-z]*\/%s.*$`, placeholderInstanceNamePrefix))
var validAwsRefIdRegex = regexp.MustCompile(fmt.Sprintf(`^aws\:\/\/\/[-0-9a-z]*\/(%s.*)$|aws\:\/\/\/[-0-9a-z]*\/([-0-9a-z]*)(\/[-0-9a-z\.]*)?$`, placeholderInstanceNamePrefix))

// AwsRefFromProviderId creates AwsInstanceRef object from provider id which
// must be in format: aws:///zone/name
func AwsRefFromProviderId(id string) (*AwsInstanceRef, error) {
if validAwsRefIdRegex.FindStringSubmatch(id) == nil {
matches := validAwsRefIdRegex.FindStringSubmatch(id)
if matches == nil || len(matches) != 4 {
return nil, fmt.Errorf("wrong id: expected format aws:///<zone>/<name>, got %v", id)
}
splitted := strings.Split(id[7:], "/")

var name string
if strings.Contains(id, placeholderInstanceNamePrefix) {
name = matches[1]
} else {
name = matches[2]
}

return &AwsInstanceRef{
ProviderID: id,
Name: splitted[1],
Name: name,
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ func TestAwsRefFromProviderId(t *testing.T) {
ProviderID: "aws:///eu-central-1c/i-placeholder-K3-EKS-spotr5xlasgsubnet02af43b02922e710f-10QH9H0C8PG7O-14",
},
},
{
// ref: https://github.com/kubernetes/autoscaler/issues/8305
provID: "aws:///us-east-1a/i-placeholder-some/arbitrary/cluster/local",
expErr: false,
expRef: &AwsInstanceRef{
Name: "i-placeholder-some/arbitrary/cluster/local",
ProviderID: "aws:///us-east-1a/i-placeholder-some/arbitrary/cluster/local",
},
},
}

for _, test := range tests {
Expand Down
Loading