-
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
11 changed files
with
320 additions
and
0 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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 | ||
clusterDeleter interfaces.ClusterDeleter | ||
gitopsManager interfaces.GitOpsManager | ||
} | ||
|
||
// NewDelete builds a new delete construct. | ||
func NewDelete(bootstrapper interfaces.Bootstrapper, | ||
provider providers.Provider, | ||
writer filewriter.FileWriter, | ||
clusterManager interfaces.ClusterManager, | ||
clusterDeleter interfaces.ClusterDeleter, | ||
gitopsManager interfaces.GitOpsManager, | ||
) *Delete { | ||
return &Delete{ | ||
bootstrapper: bootstrapper, | ||
provider: provider, | ||
writer: writer, | ||
clusterManager: clusterManager, | ||
clusterDeleter: clusterDeleter, | ||
gitopsManager: gitopsManager, | ||
} | ||
} | ||
|
||
// 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, | ||
ClusterDeleter: c.clusterDeleter, | ||
GitOpsManager: c.gitopsManager, | ||
} | ||
|
||
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,65 @@ | ||
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.ClusterDeleter.DeleteCAPICluster(ctx, commandContext.ClusterSpec.Cluster.Name, *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