From 2a211c0c8c610cb3a0bed34f65dc60c4aedf602f Mon Sep 17 00:00:00 2001 From: Martin Linkhorst Date: Tue, 17 Sep 2024 17:15:25 +0200 Subject: [PATCH] se unique cluster alias as identifier rather than redundant eksID Signed-off-by: Martin Linkhorst --- provisioner/aws.go | 2 +- provisioner/template.go | 6 ------ provisioner/template_test.go | 9 --------- provisioner/zalando_eks.go | 4 ++-- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/provisioner/aws.go b/provisioner/aws.go index 841605a4..605f4df3 100644 --- a/provisioner/aws.go +++ b/provisioner/aws.go @@ -777,7 +777,7 @@ type EKSClusterDetails struct { func (a *awsAdapter) GetEKSClusterDetails(cluster *api.Cluster) (*EKSClusterDetails, error) { resp, err := a.eksClient.DescribeCluster(&eks.DescribeClusterInput{ - Name: aws.String(eksID(cluster.ID)), + Name: aws.String(cluster.Alias), }) if err != nil { return nil, err diff --git a/provisioner/template.go b/provisioner/template.go index 727bce12..f5512fe7 100644 --- a/provisioner/template.go +++ b/provisioner/template.go @@ -95,7 +95,6 @@ func renderTemplate(context *templateContext, file string) (string, error) { "azID": azID, "azCount": azCount, "split": split, - "eksID": eksID, "mountUnitName": mountUnitName, "accountID": accountID, "portRanges": portRanges, @@ -281,11 +280,6 @@ func list(args ...interface{}) []interface{} { return args } -func eksID(id string) string { - parts := strings.Split(id, ":") - return parts[len(parts)-1] -} - // accountID returns just the ID part of an account func accountID(account string) (string, error) { items := strings.Split(account, ":") diff --git a/provisioner/template_test.go b/provisioner/template_test.go index f7d5fc74..46b0d637 100644 --- a/provisioner/template_test.go +++ b/provisioner/template_test.go @@ -278,15 +278,6 @@ func TestAccountIDFailsOnInvalid(t *testing.T) { require.Error(t, err) } -func TestEKSID(t *testing.T) { - result, err := renderSingle( - t, - `{{ eksID "aws:000000:eu-north-1:kube-1" }}`, - "") - require.NoError(t, err) - require.EqualValues(t, "kube-1", result) -} - func TestParsePortRanges(t *testing.T) { testTemplate := `{{- if index .Values.data.portRanges -}} {{- range $index, $element := portRanges .Values.data.portRanges -}} diff --git a/provisioner/zalando_eks.go b/provisioner/zalando_eks.go index da6df613..2a6c906d 100644 --- a/provisioner/zalando_eks.go +++ b/provisioner/zalando_eks.go @@ -82,7 +82,7 @@ func (z *ZalandoEKSProvisioner) Provision( return fmt.Errorf("failed to setup AWS Adapter: %v", err) } - eksTokenSource := eks.NewTokenSource(awsAdapter.session, eksID(cluster.ID)) + eksTokenSource := eks.NewTokenSource(awsAdapter.session, cluster.Alias) logger.Infof( "clusterpy: Prepare for provisioning EKS cluster %s (%s)..", @@ -127,7 +127,7 @@ func (z *ZalandoEKSProvisioner) Decommission( } cluster.APIServerURL = cluster.ConfigItems[KeyEKSEndpoint] - tokenSource := eks.NewTokenSource(awsAdapter.session, eksID(cluster.ID)) + tokenSource := eks.NewTokenSource(awsAdapter.session, cluster.Alias) return z.decommission( ctx,