-
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
1 parent
9f866a2
commit 6ba7d33
Showing
12 changed files
with
224 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ docs/.hugo_build.lock | |
*.log | ||
pkg/executables/TestDeployTemplate* | ||
pkg/files/config | ||
*.yaml |
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
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,61 @@ | ||
package workload | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/eks-anywhere/pkg/cluster" | ||
"github.com/aws/eks-anywhere/pkg/filewriter" | ||
"github.com/aws/eks-anywhere/pkg/logger" | ||
"github.com/aws/eks-anywhere/pkg/providers" | ||
"github.com/aws/eks-anywhere/pkg/task" | ||
"github.com/aws/eks-anywhere/pkg/workflows/interfaces" | ||
) | ||
|
||
// CreateWorkload is a schema for create cluster. | ||
type CreateWorkload struct { | ||
provider providers.Provider | ||
clusterManager interfaces.ClusterManager | ||
gitOpsManager interfaces.GitOpsManager | ||
writer filewriter.FileWriter | ||
eksdInstaller interfaces.EksdInstaller | ||
clusterApplier interfaces.ClusterApplier | ||
packageInstaller interfaces.PackageInstaller | ||
} | ||
|
||
// NewCreateWorkload builds a new create construct. | ||
func NewCreateWorkload(provider providers.Provider, | ||
clusterManager interfaces.ClusterManager, gitOpsManager interfaces.GitOpsManager, | ||
writer filewriter.FileWriter, | ||
clusterCreate interfaces.ClusterApplier, | ||
eksdInstaller interfaces.EksdInstaller, | ||
packageInstaller interfaces.PackageInstaller, | ||
) *CreateWorkload { | ||
return &CreateWorkload{ | ||
provider: provider, | ||
clusterManager: clusterManager, | ||
gitOpsManager: gitOpsManager, | ||
writer: writer, | ||
eksdInstaller: eksdInstaller, | ||
clusterApplier: clusterCreate, | ||
packageInstaller: packageInstaller, | ||
} | ||
} | ||
|
||
// Run Create implements create functionality for workload cluster's create operation. | ||
func (c *CreateWorkload) Run(ctx context.Context, clusterSpec *cluster.Spec, validator interfaces.Validator) error { | ||
logger.Info("POC New workflow creating workload cluster using the controller") | ||
commandContext := &task.CommandContext{ | ||
Provider: c.provider, | ||
ClusterManager: c.clusterManager, | ||
GitOpsManager: c.gitOpsManager, | ||
ClusterSpec: clusterSpec, | ||
Writer: c.writer, | ||
Validations: validator, | ||
ManagementCluster: clusterSpec.ManagementCluster, | ||
ClusterApplier: c.clusterApplier, | ||
} | ||
|
||
err := task.NewTaskRunner(&setAndValidateWorkloadTask{}, c.writer).RunTask(ctx, commandContext) | ||
|
||
return err | ||
} |
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,83 @@ | ||
package workload | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/eks-anywhere/pkg/logger" | ||
"github.com/aws/eks-anywhere/pkg/task" | ||
"github.com/aws/eks-anywhere/pkg/validations" | ||
"github.com/aws/eks-anywhere/pkg/workflows" | ||
) | ||
|
||
// task related entities | ||
|
||
type setAndValidateWorkloadTask struct{} | ||
|
||
// SetAndValidateTask implementation | ||
|
||
// Run createCluster performs actions needed to create the workload cluster. | ||
func (s *setAndValidateWorkloadTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { | ||
logger.Info("POC Performing setup and validations") | ||
runner := validations.NewRunner() | ||
runner.Register(s.providerValidation(ctx, commandContext)...) | ||
runner.Register(commandContext.GitOpsManager.Validations(ctx, commandContext.ClusterSpec)...) | ||
runner.Register(commandContext.Validations.PreflightValidations(ctx)...) | ||
|
||
err := runner.Run() | ||
if err != nil { | ||
commandContext.SetError(err) | ||
return nil | ||
} | ||
return &createCluster{} | ||
} | ||
|
||
func (s *setAndValidateWorkloadTask) providerValidation(ctx context.Context, commandContext *task.CommandContext) []validations.Validation { | ||
return []validations.Validation{ | ||
func() *validations.ValidationResult { | ||
return &validations.ValidationResult{ | ||
Name: fmt.Sprintf("POC workload cluster's %s Provider setup is valid", commandContext.Provider.Name()), | ||
Err: commandContext.Provider.SetupAndValidateCreateCluster(ctx, commandContext.ClusterSpec), | ||
} | ||
}, | ||
} | ||
} | ||
|
||
func (s *setAndValidateWorkloadTask) Name() string { | ||
return "setup-validate" | ||
} | ||
|
||
func (s *setAndValidateWorkloadTask) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) { | ||
return nil, nil | ||
} | ||
|
||
func (s *setAndValidateWorkloadTask) Checkpoint() *task.CompletedTask { | ||
return nil | ||
} | ||
|
||
type createCluster struct{} | ||
|
||
// Run createCluster performs actions needed to create the management cluster. | ||
func (s *createCluster) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { | ||
logger.Info("Creating workload cluster") | ||
if err := commandContext.ClusterApplier.Run(ctx, commandContext.ClusterSpec, *commandContext.ManagementCluster); err != nil { | ||
commandContext.SetError(err) | ||
return &workflows.CollectMgmtClusterDiagnosticsTask{} | ||
} | ||
|
||
return &writeClusterConfig{} | ||
} | ||
|
||
func (s *createCluster) Name() string { | ||
return "create-workload-cluster" | ||
} | ||
|
||
func (s *createCluster) Checkpoint() *task.CompletedTask { | ||
return &task.CompletedTask{ | ||
Checkpoint: nil, | ||
} | ||
} | ||
|
||
func (s *createCluster) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) { | ||
return &writeClusterConfig{}, 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,39 @@ | ||
package workload | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/eks-anywhere/pkg/clustermarshaller" | ||
"github.com/aws/eks-anywhere/pkg/logger" | ||
"github.com/aws/eks-anywhere/pkg/task" | ||
) | ||
|
||
type writeClusterConfig struct{} | ||
|
||
// Run writeClusterConfig writes new management cluster's cluster config file to the destination after the create process. | ||
func (s *writeClusterConfig) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { | ||
logger.Info("Writing cluster config file") | ||
err := clustermarshaller.WriteClusterConfig(commandContext.ClusterSpec, commandContext.Provider.DatacenterConfig(commandContext.ClusterSpec), commandContext.Provider.MachineConfigs(commandContext.ClusterSpec), commandContext.Writer) | ||
if err != nil { | ||
commandContext.SetError(err) | ||
} | ||
|
||
if commandContext.OriginalError == nil { | ||
logger.MarkSuccess("Cluster created!") | ||
} | ||
return nil | ||
} | ||
|
||
func (s *writeClusterConfig) Name() string { | ||
return "write-cluster-config" | ||
} | ||
|
||
func (s *writeClusterConfig) Checkpoint() *task.CompletedTask { | ||
return &task.CompletedTask{ | ||
Checkpoint: nil, | ||
} | ||
} | ||
|
||
func (s *writeClusterConfig) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) { | ||
return nil, nil | ||
} |