-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
913 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package management | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/eks-anywhere/pkg/cluster" | ||
"github.com/aws/eks-anywhere/pkg/filewriter" | ||
"github.com/aws/eks-anywhere/pkg/providers" | ||
"github.com/aws/eks-anywhere/pkg/task" | ||
"github.com/aws/eks-anywhere/pkg/types" | ||
"github.com/aws/eks-anywhere/pkg/workflows/interfaces" | ||
) | ||
|
||
// Delete is the workflow that deletes a workload clusters. | ||
type Delete struct { | ||
bootstrapper interfaces.Bootstrapper | ||
provider providers.Provider | ||
writer filewriter.FileWriter | ||
clusterManager interfaces.ClusterManager | ||
gitopsManager interfaces.GitOpsManager | ||
clusterDeleter interfaces.ClusterDeleter | ||
eksdInstaller interfaces.EksdInstaller | ||
eksaInstaller interfaces.EksaInstaller | ||
clientFactory interfaces.ClientFactory | ||
} | ||
|
||
// NewDelete builds a new delete construct. | ||
func NewDelete(bootstrapper interfaces.Bootstrapper, | ||
provider providers.Provider, | ||
writer filewriter.FileWriter, | ||
clusterManager interfaces.ClusterManager, | ||
gitopsManager interfaces.GitOpsManager, | ||
clusterDeleter interfaces.ClusterDeleter, | ||
eksdInstaller interfaces.EksdInstaller, | ||
eksaInstaller interfaces.EksaInstaller, | ||
clientFactory interfaces.ClientFactory, | ||
) *Delete { | ||
return &Delete{ | ||
bootstrapper: bootstrapper, | ||
provider: provider, | ||
writer: writer, | ||
clusterManager: clusterManager, | ||
gitopsManager: gitopsManager, | ||
clusterDeleter: clusterDeleter, | ||
eksdInstaller: eksdInstaller, | ||
eksaInstaller: eksaInstaller, | ||
clientFactory: clientFactory, | ||
} | ||
} | ||
|
||
// Run executes the tasks to delete a management cluster. | ||
func (c *Delete) Run(ctx context.Context, workload *types.Cluster, clusterSpec *cluster.Spec) error { | ||
commandContext := &task.CommandContext{ | ||
Bootstrapper: c.bootstrapper, | ||
Provider: c.provider, | ||
Writer: c.writer, | ||
ClusterManager: c.clusterManager, | ||
ClusterSpec: clusterSpec, | ||
WorkloadCluster: workload, | ||
GitOpsManager: c.gitopsManager, | ||
ClusterDeleter: c.clusterDeleter, | ||
EksdInstaller: c.eksdInstaller, | ||
EksaInstaller: c.eksaInstaller, | ||
ClientFactory: c.clientFactory, | ||
} | ||
|
||
return task.NewTaskRunner(&setupAndValidateDelete{}, c.writer).RunTask(ctx, commandContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package management | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/eks-anywhere/pkg/constants" | ||
"github.com/aws/eks-anywhere/pkg/logger" | ||
"github.com/aws/eks-anywhere/pkg/task" | ||
"github.com/aws/eks-anywhere/pkg/workflows" | ||
) | ||
|
||
type deleteBootstrapClusterForDeleteTask struct{} | ||
|
||
func (s *deleteBootstrapClusterForDeleteTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { | ||
logger.Info("Deleting bootstrap cluster") | ||
if err := commandContext.Bootstrapper.DeleteBootstrapCluster(ctx, commandContext.BootstrapCluster, constants.Delete, false); err != nil { | ||
commandContext.SetError(err) | ||
} | ||
|
||
if commandContext.OriginalError != nil { | ||
return &workflows.CollectMgmtClusterDiagnosticsTask{} | ||
} | ||
|
||
logger.MarkSuccess("Cluster deleted!") | ||
return nil | ||
} | ||
|
||
func (s *deleteBootstrapClusterForDeleteTask) Name() string { | ||
return "kind-cluster-delete" | ||
} | ||
|
||
func (s *deleteBootstrapClusterForDeleteTask) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) { | ||
return nil, nil | ||
} | ||
|
||
func (s *deleteBootstrapClusterForDeleteTask) Checkpoint() *task.CompletedTask { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package management | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/eks-anywhere/pkg/logger" | ||
"github.com/aws/eks-anywhere/pkg/task" | ||
"github.com/aws/eks-anywhere/pkg/workflows" | ||
) | ||
|
||
type deleteManagementCluster struct{} | ||
|
||
func (s *deleteManagementCluster) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { | ||
logger.Info("Deleting management cluster") | ||
|
||
err := commandContext.ClusterManager.ResumeEKSAControllerReconcile(ctx, commandContext.BootstrapCluster, commandContext.ClusterSpec, commandContext.Provider) | ||
if err != nil { | ||
commandContext.SetError(err) | ||
return &workflows.CollectMgmtClusterDiagnosticsTask{} | ||
} | ||
|
||
err = commandContext.ClusterManager.AddManagedByCLIAnnotationForCluster(ctx, commandContext.BootstrapCluster, commandContext.ClusterSpec, commandContext.Provider) | ||
if err != nil { | ||
commandContext.SetError(err) | ||
return &workflows.CollectMgmtClusterDiagnosticsTask{} | ||
} | ||
|
||
err = commandContext.ClusterDeleter.Run(ctx, commandContext.ClusterSpec, *commandContext.BootstrapCluster) | ||
if err != nil { | ||
commandContext.SetError(err) | ||
return &workflows.CollectMgmtClusterDiagnosticsTask{} | ||
} | ||
|
||
err = commandContext.Provider.PostClusterDeleteValidate(ctx, commandContext.BootstrapCluster) | ||
if err != nil { | ||
commandContext.SetError(err) | ||
return &workflows.CollectMgmtClusterDiagnosticsTask{} | ||
} | ||
|
||
return &cleanupGitRepo{} | ||
} | ||
|
||
func (s *deleteManagementCluster) Name() string { | ||
return "delete-management-cluster" | ||
} | ||
|
||
func (s *deleteManagementCluster) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) { | ||
return nil, nil | ||
} | ||
|
||
func (s *deleteManagementCluster) Checkpoint() *task.CompletedTask { | ||
return nil | ||
} | ||
|
||
type cleanupGitRepo struct{} | ||
|
||
func (s *cleanupGitRepo) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { | ||
logger.Info("Clean up Git Repo") | ||
err := commandContext.GitOpsManager.CleanupGitRepo(ctx, commandContext.ClusterSpec) | ||
if err != nil { | ||
commandContext.SetError(err) | ||
return &workflows.CollectDiagnosticsTask{} | ||
} | ||
|
||
return &deleteBootstrapClusterForDeleteTask{} | ||
} | ||
|
||
func (s *cleanupGitRepo) Name() string { | ||
return "clean-up-git-repo" | ||
} | ||
|
||
func (s *cleanupGitRepo) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) { | ||
return nil, nil | ||
} | ||
|
||
func (s *cleanupGitRepo) Checkpoint() *task.CompletedTask { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package management | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/eks-anywhere/pkg/logger" | ||
"github.com/aws/eks-anywhere/pkg/task" | ||
) | ||
|
||
type createBootStrapClusterForDeleteTask struct{} | ||
|
||
func (s *createBootStrapClusterForDeleteTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { | ||
logger.Info("Creating new bootstrap cluster") | ||
|
||
bootstrapOptions, err := commandContext.Provider.BootstrapClusterOpts(commandContext.ClusterSpec) | ||
if err != nil { | ||
commandContext.SetError(err) | ||
return nil | ||
} | ||
|
||
bootstrapCluster, err := commandContext.Bootstrapper.CreateBootstrapCluster(ctx, commandContext.ClusterSpec, bootstrapOptions...) | ||
if err != nil { | ||
commandContext.SetError(err) | ||
return nil | ||
} | ||
commandContext.BootstrapCluster = bootstrapCluster | ||
|
||
return &installCAPIComponentsForDeleteTask{} | ||
} | ||
|
||
func (s *createBootStrapClusterForDeleteTask) Name() string { | ||
return "bootstrap-cluster-for-delete-init" | ||
} | ||
|
||
func (s *createBootStrapClusterForDeleteTask) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) { | ||
return nil, nil | ||
} | ||
|
||
func (s *createBootStrapClusterForDeleteTask) Checkpoint() *task.CompletedTask { | ||
return nil | ||
} |
Oops, something went wrong.