From 296f9dc77fd10c375f17551260d1c82a1afe8bf1 Mon Sep 17 00:00:00 2001 From: Mitali Paygude Date: Wed, 14 Feb 2024 18:37:55 -0800 Subject: [PATCH] m --- pkg/clustermanager/cluster_manager.go | 4 ++-- pkg/workflows/interfaces/interfaces.go | 2 +- pkg/workflows/interfaces/mocks/clients.go | 8 +++---- pkg/workflows/management/create_test.go | 23 +++++++++++++++++++++ pkg/workflows/management/create_workload.go | 2 +- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/pkg/clustermanager/cluster_manager.go b/pkg/clustermanager/cluster_manager.go index 10fb3659e2701..15bd462a055c2 100644 --- a/pkg/clustermanager/cluster_manager.go +++ b/pkg/clustermanager/cluster_manager.go @@ -842,8 +842,8 @@ 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) +func (c *ClusterManager) GenerateAWSIAMKubeconfig(ctx context.Context, cluster *types.Cluster) error { + return c.awsIamAuth.GenerateManagementAWSIAMKubeconfig(ctx, cluster) } func (c *ClusterManager) CreateAwsIamAuthCaSecret(ctx context.Context, managementCluster *types.Cluster, workloadClusterName string) error { diff --git a/pkg/workflows/interfaces/interfaces.go b/pkg/workflows/interfaces/interfaces.go index 31c6f88b2c5f0..87469494a8ac8 100644 --- a/pkg/workflows/interfaces/interfaces.go +++ b/pkg/workflows/interfaces/interfaces.go @@ -54,7 +54,7 @@ type ClusterManager interface { Upgrade(ctx context.Context, cluster *types.Cluster, currentManagementComponents, newManagementComponents *cluster.ManagementComponents, newSpec *cluster.Spec) (*types.ChangeDiff, error) InstallAwsIamAuth(ctx context.Context, managementCluster, workloadCluster *types.Cluster, clusterSpec *cluster.Spec) error CreateAwsIamAuthCaSecret(ctx context.Context, bootstrapCluster *types.Cluster, workloadClusterName string) error - GenerateAWSIAMKubeconfig(ctx context.Context, management, workload *types.Cluster, spec *cluster.Spec) error + GenerateAWSIAMKubeconfig(ctx context.Context, cluster *types.Cluster) error DeletePackageResources(ctx context.Context, managementCluster *types.Cluster, clusterName string) error CreateRegistryCredSecret(ctx context.Context, mgmt *types.Cluster) error CreateNamespace(ctx context.Context, targetCluster *types.Cluster, namespace string) error diff --git a/pkg/workflows/interfaces/mocks/clients.go b/pkg/workflows/interfaces/mocks/clients.go index 9dd336fdff89b..d9329ef401e9a 100644 --- a/pkg/workflows/interfaces/mocks/clients.go +++ b/pkg/workflows/interfaces/mocks/clients.go @@ -284,17 +284,17 @@ func (mr *MockClusterManagerMockRecorder) EKSAClusterSpecChanged(arg0, arg1, arg } // GenerateAWSIAMKubeconfig mocks base method. -func (m *MockClusterManager) GenerateAWSIAMKubeconfig(arg0 context.Context, arg1, arg2 *types.Cluster, arg3 *cluster.Spec) error { +func (m *MockClusterManager) GenerateAWSIAMKubeconfig(arg0 context.Context, arg1 *types.Cluster) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GenerateAWSIAMKubeconfig", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "GenerateAWSIAMKubeconfig", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } // GenerateAWSIAMKubeconfig indicates an expected call of GenerateAWSIAMKubeconfig. -func (mr *MockClusterManagerMockRecorder) GenerateAWSIAMKubeconfig(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockClusterManagerMockRecorder) GenerateAWSIAMKubeconfig(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateAWSIAMKubeconfig", reflect.TypeOf((*MockClusterManager)(nil).GenerateAWSIAMKubeconfig), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GenerateAWSIAMKubeconfig", reflect.TypeOf((*MockClusterManager)(nil).GenerateAWSIAMKubeconfig), arg0, arg1) } // GetCurrentClusterSpec mocks base method. diff --git a/pkg/workflows/management/create_test.go b/pkg/workflows/management/create_test.go index fe85f20220ab9..15d6534bdcaae 100644 --- a/pkg/workflows/management/create_test.go +++ b/pkg/workflows/management/create_test.go @@ -532,6 +532,29 @@ func TestCreateSyncFailure(t *testing.T) { } } +func TestCreateAWSIAMFailure(t *testing.T) { + test := newCreateTest(t) + test.expectSetup() + test.expectPreflightValidationsToPass() + test.expectCreateBootstrap() + test.expectCAPIInstall(nil, nil, nil) + test.expectInstallEksaComponentsBootstrap(nil, nil, nil, nil) + test.clusterSpec.AWSIamConfig = &v1alpha1.AWSIamConfig{} + + test.clusterManager.EXPECT().CreateNamespace(test.ctx, test.bootstrapCluster, test.clusterSpec.Cluster.Namespace).Return(nil) + test.clusterCreator.EXPECT().CreateSync(test.ctx, test.clusterSpec, test.bootstrapCluster).Return(test.workloadCluster, nil) + test.clusterManager.EXPECT().GenerateAWSIAMKubeconfig(test.ctx, test.workloadCluster).Return(errors.New("test")) + + test.clusterManager.EXPECT().SaveLogsManagementCluster(test.ctx, test.clusterSpec, test.bootstrapCluster) + test.clusterManager.EXPECT().SaveLogsWorkloadCluster(test.ctx, test.provider, test.clusterSpec, test.workloadCluster) + test.writer.EXPECT().Write(fmt.Sprintf("%s-checkpoint.yaml", test.clusterSpec.Cluster.Name), gomock.Any()) + + err := test.run() + if err == nil { + t.Fatalf("Create.Run() expected to return an error %v", err) + } +} + func TestCreateEKSANamespaceFailure(t *testing.T) { test := newCreateTest(t) test.expectSetup() diff --git a/pkg/workflows/management/create_workload.go b/pkg/workflows/management/create_workload.go index 22325db182aaf..298e38258305c 100644 --- a/pkg/workflows/management/create_workload.go +++ b/pkg/workflows/management/create_workload.go @@ -34,7 +34,7 @@ func (s *createWorkloadClusterTask) Run(ctx context.Context, commandContext *tas if commandContext.ClusterSpec.AWSIamConfig != nil { logger.Info("Generating the aws iam kubeconfig file") - err = commandContext.ClusterManager.GenerateAWSIAMKubeconfig(ctx, commandContext.BootstrapCluster, workloadCluster, commandContext.ClusterSpec) + err = commandContext.ClusterManager.GenerateAWSIAMKubeconfig(ctx, commandContext.WorkloadCluster) if err != nil { commandContext.SetError(err) return &workflows.CollectDiagnosticsTask{}