From 918d4178eda0f59efbd6774adbd7dbbe94609127 Mon Sep 17 00:00:00 2001 From: Mitali Paygude Date: Fri, 16 Feb 2024 13:20:55 -0800 Subject: [PATCH] Log the cluster spec while cluster creation (#7621) --- .../management/create_install_eksa.go | 10 +++ pkg/workflows/management/create_test.go | 69 ++++++++----------- pkg/workflows/workload/createcluster.go | 10 +++ 3 files changed, 50 insertions(+), 39 deletions(-) diff --git a/pkg/workflows/management/create_install_eksa.go b/pkg/workflows/management/create_install_eksa.go index fc5a91e97fc4..93a91627bd5e 100644 --- a/pkg/workflows/management/create_install_eksa.go +++ b/pkg/workflows/management/create_install_eksa.go @@ -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" @@ -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{} } diff --git a/pkg/workflows/management/create_test.go b/pkg/workflows/management/create_test.go index 41505fc0d81a..4884b57be875 100644 --- a/pkg/workflows/management/create_test.go +++ b/pkg/workflows/management/create_test.go @@ -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() { @@ -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() @@ -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 { @@ -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() @@ -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, @@ -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")) @@ -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()) diff --git a/pkg/workflows/workload/createcluster.go b/pkg/workflows/workload/createcluster.go index 32a60b65e3ba..b6bca3394383 100644 --- a/pkg/workflows/workload/createcluster.go +++ b/pkg/workflows/workload/createcluster.go @@ -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" @@ -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{} }