From ca43e6c7baa41c85b639b40716610c31f6296917 Mon Sep 17 00:00:00 2001 From: Mitali Paygude Date: Wed, 14 Feb 2024 17:44:19 -0800 Subject: [PATCH] m --- pkg/awsiamauth/installer.go | 9 +++---- pkg/awsiamauth/installer_test.go | 37 +++++++++++++++++++++++++++ pkg/clustermanager/cluster_manager.go | 6 +++-- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/pkg/awsiamauth/installer.go b/pkg/awsiamauth/installer.go index 5ee5261bad95f..e6441f1691267 100644 --- a/pkg/awsiamauth/installer.go +++ b/pkg/awsiamauth/installer.go @@ -159,15 +159,14 @@ func (i *Installer) GenerateKubeconfig( // GenerateManagementAWSIAMKubeconfig generates the AWS IAM auth kubeconfig. func (i *Installer) GenerateManagementAWSIAMKubeconfig( ctx context.Context, - management, workload *types.Cluster, - spec *cluster.Spec, + cluster *types.Cluster, ) error { - fileName := fmt.Sprintf("%s-aws.kubeconfig", workload.Name) + fileName := fmt.Sprintf("%s-aws.kubeconfig", cluster.Name) decodedKubeconfigSecretValue, err := i.k8s.GetAWSIAMKubeconfigSecretValue( ctx, - management, - workload.Name, + cluster, + cluster.Name, ) if err != nil { return fmt.Errorf("generating aws-iam-authenticator kubeconfig: %v", err) diff --git a/pkg/awsiamauth/installer_test.go b/pkg/awsiamauth/installer_test.go index 7a0a1f1060c45..6f2bcd168cbbb 100644 --- a/pkg/awsiamauth/installer_test.go +++ b/pkg/awsiamauth/installer_test.go @@ -323,3 +323,40 @@ func TestUpgradeAWSIAMAuth(t *testing.T) { } test.AssertContentToFile(t, string(manifest), "testdata/UpgradeAWSIAMAuth-manifest.yaml") } + +func TestGenerateManagementAWSIAMKubeconfig(t *testing.T) { + ctrl := gomock.NewController(t) + certs := cryptomocks.NewMockCertificateGenerator(ctrl) + clusterID := uuid.MustParse("36db102f-9e1e-4ca4-8300-271d30b14161") + + k8s := NewMockKubernetesClient(ctrl) + k8s.EXPECT().GetAWSIAMKubeconfigSecretValue(gomock.Any(), gomock.Any(), gomock.Any()).Return([]byte("kubeconfig"), nil) + + writer := filewritermock.NewMockFileWriter(ctrl) + writer.EXPECT().Write(gomock.Any(), gomock.Any(), gomock.Any()).Return("kubeconfig", nil) + + installer := awsiamauth.NewInstaller(certs, clusterID, k8s, writer) + + err := installer.GenerateManagementAWSIAMKubeconfig(context.Background(), &types.Cluster{}) + if err != nil { + t.Fatal(err) + } +} + +func TestGenerateManagementAWSIAMKubeconfigError(t *testing.T) { + ctrl := gomock.NewController(t) + certs := cryptomocks.NewMockCertificateGenerator(ctrl) + clusterID := uuid.MustParse("36db102f-9e1e-4ca4-8300-271d30b14161") + + k8s := NewMockKubernetesClient(ctrl) + k8s.EXPECT().GetAWSIAMKubeconfigSecretValue(gomock.Any(), gomock.Any(), gomock.Any()).Return([]byte{}, errors.New("test")) + + writer := filewritermock.NewMockFileWriter(ctrl) + + installer := awsiamauth.NewInstaller(certs, clusterID, k8s, writer) + + err := installer.GenerateManagementAWSIAMKubeconfig(context.Background(), &types.Cluster{}) + if err == nil { + t.Fatal(err) + } +} \ No newline at end of file diff --git a/pkg/clustermanager/cluster_manager.go b/pkg/clustermanager/cluster_manager.go index 03a862ddee9e4..abf2b645f41c0 100644 --- a/pkg/clustermanager/cluster_manager.go +++ b/pkg/clustermanager/cluster_manager.go @@ -123,7 +123,7 @@ type AwsIamAuth interface { InstallAWSIAMAuth(ctx context.Context, management, workload *types.Cluster, spec *cluster.Spec) error UpgradeAWSIAMAuth(ctx context.Context, cluster *types.Cluster, spec *cluster.Spec) error GenerateKubeconfig(ctx context.Context, management, workload *types.Cluster, spec *cluster.Spec) error - GenerateManagementAWSIAMKubeconfig(ctx context.Context, management, workload *types.Cluster, spec *cluster.Spec) error + GenerateManagementAWSIAMKubeconfig(ctx context.Context, cluster *types.Cluster) error } // EKSAComponents allows to manage the eks-a components installation in a cluster. @@ -843,7 +843,9 @@ func (c *ClusterManager) InstallAwsIamAuth(ctx context.Context, management, work // GenerateAWSIAMKubeconfig generates a kubeconfig for interacting with the cluster with aws-iam-authenticator client. func (c *ClusterManager) GenerateAWSIAMKubeconfig(ctx context.Context, management, workload *types.Cluster, spec *cluster.Spec) error { - return c.awsIamAuth.GenerateManagementAWSIAMKubeconfig(ctx, management, workload, spec) + + + return c.awsIamAuth.GenerateManagementAWSIAMKubeconfig(ctx, management) } func (c *ClusterManager) CreateAwsIamAuthCaSecret(ctx context.Context, managementCluster *types.Cluster, workloadClusterName string) error {