From 6714aaccdcdd293eb800f78e0970e8ea31b2b9ed Mon Sep 17 00:00:00 2001 From: Tanvir Tatla Date: Tue, 20 Feb 2024 11:41:39 -0800 Subject: [PATCH 1/2] Pause eksa cluster before moving capi for delete --- pkg/dependencies/factory.go | 2 +- pkg/workflows/management/delete_move_capi.go | 8 +++++++- pkg/workflows/management/delete_test.go | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/dependencies/factory.go b/pkg/dependencies/factory.go index 10bcca81609e..5300d280989c 100644 --- a/pkg/dependencies/factory.go +++ b/pkg/dependencies/factory.go @@ -1288,7 +1288,7 @@ func (f *Factory) WithClusterDeleter() *Factory { f.buildSteps = append(f.buildSteps, func(ctx context.Context) error { var opts []clustermanager.DeleterOpt if f.config.noTimeouts { - opts = append(opts, clustermanager.WithDeleterNoTimeouts()) + opts = append(opts, clustermanager.WithDeleterApplyClusterTimeout(time.Hour)) } f.dependencies.ClusterDeleter = clustermanager.NewDeleter( diff --git a/pkg/workflows/management/delete_move_capi.go b/pkg/workflows/management/delete_move_capi.go index 3cbe166952e8..d34a224dd6a9 100644 --- a/pkg/workflows/management/delete_move_capi.go +++ b/pkg/workflows/management/delete_move_capi.go @@ -12,8 +12,14 @@ import ( type moveClusterManagementForDeleteTask struct{} func (s *moveClusterManagementForDeleteTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { + err := commandContext.ClusterManager.PauseEKSAControllerReconcile(ctx, commandContext.WorkloadCluster, commandContext.ClusterSpec, commandContext.Provider) + if err != nil { + commandContext.SetError(err) + return &workflows.CollectDiagnosticsTask{} + } + logger.Info("Moving cluster management from workload cluster to bootstrap") - err := commandContext.ClusterManager.MoveCAPI(ctx, commandContext.WorkloadCluster, commandContext.BootstrapCluster, commandContext.WorkloadCluster.Name, commandContext.ClusterSpec, types.WithNodeRef()) + err = commandContext.ClusterManager.MoveCAPI(ctx, commandContext.WorkloadCluster, commandContext.BootstrapCluster, commandContext.WorkloadCluster.Name, commandContext.ClusterSpec, types.WithNodeRef()) if err != nil { commandContext.SetError(err) return &workflows.CollectDiagnosticsTask{} diff --git a/pkg/workflows/management/delete_test.go b/pkg/workflows/management/delete_test.go index 0c6f1963ada0..5776f82e6ccf 100644 --- a/pkg/workflows/management/delete_test.go +++ b/pkg/workflows/management/delete_test.go @@ -159,6 +159,7 @@ func (c *deleteTestSetup) expectInstallCAPI(err error) { } func (c *deleteTestSetup) expectMoveCAPI(err error) { + c.clusterManager.EXPECT().PauseEKSAControllerReconcile(c.ctx, c.workloadCluster, c.clusterSpec, c.provider) c.clusterManager.EXPECT().MoveCAPI(c.ctx, c.workloadCluster, c.bootstrapCluster, c.workloadCluster.Name, c.clusterSpec, gomock.Any()).Return(err) } From 55182fd217313ce9564826e0e6517681a0a5da81 Mon Sep 17 00:00:00 2001 From: Tanvir Tatla Date: Tue, 20 Feb 2024 11:53:28 -0800 Subject: [PATCH 2/2] add test for pause eksa --- pkg/workflows/management/delete_test.go | 48 ++++++++++++++++++------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/pkg/workflows/management/delete_test.go b/pkg/workflows/management/delete_test.go index 5776f82e6ccf..a3ceee4d9356 100644 --- a/pkg/workflows/management/delete_test.go +++ b/pkg/workflows/management/delete_test.go @@ -158,9 +158,12 @@ func (c *deleteTestSetup) expectInstallCAPI(err error) { c.clusterManager.EXPECT().InstallCAPI(c.ctx, gomock.Any(), c.clusterSpec, c.bootstrapCluster, c.provider).Return(err) } -func (c *deleteTestSetup) expectMoveCAPI(err error) { - c.clusterManager.EXPECT().PauseEKSAControllerReconcile(c.ctx, c.workloadCluster, c.clusterSpec, c.provider) - c.clusterManager.EXPECT().MoveCAPI(c.ctx, c.workloadCluster, c.bootstrapCluster, c.workloadCluster.Name, c.clusterSpec, gomock.Any()).Return(err) +func (c *deleteTestSetup) expectMoveCAPI(err1, err2 error) { + c.clusterManager.EXPECT().PauseEKSAControllerReconcile(c.ctx, c.workloadCluster, c.clusterSpec, c.provider).Return(err1) + if err1 != nil { + return + } + c.clusterManager.EXPECT().MoveCAPI(c.ctx, c.workloadCluster, c.bootstrapCluster, c.workloadCluster.Name, c.clusterSpec, gomock.Any()).Return(err2) } func (c *deleteTestSetup) expectInstallEksaComponentsBootstrap(err1, err2, err3, err4, err5 error) { @@ -219,7 +222,7 @@ func TestDeleteRunSuccess(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(nil) + test.expectMoveCAPI(nil, nil) test.expectInstallEksaComponentsBootstrap(nil, nil, nil, nil, nil) test.expectApplyOnBootstrap(nil) test.expectDeleteCluster(nil, nil, nil, nil) @@ -309,6 +312,25 @@ func TestDeleteRunFailInstallCAPI(t *testing.T) { } } +func TestDeleteRunFailPauseEksa(t *testing.T) { + features.ClearCache() + os.Setenv(features.UseControllerForCli, "true") + test := newDeleteTest(t) + test.expectSetup(nil) + test.expectBootstrapOpts(nil) + test.expectCreateBootstrap(nil) + test.expectPreCAPI(nil) + test.expectInstallCAPI(nil) + test.expectMoveCAPI(fmt.Errorf(""), nil) + test.expectSaveLogsWorkload() + test.expectSaveLogsManagement() + + err := test.run() + if err == nil { + t.Fatalf("Delete.Run() err = %v, want err = nil", err) + } +} + func TestDeleteRunFailMoveCAPI(t *testing.T) { features.ClearCache() os.Setenv(features.UseControllerForCli, "true") @@ -318,7 +340,7 @@ func TestDeleteRunFailMoveCAPI(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(fmt.Errorf("")) + test.expectMoveCAPI(nil, fmt.Errorf("")) test.expectSaveLogsWorkload() test.expectSaveLogsManagement() @@ -337,7 +359,7 @@ func TestDeleteRunFailResumeReconcile(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(nil) + test.expectMoveCAPI(nil, nil) test.expectInstallEksaComponentsBootstrap(fmt.Errorf(""), nil, nil, nil, nil) test.expectSaveLogsManagement() test.expectSaveLogsWorkload() @@ -356,7 +378,7 @@ func TestDeleteRunFailAddAnnotation(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(nil) + test.expectMoveCAPI(nil, nil) test.expectInstallEksaComponentsBootstrap(nil, fmt.Errorf(""), nil, nil, nil) test.expectSaveLogsManagement() test.expectSaveLogsWorkload() @@ -376,7 +398,7 @@ func TestDeleteRunFailProviderInstall(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(nil) + test.expectMoveCAPI(nil, nil) test.expectInstallEksaComponentsBootstrap(nil, nil, fmt.Errorf(""), nil, nil) test.expectSaveLogsManagement() test.expectSaveLogsWorkload() @@ -396,7 +418,7 @@ func TestDeleteRunFailEksdInstall(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(nil) + test.expectMoveCAPI(nil, nil) test.expectInstallEksaComponentsBootstrap(nil, nil, nil, fmt.Errorf(""), nil) test.expectSaveLogsManagement() test.expectSaveLogsWorkload() @@ -416,7 +438,7 @@ func TestDeleteRunFailBuildClient(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(nil) + test.expectMoveCAPI(nil, nil) test.expectInstallEksaComponentsBootstrap(nil, nil, nil, nil, fmt.Errorf("")) test.expectSaveLogsManagement() test.expectSaveLogsWorkload() @@ -436,7 +458,7 @@ func TestDeleteRunFailPostDelete(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(nil) + test.expectMoveCAPI(nil, nil) test.expectInstallEksaComponentsBootstrap(nil, nil, nil, nil, nil) test.expectCreateNamespace() test.expectApplyOnBootstrap(nil) @@ -458,7 +480,7 @@ func TestDeleteRunFailCleanupGit(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(nil) + test.expectMoveCAPI(nil, nil) test.expectInstallEksaComponentsBootstrap(nil, nil, nil, nil, nil) test.expectCreateNamespace() test.expectApplyOnBootstrap(nil) @@ -482,7 +504,7 @@ func TestDeleteRunFailDeleteBootstrap(t *testing.T) { test.expectCreateBootstrap(nil) test.expectPreCAPI(nil) test.expectInstallCAPI(nil) - test.expectMoveCAPI(nil) + test.expectMoveCAPI(nil, nil) test.expectInstallEksaComponentsBootstrap(nil, nil, nil, nil, nil) test.expectApplyOnBootstrap(nil) test.expectCreateNamespace()