Skip to content

Commit

Permalink
Log the cluster spec while cluster creation (#7621)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude authored Feb 16, 2024
1 parent e6dd03c commit 918d417
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 39 deletions.
10 changes: 10 additions & 0 deletions pkg/workflows/management/create_install_eksa.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/clustermarshaller"
"github.com/aws/eks-anywhere/pkg/logger"
"github.com/aws/eks-anywhere/pkg/task"
"github.com/aws/eks-anywhere/pkg/types"
Expand Down Expand Up @@ -70,6 +71,15 @@ func (s *installEksaComponentsOnWorkloadTask) Run(ctx context.Context, commandCo
return &workflows.CollectMgmtClusterDiagnosticsTask{}
}

datacenterConfig := commandContext.Provider.DatacenterConfig(commandContext.ClusterSpec)
machineConfigs := commandContext.Provider.MachineConfigs(commandContext.ClusterSpec)

resourcesSpec, err := clustermarshaller.MarshalClusterSpec(commandContext.ClusterSpec, datacenterConfig, machineConfigs)
if err != nil {
commandContext.SetError(err)
}
logger.V(6).Info(string(resourcesSpec))

return &installGitOpsManagerTask{}
}

Expand Down
69 changes: 30 additions & 39 deletions pkg/workflows/management/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,29 +238,13 @@ func (c *createTestSetup) expectInstallEksaComponentsWorkload(err1, err2, err3 e
}

func (c *createTestSetup) expectInstallGitOpsManager() {
gomock.InOrder(
c.provider.EXPECT().DatacenterConfig(
c.clusterSpec).Return(c.datacenterConfig),

c.provider.EXPECT().MachineConfigs(
c.clusterSpec).Return(c.machineConfigs),

c.gitOpsManager.EXPECT().InstallGitOps(
c.ctx, c.workloadCluster, c.managementComponents, c.clusterSpec, c.datacenterConfig, c.machineConfigs),
)
c.gitOpsManager.EXPECT().InstallGitOps(
c.ctx, c.workloadCluster, c.managementComponents, c.clusterSpec, c.datacenterConfig, c.machineConfigs)
}

func (c *createTestSetup) expectWriteClusterConfig() {
gomock.InOrder(
c.provider.EXPECT().DatacenterConfig(
c.clusterSpec).Return(c.datacenterConfig),

c.provider.EXPECT().MachineConfigs(
c.clusterSpec).Return(c.machineConfigs),

c.writer.EXPECT().Write(
"test-cluster-eks-a-cluster.yaml", gomock.Any(), gomock.Any()),
)
c.writer.EXPECT().Write(
"test-cluster-eks-a-cluster.yaml", gomock.Any(), gomock.Any())
}

func (c *createTestSetup) expectCreateNamespace() {
Expand All @@ -284,6 +268,18 @@ func (c *createTestSetup) expectCuratedPackagesInstallation() {
c.packageInstaller.EXPECT().InstallCuratedPackages(c.ctx).Times(1)
}

func (c *createTestSetup) expectDatacenterConfig() {
gomock.InOrder(
c.provider.EXPECT().DatacenterConfig(c.clusterSpec).Return(c.datacenterConfig).AnyTimes(),
)
}

func (c *createTestSetup) expectMachineConfigs() {
gomock.InOrder(
c.provider.EXPECT().MachineConfigs(c.clusterSpec).Return(c.machineConfigs).AnyTimes(),
)
}

func TestCreateRunSuccess(t *testing.T) {
test := newCreateTest(t)
test.expectSetup()
Expand All @@ -301,6 +297,8 @@ func TestCreateRunSuccess(t *testing.T) {
test.expectDeleteBootstrap(nil)
test.expectCuratedPackagesInstallation()
test.expectCreateNamespace()
test.expectDatacenterConfig()
test.expectMachineConfigs()

err := test.run()
if err != nil {
Expand Down Expand Up @@ -800,17 +798,12 @@ func TestCreateGitOPsFailure(t *testing.T) {
test.expectMoveManagement(nil)
test.expectInstallEksaComponentsWorkload(nil, nil, nil)
test.expectCreateNamespace()
test.expectDatacenterConfig()
test.expectMachineConfigs()

gomock.InOrder(
test.provider.EXPECT().DatacenterConfig(
test.clusterSpec).Return(test.datacenterConfig),

test.provider.EXPECT().MachineConfigs(
test.clusterSpec).Return(test.machineConfigs),
test.gitOpsManager.EXPECT().InstallGitOps(
test.ctx, test.workloadCluster, test.managementComponents, test.clusterSpec, test.datacenterConfig, test.machineConfigs).Return(errors.New("test"))

test.gitOpsManager.EXPECT().InstallGitOps(
test.ctx, test.workloadCluster, test.managementComponents, test.clusterSpec, test.datacenterConfig, test.machineConfigs).Return(errors.New("test")),
)
test.expectWriteClusterConfig()
test.expectDeleteBootstrap(nil)
test.expectCuratedPackagesInstallation()
Expand All @@ -836,17 +829,11 @@ func TestCreateWriteConfigFailure(t *testing.T) {
test.expectInstallGitOpsManager()
test.expectPreflightValidationsToPass()
test.expectCreateNamespace()
test.expectDatacenterConfig()
test.expectMachineConfigs()

gomock.InOrder(
test.provider.EXPECT().DatacenterConfig(
test.clusterSpec).Return(test.datacenterConfig),

test.provider.EXPECT().MachineConfigs(
test.clusterSpec).Return(test.machineConfigs),

test.writer.EXPECT().Write(
"test-cluster-eks-a-cluster.yaml", gomock.Any(), gomock.Any()).Return("", errors.New("test")),
)
test.writer.EXPECT().Write(
"test-cluster-eks-a-cluster.yaml", gomock.Any(), gomock.Any()).Return("", errors.New("test"))

test.clusterManager.EXPECT().SaveLogsManagementCluster(
test.ctx, test.clusterSpec, test.bootstrapCluster,
Expand Down Expand Up @@ -879,6 +866,8 @@ func TestCreateWriteConfigAWSIAMFailure(t *testing.T) {
test.clusterSpec.AWSIamConfig = &v1alpha1.AWSIamConfig{}
test.expectWriteClusterConfig()
test.expectCreateNamespace()
test.expectDatacenterConfig()
test.expectMachineConfigs()

test.clusterManager.EXPECT().GenerateAWSIAMKubeconfig(test.ctx, test.workloadCluster).Return(errors.New("test"))

Expand Down Expand Up @@ -913,6 +902,8 @@ func TestCreateRunDeleteBootstrapFailure(t *testing.T) {
test.expectDeleteBootstrap(fmt.Errorf("test"))
test.expectCuratedPackagesInstallation()
test.expectCreateNamespace()
test.expectDatacenterConfig()
test.expectMachineConfigs()

test.writer.EXPECT().Write("test-cluster-checkpoint.yaml", gomock.Any(), gomock.Any())

Expand Down
10 changes: 10 additions & 0 deletions pkg/workflows/workload/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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"
"github.com/aws/eks-anywhere/pkg/workflows"
Expand All @@ -28,6 +29,15 @@ func (c *createCluster) Run(ctx context.Context, commandContext *task.CommandCon
}
commandContext.WorkloadCluster = workloadCluster

datacenterConfig := commandContext.Provider.DatacenterConfig(commandContext.ClusterSpec)
machineConfigs := commandContext.Provider.MachineConfigs(commandContext.ClusterSpec)

resourcesSpec, err := clustermarshaller.MarshalClusterSpec(commandContext.ClusterSpec, datacenterConfig, machineConfigs)
if err != nil {
commandContext.SetError(err)
}
logger.V(6).Info(string(resourcesSpec))

return &installGitOpsManagerTask{}
}

Expand Down

0 comments on commit 918d417

Please sign in to comment.