Skip to content

Commit

Permalink
Move CAPI resources task using controller behind feature flag (#7420)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude authored Jan 30, 2024
1 parent 6482f52 commit ea6ef64
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/workflows/management/create_install_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (s *installProviderSpecificResources) Run(ctx context.Context, commandConte
commandContext.SetError(err)
return &workflows.CollectDiagnosticsTask{}
}
return nil
return &moveClusterManagementTask{}
}

func (s *installProviderSpecificResources) Name() string {
Expand Down
35 changes: 35 additions & 0 deletions pkg/workflows/management/create_move_capi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package management

import (
"context"

"github.com/aws/eks-anywhere/pkg/logger"
"github.com/aws/eks-anywhere/pkg/task"
"github.com/aws/eks-anywhere/pkg/types"
"github.com/aws/eks-anywhere/pkg/workflows"
)

type moveClusterManagementTask struct{}

func (s *moveClusterManagementTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task {
logger.Info("Moving cluster management from bootstrap to workload cluster")
err := commandContext.ClusterManager.MoveCAPI(ctx, commandContext.BootstrapCluster, commandContext.WorkloadCluster, commandContext.WorkloadCluster.Name, commandContext.ClusterSpec, types.WithNodeRef())
if err != nil {
commandContext.SetError(err)
return &workflows.CollectDiagnosticsTask{}
}

return nil
}

func (s *moveClusterManagementTask) Name() string {
return "capi-management-move"
}

func (s *moveClusterManagementTask) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) {
return nil, nil
}

func (s *moveClusterManagementTask) Checkpoint() *task.CompletedTask {
return nil
}
28 changes: 28 additions & 0 deletions pkg/workflows/management/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ func (c *createTestSetup) expectInstallResourcesOnManagementTask(err error) {
)
}

func (c *createTestSetup) expectMoveManagement(err error) {
c.clusterManager.EXPECT().MoveCAPI(
c.ctx, c.bootstrapCluster, c.workloadCluster, c.workloadCluster.Name, c.clusterSpec, gomock.Any()).Return(err)
}

func TestCreateRunSuccess(t *testing.T) {
test := newCreateTest(t)
test.expectSetup()
Expand All @@ -207,6 +212,7 @@ func TestCreateRunSuccess(t *testing.T) {
test.expectInstallEksaComponentsBootstrap(nil, nil, nil, nil, nil, nil)
test.expectCreateWorkload(nil, nil, nil, nil)
test.expectInstallResourcesOnManagementTask(nil)
test.expectMoveManagement(nil)

err := test.run()
if err != nil {
Expand Down Expand Up @@ -587,3 +593,25 @@ func TestCreatePostWorkloadInitFailure(t *testing.T) {
t.Fatalf("Create.Run() expected to return an error %v", err)
}
}

func TestCreateMoveCAPIFailure(t *testing.T) {
c := newCreateTest(t)
c.expectSetup()
c.expectCreateBootstrap()
c.expectPreflightValidationsToPass()
c.expectCAPIInstall(nil, nil, nil)
c.expectInstallEksaComponentsBootstrap(nil, nil, nil, nil, nil, nil)
c.expectCreateWorkload(nil, nil, nil, nil)
c.expectInstallResourcesOnManagementTask(nil)
c.expectMoveManagement(errors.New("test"))

c.clusterManager.EXPECT().SaveLogsManagementCluster(c.ctx, c.clusterSpec, c.bootstrapCluster)
c.clusterManager.EXPECT().SaveLogsWorkloadCluster(c.ctx, c.provider, c.clusterSpec, c.workloadCluster)

c.writer.EXPECT().Write(fmt.Sprintf("%s-checkpoint.yaml", c.clusterSpec.Cluster.Name), gomock.Any())

err := c.run()
if err == nil {
t.Fatalf("Create.Run() expected to return an error %v", err)
}
}

0 comments on commit ea6ef64

Please sign in to comment.