Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude committed Feb 15, 2024
1 parent 0c2a611 commit ca43e6c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
9 changes: 4 additions & 5 deletions pkg/awsiamauth/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions pkg/awsiamauth/installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Check failure on line 362 in pkg/awsiamauth/installer_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with -s standard,default,prefix(github.com/aws/eks-anywhere) (gci)
6 changes: 4 additions & 2 deletions pkg/clustermanager/cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Check failure on line 846 in pkg/clustermanager/cluster_manager.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 847 in pkg/clustermanager/cluster_manager.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with -s standard,default,prefix(github.com/aws/eks-anywhere) (gci)
return c.awsIamAuth.GenerateManagementAWSIAMKubeconfig(ctx, management)
}

func (c *ClusterManager) CreateAwsIamAuthCaSecret(ctx context.Context, managementCluster *types.Cluster, workloadClusterName string) error {
Expand Down

0 comments on commit ca43e6c

Please sign in to comment.