Skip to content

Commit

Permalink
Create namespace if specified (#7575)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude authored Feb 14, 2024
1 parent d08ab96 commit bf6c916
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
8 changes: 5 additions & 3 deletions pkg/workflows/management/create_install_eksa.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ func (s *installEksaComponentsOnWorkloadTask) Run(ctx context.Context, commandCo
commandContext.ClusterSpec.Cluster.AddManagedByCLIAnnotation()
commandContext.ClusterSpec.Cluster.SetManagementComponentsVersion(commandContext.ClusterSpec.EKSARelease.Spec.Version)

if err := commandContext.ClusterManager.CreateNamespace(ctx, commandContext.WorkloadCluster, commandContext.ClusterSpec.Cluster.Namespace); err != nil {
commandContext.SetError(err)
return &workflows.CollectMgmtClusterDiagnosticsTask{}
if commandContext.ClusterSpec.Cluster.Namespace != "" {
if err := commandContext.ClusterManager.CreateNamespace(ctx, commandContext.WorkloadCluster, commandContext.ClusterSpec.Cluster.Namespace); err != nil {
commandContext.SetError(err)
return &workflows.CollectMgmtClusterDiagnosticsTask{}
}
}

logger.Info("Applying cluster spec to workload cluster")
Expand Down
39 changes: 22 additions & 17 deletions pkg/workflows/management/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,31 @@ func newCreateTest(t *testing.T) *createTestSetup {
t.Setenv(e, "true")
}

clusterSpec := test.NewClusterSpec(func(s *cluster.Spec) { s.Cluster.Name = "test-cluster" })
clusterSpec := test.NewClusterSpec(func(s *cluster.Spec) {
s.Cluster.Name = "test-cluster"
s.Cluster.Namespace = "test-ns"
})
managementComponents := cluster.ManagementComponentsFromBundles(clusterSpec.Bundles)

return &createTestSetup{
t: t,
bootstrapper: bootstrapper,
clusterManager: clusterManager,
gitOpsManager: gitOpsManager,
provider: provider,
writer: writer,
validator: validator,
eksdInstaller: eksdInstaller,
eksaInstaller: eksaInstaller,
packageInstaller: packageInstaller,
clusterCreator: clusterCreator,
datacenterConfig: datacenterConfig,
machineConfigs: machineConfigs,
workflow: workflow,
ctx: context.Background(),
bootstrapCluster: &types.Cluster{Name: "test-cluster"},
t: t,
bootstrapper: bootstrapper,
clusterManager: clusterManager,
gitOpsManager: gitOpsManager,
provider: provider,
writer: writer,
validator: validator,
eksdInstaller: eksdInstaller,
eksaInstaller: eksaInstaller,
packageInstaller: packageInstaller,
clusterCreator: clusterCreator,
datacenterConfig: datacenterConfig,
machineConfigs: machineConfigs,
workflow: workflow,
ctx: context.Background(),
bootstrapCluster: &types.Cluster{
Name: "test-cluster",
},
workloadCluster: &types.Cluster{},
managementComponents: managementComponents,
clusterSpec: clusterSpec,
Expand Down
8 changes: 5 additions & 3 deletions pkg/workflows/management/create_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ func (s *createWorkloadClusterTask) Run(ctx context.Context, commandContext *tas
commandContext.ClusterSpec.Cluster.AddManagedByCLIAnnotation()
commandContext.ClusterSpec.Cluster.SetManagementComponentsVersion(commandContext.ClusterSpec.EKSARelease.Spec.Version)

if err := commandContext.ClusterManager.CreateNamespace(ctx, commandContext.BootstrapCluster, commandContext.ClusterSpec.Cluster.Namespace); err != nil {
commandContext.SetError(err)
return &workflows.CollectMgmtClusterDiagnosticsTask{}
if commandContext.ClusterSpec.Cluster.Namespace != "" {
if err := commandContext.ClusterManager.CreateNamespace(ctx, commandContext.BootstrapCluster, commandContext.ClusterSpec.Cluster.Namespace); err != nil {
commandContext.SetError(err)
return &workflows.CollectMgmtClusterDiagnosticsTask{}
}
}

workloadCluster, err := commandContext.ClusterCreator.CreateSync(ctx, commandContext.ClusterSpec, commandContext.BootstrapCluster)
Expand Down
5 changes: 4 additions & 1 deletion pkg/workflows/workload/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func newCreateTest(t *testing.T) *createTestSetup {

validator := mocks.NewMockValidator(mockCtrl)

clusterSpec := test.NewClusterSpec(func(s *cluster.Spec) { s.Cluster.Name = "test-cluster" })
clusterSpec := test.NewClusterSpec(func(s *cluster.Spec) {
s.Cluster.Name = "test-cluster"
})
managementComponents := cluster.ManagementComponentsFromBundles(clusterSpec.Bundles)

workload := workload.NewCreate(
Expand Down Expand Up @@ -90,6 +92,7 @@ func newCreateTest(t *testing.T) *createTestSetup {
clusterCreator: clusterUpgrader,
clusterSpec: test.NewClusterSpec(func(s *cluster.Spec) {
s.Cluster.Name = "workload"
s.Cluster.Namespace = "test-ns"
s.Cluster.Spec.DatacenterRef.Kind = v1alpha1.VSphereDatacenterKind
s.ManagementCluster = &types.Cluster{Name: "management"}
}),
Expand Down
8 changes: 5 additions & 3 deletions pkg/workflows/workload/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ type createCluster struct{}
func (c *createCluster) Run(ctx context.Context, commandContext *task.CommandContext) task.Task {
logger.Info("Creating workload cluster")

if err := commandContext.ClusterManager.CreateNamespace(ctx, commandContext.ManagementCluster, commandContext.ClusterSpec.Cluster.Namespace); err != nil {
commandContext.SetError(err)
return &workflows.CollectMgmtClusterDiagnosticsTask{}
if commandContext.ClusterSpec.Cluster.Namespace != "" {
if err := commandContext.ClusterManager.CreateNamespace(ctx, commandContext.ManagementCluster, commandContext.ClusterSpec.Cluster.Namespace); err != nil {
commandContext.SetError(err)
return &workflows.CollectMgmtClusterDiagnosticsTask{}
}
}

workloadCluster, err := commandContext.ClusterCreator.CreateSync(ctx, commandContext.ClusterSpec, commandContext.ManagementCluster)
Expand Down

0 comments on commit bf6c916

Please sign in to comment.