Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause eksa cluster before moving capi for delete #7650

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/dependencies/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion pkg/workflows/management/delete_move_capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
47 changes: 35 additions & 12 deletions pkg/workflows/management/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +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().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) {
Expand Down Expand Up @@ -218,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)
Expand Down Expand Up @@ -308,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")
Expand All @@ -317,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()

Expand All @@ -336,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()
Expand All @@ -355,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()
Expand All @@ -375,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()
Expand All @@ -395,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()
Expand All @@ -415,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()
Expand All @@ -435,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)
Expand All @@ -457,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)
Expand All @@ -481,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()
Expand Down
Loading