-
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.
Create management cluster using controller validation task (#7307)
- Loading branch information
1 parent
413ea04
commit 9d8959c
Showing
5 changed files
with
232 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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/workflows/interfaces" | ||
) | ||
|
||
// Create is a schema for create cluster. | ||
type Create struct { | ||
bootstrapper interfaces.Bootstrapper | ||
provider providers.Provider | ||
clusterManager interfaces.ClusterManager | ||
gitOpsManager interfaces.GitOpsManager | ||
writer filewriter.FileWriter | ||
eksdInstaller interfaces.EksdInstaller | ||
packageInstaller interfaces.PackageInstaller | ||
clusterCreator interfaces.ClusterCreator | ||
} | ||
|
||
// NewCreate builds a new create construct. | ||
func NewCreate(bootstrapper interfaces.Bootstrapper, provider providers.Provider, | ||
clusterManager interfaces.ClusterManager, gitOpsManager interfaces.GitOpsManager, | ||
writer filewriter.FileWriter, eksdInstaller interfaces.EksdInstaller, | ||
packageInstaller interfaces.PackageInstaller, | ||
clusterCreator interfaces.ClusterCreator, | ||
) *Create { | ||
return &Create{ | ||
bootstrapper: bootstrapper, | ||
provider: provider, | ||
clusterManager: clusterManager, | ||
gitOpsManager: gitOpsManager, | ||
writer: writer, | ||
eksdInstaller: eksdInstaller, | ||
packageInstaller: packageInstaller, | ||
clusterCreator: clusterCreator, | ||
} | ||
} | ||
|
||
// Run runs all the create management cluster tasks. | ||
func (c *Create) Run(ctx context.Context, clusterSpec *cluster.Spec, validator interfaces.Validator) error { | ||
commandContext := &task.CommandContext{ | ||
Bootstrapper: c.bootstrapper, | ||
Provider: c.provider, | ||
ClusterManager: c.clusterManager, | ||
GitOpsManager: c.gitOpsManager, | ||
ClusterSpec: clusterSpec, | ||
Writer: c.writer, | ||
Validations: validator, | ||
EksdInstaller: c.eksdInstaller, | ||
PackageInstaller: c.packageInstaller, | ||
ClusterCreator: c.clusterCreator, | ||
} | ||
|
||
return task.NewTaskRunner(&setupAndValidateCreate{}, 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,117 @@ | ||
package management_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
|
||
"github.com/aws/eks-anywhere/internal/test" | ||
"github.com/aws/eks-anywhere/pkg/api/v1alpha1" | ||
"github.com/aws/eks-anywhere/pkg/cluster" | ||
"github.com/aws/eks-anywhere/pkg/features" | ||
writermocks "github.com/aws/eks-anywhere/pkg/filewriter/mocks" | ||
"github.com/aws/eks-anywhere/pkg/providers" | ||
providermocks "github.com/aws/eks-anywhere/pkg/providers/mocks" | ||
"github.com/aws/eks-anywhere/pkg/types" | ||
"github.com/aws/eks-anywhere/pkg/workflows/interfaces/mocks" | ||
"github.com/aws/eks-anywhere/pkg/workflows/management" | ||
) | ||
|
||
type createTestSetup struct { | ||
t *testing.T | ||
packageInstaller *mocks.MockPackageInstaller | ||
clusterManager *mocks.MockClusterManager | ||
bootstrapper *mocks.MockBootstrapper | ||
gitOpsManager *mocks.MockGitOpsManager | ||
provider *providermocks.MockProvider | ||
writer *writermocks.MockFileWriter | ||
validator *mocks.MockValidator | ||
eksdInstaller *mocks.MockEksdInstaller | ||
clusterCreator *mocks.MockClusterCreator | ||
datacenterConfig providers.DatacenterConfig | ||
machineConfigs []providers.MachineConfig | ||
ctx context.Context | ||
clusterSpec *cluster.Spec | ||
bootstrapCluster *types.Cluster | ||
workloadCluster *types.Cluster | ||
workflow *management.Create | ||
} | ||
|
||
func newCreateTest(t *testing.T) *createTestSetup { | ||
featureEnvVars := []string{} | ||
featureEnvVars = append(featureEnvVars, features.UseControllerForCli) | ||
mockCtrl := gomock.NewController(t) | ||
bootstrapper := mocks.NewMockBootstrapper(mockCtrl) | ||
clusterManager := mocks.NewMockClusterManager(mockCtrl) | ||
gitOpsManager := mocks.NewMockGitOpsManager(mockCtrl) | ||
provider := providermocks.NewMockProvider(mockCtrl) | ||
writer := writermocks.NewMockFileWriter(mockCtrl) | ||
eksdInstaller := mocks.NewMockEksdInstaller(mockCtrl) | ||
packageInstaller := mocks.NewMockPackageInstaller(mockCtrl) | ||
|
||
datacenterConfig := &v1alpha1.VSphereDatacenterConfig{} | ||
machineConfigs := []providers.MachineConfig{&v1alpha1.VSphereMachineConfig{}} | ||
clusterCreator := mocks.NewMockClusterCreator(mockCtrl) | ||
validator := mocks.NewMockValidator(mockCtrl) | ||
|
||
workflow := management.NewCreate( | ||
bootstrapper, | ||
provider, | ||
clusterManager, | ||
gitOpsManager, | ||
writer, | ||
eksdInstaller, | ||
packageInstaller, | ||
clusterCreator, | ||
) | ||
|
||
for _, e := range featureEnvVars { | ||
t.Setenv(e, "true") | ||
} | ||
|
||
return &createTestSetup{ | ||
t: t, | ||
bootstrapper: bootstrapper, | ||
clusterManager: clusterManager, | ||
gitOpsManager: gitOpsManager, | ||
provider: provider, | ||
writer: writer, | ||
validator: validator, | ||
eksdInstaller: eksdInstaller, | ||
packageInstaller: packageInstaller, | ||
clusterCreator: clusterCreator, | ||
datacenterConfig: datacenterConfig, | ||
machineConfigs: machineConfigs, | ||
workflow: workflow, | ||
ctx: context.Background(), | ||
bootstrapCluster: &types.Cluster{Name: "bootstrap"}, | ||
workloadCluster: &types.Cluster{Name: "workload"}, | ||
clusterSpec: test.NewClusterSpec(func(s *cluster.Spec) { s.Cluster.Name = "cluster-name" }), | ||
} | ||
} | ||
|
||
func (c *createTestSetup) expectSetup() { | ||
c.provider.EXPECT().SetupAndValidateCreateCluster(c.ctx, c.clusterSpec) | ||
c.provider.EXPECT().Name() | ||
c.gitOpsManager.EXPECT().Validations(c.ctx, c.clusterSpec) | ||
} | ||
|
||
func (c *createTestSetup) run() error { | ||
return c.workflow.Run(c.ctx, c.clusterSpec, c.validator) | ||
} | ||
|
||
func (c *createTestSetup) expectPreflightValidationsToPass() { | ||
c.validator.EXPECT().PreflightValidations(c.ctx) | ||
} | ||
|
||
func TestCreateRunSuccess(t *testing.T) { | ||
test := newCreateTest(t) | ||
test.expectSetup() | ||
test.expectPreflightValidationsToPass() | ||
|
||
err := test.run() | ||
if err != nil { | ||
t.Fatalf("Create.Run() err = %v, want err = nil", 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
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