diff --git a/cmd/eksctl-anywhere/cmd/deletecluster.go b/cmd/eksctl-anywhere/cmd/deletecluster.go index 8f9af5eaaa2f..762db2f2128f 100644 --- a/cmd/eksctl-anywhere/cmd/deletecluster.go +++ b/cmd/eksctl-anywhere/cmd/deletecluster.go @@ -134,13 +134,11 @@ func (dc *deleteClusterOptions) deleteCluster(ctx context.Context) error { cluster = &types.Cluster{ Name: clusterSpec.Cluster.Name, KubeconfigFile: kubeconfig.FromClusterName(clusterSpec.Cluster.Name), - ExistingManagement: false, } } else { cluster = &types.Cluster{ Name: clusterSpec.Cluster.Name, KubeconfigFile: clusterSpec.ManagementCluster.KubeconfigFile, - ExistingManagement: true, } } diff --git a/cmd/eksctl-anywhere/cmd/upgrademanagementcomponents.go b/cmd/eksctl-anywhere/cmd/upgrademanagementcomponents.go index 7143a3a5879e..f12ac3622e0e 100644 --- a/cmd/eksctl-anywhere/cmd/upgrademanagementcomponents.go +++ b/cmd/eksctl-anywhere/cmd/upgrademanagementcomponents.go @@ -81,9 +81,8 @@ var upgradeManagementComponentsCmd = &cobra.Command{ ) managementCluster := &types.Cluster{ - Name: clusterSpec.Cluster.Name, - KubeconfigFile: kubeconfig.FromClusterName(clusterSpec.Cluster.Name), - ExistingManagement: clusterSpec.Cluster.IsSelfManaged(), + Name: clusterSpec.Cluster.Name, + KubeconfigFile: kubeconfig.FromClusterName(clusterSpec.Cluster.Name), } validator := management.NewUMCValidator(managementCluster, deps.Kubectl) diff --git a/pkg/cluster/load.go b/pkg/cluster/load.go index 5df0f6cd5cad..e6e4523edf07 100644 --- a/pkg/cluster/load.go +++ b/pkg/cluster/load.go @@ -39,6 +39,5 @@ func LoadManagement(kubeconfig string) (*types.Cluster, error) { return &types.Cluster{ Name: kc.Clusters[0].Name, KubeconfigFile: kubeconfig, - ExistingManagement: true, }, nil } diff --git a/pkg/clustermanager/cluster_manager.go b/pkg/clustermanager/cluster_manager.go index a2f0ccb10144..9c0e2b19ee2e 100644 --- a/pkg/clustermanager/cluster_manager.go +++ b/pkg/clustermanager/cluster_manager.go @@ -407,8 +407,7 @@ func (c *ClusterManager) CreateWorkloadCluster(ctx context.Context, managementCl clusterName := clusterSpec.Cluster.Name workloadCluster := &types.Cluster{ - Name: clusterName, - ExistingManagement: managementCluster.ExistingManagement, + Name: clusterName, } if err := c.applyProviderManifests(ctx, clusterSpec, managementCluster, provider); err != nil { @@ -590,7 +589,7 @@ func (c *ClusterManager) deleteEKSAObjects(ctx context.Context, managementCluste func (c *ClusterManager) UpgradeCluster(ctx context.Context, managementCluster, workloadCluster *types.Cluster, newClusterSpec *cluster.Spec, provider providers.Provider) error { eksaMgmtCluster := workloadCluster - if managementCluster != nil && managementCluster.ExistingManagement { + if managementCluster != nil { eksaMgmtCluster = managementCluster } diff --git a/pkg/clustermanager/cluster_manager_test.go b/pkg/clustermanager/cluster_manager_test.go index ae44e53010d8..9f35826273fb 100644 --- a/pkg/clustermanager/cluster_manager_test.go +++ b/pkg/clustermanager/cluster_manager_test.go @@ -842,8 +842,7 @@ func TestClusterManagerUpgradeWorkloadClusterSuccess(t *testing.T) { workClusterName := "cluster-name-w" mCluster := &types.Cluster{ - Name: mgmtClusterName, - ExistingManagement: true, + Name: mgmtClusterName, } wCluster := &types.Cluster{ Name: workClusterName, @@ -888,8 +887,7 @@ func TestClusterManagerUpgradeWorkloadClusterAWSIamConfigSuccess(t *testing.T) { workClusterName := "cluster-name-w" mCluster := &types.Cluster{ - Name: mgmtClusterName, - ExistingManagement: true, + Name: mgmtClusterName, } wCluster := &types.Cluster{ Name: workClusterName, @@ -969,8 +967,7 @@ func TestClusterManagerUpgradeCloudStackWorkloadClusterSuccess(t *testing.T) { workClusterName := "cluster-name-w" mCluster := &types.Cluster{ - Name: mgmtClusterName, - ExistingManagement: true, + Name: mgmtClusterName, } wCluster := &types.Cluster{ Name: workClusterName, @@ -1015,8 +1012,7 @@ func TestClusterManagerUpgradeWorkloadClusterWaitForMDReadyErrorOnce(t *testing. workClusterName := "cluster-name-w" mCluster := &types.Cluster{ - Name: mgmtClusterName, - ExistingManagement: true, + Name: mgmtClusterName, } wCluster := &types.Cluster{ Name: workClusterName, @@ -1064,8 +1060,7 @@ func TestClusterManagerUpgradeWorkloadClusterWaitForMDReadyUnreadyOnce(t *testin workClusterName := "cluster-name-w" mCluster := &types.Cluster{ - Name: mgmtClusterName, - ExistingManagement: true, + Name: mgmtClusterName, } wCluster := &types.Cluster{ Name: workClusterName, @@ -1152,8 +1147,7 @@ func TestClusterManagerUpgradeWorkloadClusterGetMachineDeploymentError(t *testin workClusterName := "cluster-name-w" mCluster := &types.Cluster{ - Name: mgmtClusterName, - ExistingManagement: true, + Name: mgmtClusterName, } wCluster := &types.Cluster{ Name: workClusterName, @@ -1188,8 +1182,7 @@ func TestClusterManagerUpgradeWorkloadClusterRemoveOldWorkerNodeGroupsError(t *t workClusterName := "cluster-name-w" mCluster := &types.Cluster{ - Name: mgmtClusterName, - ExistingManagement: true, + Name: mgmtClusterName, } wCluster := &types.Cluster{ Name: workClusterName, diff --git a/pkg/gitops/flux/flux.go b/pkg/gitops/flux/flux.go index 6a36bfdca32a..854b9f3724cc 100644 --- a/pkg/gitops/flux/flux.go +++ b/pkg/gitops/flux/flux.go @@ -126,7 +126,7 @@ func (f *Flux) Bootstrap(ctx context.Context, cluster *types.Cluster, clusterSpe } func (f *Flux) BootstrapGithub(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec) error { - if cluster.ExistingManagement || clusterSpec.FluxConfig.Spec.Github == nil { + if clusterSpec.Cluster.IsManaged() || clusterSpec.FluxConfig.Spec.Github == nil { return nil } @@ -134,7 +134,7 @@ func (f *Flux) BootstrapGithub(ctx context.Context, cluster *types.Cluster, clus } func (f *Flux) BootstrapGit(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec) error { - if cluster.ExistingManagement || clusterSpec.FluxConfig.Spec.Git == nil { + if clusterSpec.Cluster.IsManaged() || clusterSpec.FluxConfig.Spec.Git == nil { return nil } diff --git a/pkg/gitops/flux/flux_test.go b/pkg/gitops/flux/flux_test.go index 50dbf6e64713..9bcb9aa5d2e2 100644 --- a/pkg/gitops/flux/flux_test.go +++ b/pkg/gitops/flux/flux_test.go @@ -13,6 +13,7 @@ import ( "github.com/aws/eks-anywhere/internal/test" "github.com/aws/eks-anywhere/pkg/api/v1alpha1" + anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1" "github.com/aws/eks-anywhere/pkg/cluster" "github.com/aws/eks-anywhere/pkg/constants" "github.com/aws/eks-anywhere/pkg/filewriter" @@ -20,6 +21,7 @@ import ( gitFactory "github.com/aws/eks-anywhere/pkg/git/factory" gitMocks "github.com/aws/eks-anywhere/pkg/git/mocks" "github.com/aws/eks-anywhere/pkg/gitops/flux" + "github.com/aws/eks-anywhere/pkg/gitops/flux/mocks" fluxMocks "github.com/aws/eks-anywhere/pkg/gitops/flux/mocks" "github.com/aws/eks-anywhere/pkg/providers" mocksprovider "github.com/aws/eks-anywhere/pkg/providers/mocks" @@ -342,8 +344,6 @@ func TestInstallGitOpsOnWorkloadClusterWithPrexistingRepo(t *testing.T) { g := newFluxTest(t) clusterSpec := newClusterSpec(t, clusterConfig, "") - g.flux.EXPECT().BootstrapGithub(g.ctx, cluster, clusterSpec.FluxConfig) - g.git.EXPECT().GetRepo(g.ctx).Return(&git.Repository{Name: clusterSpec.FluxConfig.Spec.Github.Repository}, nil) g.git.EXPECT().Clone(g.ctx).Return(nil) @@ -1079,3 +1079,111 @@ func TestUninstallError(t *testing.T) { g.Expect(g.gitOpsFlux.Uninstall(g.ctx, c, g.clusterSpec)).To(MatchError(ContainSubstring("error in uninstall"))) } + +func TestFluxBootstrapGithub(t *testing.T) { + c := &types.Cluster{} + ctx := context.Background() + testCases := []struct { + name string + spec *cluster.Spec + needBootstrapGithub bool + }{ + { + name: "management cluster", + spec: test.NewClusterSpec(func(s *cluster.Spec) { + s.Cluster.Name = "management-cluster" + s.Cluster.SetSelfManaged() + s.FluxConfig = &anywherev1.FluxConfig{ + Spec: anywherev1.FluxConfigSpec{ + Github: &anywherev1.GithubProviderConfig{}, + }, + } + }), + needBootstrapGithub: true, + }, + { + name: "workload cluster", + spec: test.NewClusterSpec(func(s *cluster.Spec) { + s.Cluster.Name = "workload-cluster" + s.Cluster.SetManagedBy("management-cluster") + }), + needBootstrapGithub: false, + }, + { + name: "management cluster not github configured", + spec: test.NewClusterSpec(func(s *cluster.Spec) { + s.Cluster.Name = "management-cluster" + s.Cluster.SetSelfManaged() + s.FluxConfig = &anywherev1.FluxConfig{} + }), + needBootstrapGithub: false, + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + g := NewWithT(t) + ctrl := gomock.NewController(t) + mockFluxClient := mocks.NewMockFluxClient(ctrl) + if tc.needBootstrapGithub { + mockFluxClient.EXPECT().BootstrapGithub(ctx, c, tc.spec.FluxConfig).Return(nil) + } + + f := flux.NewFlux(mockFluxClient, nil, nil, nil) + g.Expect(f.BootstrapGithub(ctx, c, tc.spec)).NotTo(HaveOccurred()) + }) + } +} + +func TestFluxBootstrapGit(t *testing.T) { + c := &types.Cluster{} + ctx := context.Background() + testCases := []struct { + name string + spec *cluster.Spec + needBootstrapGit bool + }{ + { + name: "management cluster", + spec: test.NewClusterSpec(func(s *cluster.Spec) { + s.Cluster.Name = "management-cluster" + s.Cluster.SetSelfManaged() + s.FluxConfig = &anywherev1.FluxConfig{ + Spec: anywherev1.FluxConfigSpec{ + Git: &anywherev1.GitProviderConfig{}, + }, + } + }), + needBootstrapGit: true, + }, + { + name: "workload cluster", + spec: test.NewClusterSpec(func(s *cluster.Spec) { + s.Cluster.Name = "workload-cluster" + s.Cluster.SetManagedBy("management-cluster") + }), + needBootstrapGit: false, + }, + { + name: "management cluster not git configured", + spec: test.NewClusterSpec(func(s *cluster.Spec) { + s.Cluster.Name = "management-cluster" + s.Cluster.SetSelfManaged() + s.FluxConfig = &anywherev1.FluxConfig{} + }), + needBootstrapGit: false, + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + g := NewWithT(t) + ctrl := gomock.NewController(t) + mockFluxClient := mocks.NewMockFluxClient(ctrl) + if tc.needBootstrapGit { + mockFluxClient.EXPECT().BootstrapGit(ctx, c, tc.spec.FluxConfig, nil).Return(nil) + } + + f := flux.NewFlux(mockFluxClient, nil, nil, nil) + g.Expect(f.BootstrapGit(ctx, c, tc.spec)).NotTo(HaveOccurred()) + }) + } +} diff --git a/pkg/providers/cloudstack/cloudstack_test.go b/pkg/providers/cloudstack/cloudstack_test.go index 695a9ce2d5e3..b079db7c97d0 100644 --- a/pkg/providers/cloudstack/cloudstack_test.go +++ b/pkg/providers/cloudstack/cloudstack_test.go @@ -732,9 +732,8 @@ func TestSetupAndValidateCreateWorkloadClusterSuccess(t *testing.T) { clusterSpec := givenClusterSpec(t, testClusterConfigMainFilename) clusterSpec.Cluster.SetManagedBy("management-cluster") clusterSpec.ManagementCluster = &types.Cluster{ - Name: "management-cluster", - KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, + Name: "management-cluster", + KubeconfigFile: "kc.kubeconfig", } setupContext(t) @@ -765,9 +764,8 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfMachineExists(t *testing.T) clusterSpec := givenClusterSpec(t, testClusterConfigMainFilename) clusterSpec.Cluster.SetManagedBy("management-cluster") clusterSpec.ManagementCluster = &types.Cluster{ - Name: "management-cluster", - KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, + Name: "management-cluster", + KubeconfigFile: "kc.kubeconfig", } setupContext(t) @@ -808,9 +806,8 @@ func TestSetupAndValidateSelfManagedClusterSkipMachineNameValidateSuccess(t *tes provider.providerKubectlClient = kubectl clusterSpec.ManagementCluster = &types.Cluster{ - Name: "management-cluster", - KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, + Name: "management-cluster", + KubeconfigFile: "kc.kubeconfig", } kubectl.EXPECT().SearchCloudStackMachineConfig(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0) @@ -828,9 +825,8 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfDatacenterExists(t *testing clusterSpec := givenClusterSpec(t, testClusterConfigMainFilename) clusterSpec.Cluster.SetManagedBy("management-cluster") clusterSpec.ManagementCluster = &types.Cluster{ - Name: "management-cluster", - KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, + Name: "management-cluster", + KubeconfigFile: "kc.kubeconfig", } setupContext(t) @@ -864,9 +860,8 @@ func TestSetupAndValidateSelfManagedClusterSkipDatacenterNameValidateSuccess(t * provider.providerKubectlClient = kubectl clusterSpec.ManagementCluster = &types.Cluster{ - Name: "management-cluster", - KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, + Name: "management-cluster", + KubeconfigFile: "kc.kubeconfig", } kubectl.EXPECT().SearchCloudStackMachineConfig(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0) diff --git a/pkg/providers/tinkerbell/tinkerbell_test.go b/pkg/providers/tinkerbell/tinkerbell_test.go index 26612ca6ffb3..2ce1d8968375 100644 --- a/pkg/providers/tinkerbell/tinkerbell_test.go +++ b/pkg/providers/tinkerbell/tinkerbell_test.go @@ -1134,7 +1134,6 @@ func TestSetupAndValidateCreateWorkloadClusterSuccess(t *testing.T) { clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { kubectl.EXPECT().SearchTinkerbellMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.TinkerbellMachineConfig{}, nil) @@ -1183,7 +1182,6 @@ func TestSetupAndValidateCreateWorkloadClusterDifferentNamespaceSuccess(t *testi clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { kubectl.EXPECT().SearchTinkerbellMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.TinkerbellMachineConfig{}, nil) @@ -1230,7 +1228,6 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfMachineExists(t *testing.T) clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } idx := 0 @@ -1276,7 +1273,6 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfDatacenterExists(t *testing clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { @@ -1315,7 +1311,6 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfDatacenterConfigError(t *te clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { @@ -1353,7 +1348,6 @@ func TestSetupAndValidateCreateWorkloadClusterErrorUnprovisionedHardware(t *test clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { kubectl.EXPECT().SearchTinkerbellMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.TinkerbellMachineConfig{}, nil) @@ -1392,7 +1386,6 @@ func TestSetupAndValidateCreateWorkloadClusterErrorProvisionedHardware(t *testin clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { kubectl.EXPECT().SearchTinkerbellMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.TinkerbellMachineConfig{}, nil) @@ -1463,7 +1456,6 @@ func TestSetupAndValidateUpgradeWorkloadClusterErrorApplyHardware(t *testing.T) clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } cluster.KubeconfigFile = "kc.kubeconfig" @@ -1502,7 +1494,6 @@ func TestSetupAndValidateUpgradeWorkloadClusterErrorBMC(t *testing.T) { clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } cluster.KubeconfigFile = "kc.kubeconfig" @@ -1544,7 +1535,6 @@ func TestSetupAndValidateCreateWorkloadClusterErrorManagementCluster(t *testing. clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { kubectl.EXPECT().SearchTinkerbellMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.TinkerbellMachineConfig{}, nil) @@ -1590,7 +1580,6 @@ func TestSetupAndValidateCreateWorkloadClusterErrorUnspecifiedTinkerbellIP(t *te clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { kubectl.EXPECT().SearchTinkerbellMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.TinkerbellMachineConfig{}, nil) @@ -1632,7 +1621,6 @@ func TestSetupAndValidateCreateWorkloadClusterErrorManagementClusterTinkerbellIP clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { kubectl.EXPECT().SearchTinkerbellMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.TinkerbellMachineConfig{}, nil) @@ -1677,7 +1665,6 @@ func TestSetupAndValidateCreateWorkloadClusterErrorDifferentTinkerbellIP(t *test clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range machineConfigs { kubectl.EXPECT().SearchTinkerbellMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.TinkerbellMachineConfig{}, nil) diff --git a/pkg/providers/vsphere/template_test.go b/pkg/providers/vsphere/template_test.go index 5443d40829a9..26724b67976a 100644 --- a/pkg/providers/vsphere/template_test.go +++ b/pkg/providers/vsphere/template_test.go @@ -1,12 +1,14 @@ package vsphere_test import ( + "os" "testing" "time" . "github.com/onsi/gomega" "github.com/aws/eks-anywhere/internal/test" + "github.com/aws/eks-anywhere/pkg/config" "github.com/aws/eks-anywhere/pkg/providers/vsphere" ) @@ -50,6 +52,9 @@ func TestVsphereTemplateBuilderGenerateCAPISpecControlPlaneInvalidEtcdSSHKey(t * } func TestTemplateBuilder_CertSANs(t *testing.T) { + os.Unsetenv(config.EksavSphereUsernameKey) + os.Unsetenv(config.EksavSpherePasswordKey) + for _, tc := range []struct { Input string Output string diff --git a/pkg/providers/vsphere/vsphere_test.go b/pkg/providers/vsphere/vsphere_test.go index d8d31acfdaf3..fbe0ee29a7c4 100644 --- a/pkg/providers/vsphere/vsphere_test.go +++ b/pkg/providers/vsphere/vsphere_test.go @@ -1572,7 +1572,6 @@ func TestSetupAndValidateCreateWorkloadClusterSuccess(t *testing.T) { clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range clusterSpec.VSphereMachineConfigs { kubectl.EXPECT().SearchVsphereMachineConfig(ctx, config.Name, clusterSpec.ManagementCluster.KubeconfigFile, config.Namespace).Return([]*v1alpha1.VSphereMachineConfig{}, nil) @@ -1603,7 +1602,6 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfMachineExists(t *testing.T) clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } idx := 0 @@ -1638,7 +1636,6 @@ func TestSetupAndValidateSelfManagedClusterSkipMachineNameValidateSuccess(t *tes clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } kubectl.EXPECT().SearchVsphereMachineConfig(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any()).Times(0) @@ -1669,7 +1666,6 @@ func TestSetupAndValidateCreateWorkloadClusterFailsIfDatacenterExists(t *testing clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } for _, config := range clusterSpec.VSphereMachineConfigs { @@ -1697,7 +1693,6 @@ func TestSetupAndValidateSelfManagedClusterSkipDatacenterNameValidateSuccess(t * clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } kubectl.EXPECT().SearchVsphereMachineConfig(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Times(0) diff --git a/pkg/task/task_test.go b/pkg/task/task_test.go index e232146ba1cd..0d71c856705f 100644 --- a/pkg/task/task_test.go +++ b/pkg/task/task_test.go @@ -172,7 +172,6 @@ func TestUnmarshalTaskCheckpointSuccess(t *testing.T) { testTaskCheckpoint := types.Cluster{ Name: "test-cluster", KubeconfigFile: "test.kubeconfig", - ExistingManagement: false, } if err := task.UnmarshalTaskCheckpoint(testTaskCheckpoint, testConfigType); err != nil { diff --git a/pkg/types/cluster.go b/pkg/types/cluster.go index 38d00b75cf08..a091a525268a 100644 --- a/pkg/types/cluster.go +++ b/pkg/types/cluster.go @@ -3,17 +3,15 @@ package types import "github.com/aws/eks-anywhere/release/api/v1alpha1" type Cluster struct { - Name string - KubeconfigFile string - ExistingManagement bool // true is the cluster has EKS Anywhere management components + Name string + KubeconfigFile string } // DeepCopy creates a new in-memory copy of c. func (c *Cluster) DeepCopy() *Cluster { return &Cluster{ - Name: c.Name, - KubeconfigFile: c.KubeconfigFile, - ExistingManagement: c.ExistingManagement, + Name: c.Name, + KubeconfigFile: c.KubeconfigFile, } } diff --git a/pkg/validations/upgradevalidations/versions.go b/pkg/validations/upgradevalidations/versions.go index 89f03e9fd93c..e9878f23d963 100644 --- a/pkg/validations/upgradevalidations/versions.go +++ b/pkg/validations/upgradevalidations/versions.go @@ -10,12 +10,7 @@ import ( ) // ValidateServerVersionSkew validates Kubernetes version skew between upgrades for the CLI. -func ValidateServerVersionSkew(ctx context.Context, newCluster *anywherev1.Cluster, cluster *types.Cluster, mgmtCluster *types.Cluster, kubectl validations.KubectlClient) error { - managementCluster := cluster - if !cluster.ExistingManagement { - managementCluster = mgmtCluster - } - +func ValidateServerVersionSkew(ctx context.Context, newCluster *anywherev1.Cluster, cluster *types.Cluster, managementCluster *types.Cluster, kubectl validations.KubectlClient) error { eksaCluster, err := kubectl.GetEksaCluster(ctx, managementCluster, newCluster.Name) if err != nil { return fmt.Errorf("fetching old cluster: %v", err) @@ -25,12 +20,7 @@ func ValidateServerVersionSkew(ctx context.Context, newCluster *anywherev1.Clust } // ValidateWorkerServerVersionSkew validates worker node group Kubernetes version skew between upgrades. -func ValidateWorkerServerVersionSkew(ctx context.Context, newCluster *anywherev1.Cluster, cluster *types.Cluster, mgmtCluster *types.Cluster, kubectl validations.KubectlClient) error { - managementCluster := cluster - if !cluster.ExistingManagement { - managementCluster = mgmtCluster - } - +func ValidateWorkerServerVersionSkew(ctx context.Context, newCluster *anywherev1.Cluster, cluster *types.Cluster, managementCluster *types.Cluster, kubectl validations.KubectlClient) error { eksaCluster, err := kubectl.GetEksaCluster(ctx, managementCluster, newCluster.Name) if err != nil { return fmt.Errorf("fetching old cluster: %v", err) diff --git a/pkg/workflows/create.go b/pkg/workflows/create.go index d4ef7f36735c..7843417a1e78 100644 --- a/pkg/workflows/create.go +++ b/pkg/workflows/create.go @@ -244,7 +244,7 @@ func (s *CreateWorkloadClusterTask) Run(ctx context.Context, commandContext *tas } } - if !commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsSelfManaged() { logger.Info("Creating EKS-A namespace") err = commandContext.ClusterManager.CreateEKSANamespace(ctx, workloadCluster) if err != nil { @@ -284,7 +284,7 @@ func (s *CreateWorkloadClusterTask) Checkpoint() *task.CompletedTask { // InstallResourcesOnManagement implementation. func (s *InstallResourcesOnManagementTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { - if commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsManaged() { return &MoveClusterManagementTask{} } logger.Info("Installing resources on management cluster") @@ -311,7 +311,7 @@ func (s *InstallResourcesOnManagementTask) Checkpoint() *task.CompletedTask { // MoveClusterManagementTask implementation func (s *MoveClusterManagementTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { - if commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsManaged() { return &InstallEksaComponentsTask{} } logger.Info("Moving cluster management from bootstrap to workload cluster") @@ -339,7 +339,7 @@ func (s *MoveClusterManagementTask) Checkpoint() *task.CompletedTask { // InstallEksaComponentsTask implementation func (s *InstallEksaComponentsTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { - if !commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsSelfManaged() { logger.Info("Installing EKS-A custom components (CRD and controller) on workload cluster") err := commandContext.ClusterManager.InstallCustomComponents(ctx, commandContext.ClusterSpec, commandContext.WorkloadCluster, commandContext.Provider) if err != nil { @@ -359,7 +359,7 @@ func (s *InstallEksaComponentsTask) Run(ctx context.Context, commandContext *tas machineConfigs := commandContext.Provider.MachineConfigs(commandContext.ClusterSpec) targetCluster := commandContext.WorkloadCluster - if commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsManaged() { targetCluster = commandContext.BootstrapCluster } err := commandContext.ClusterManager.CreateEKSAResources(ctx, targetCluster, commandContext.ClusterSpec, datacenterConfig, machineConfigs) @@ -442,7 +442,7 @@ func (s *WriteClusterConfigTask) Checkpoint() *task.CompletedTask { // DeleteBootstrapClusterTask implementation func (s *DeleteBootstrapClusterTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { - if !commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsSelfManaged() { logger.Info("Deleting bootstrap cluster") err := commandContext.Bootstrapper.DeleteBootstrapCluster(ctx, commandContext.BootstrapCluster, constants.Create, false) if err != nil { diff --git a/pkg/workflows/create_test.go b/pkg/workflows/create_test.go index 8db5517446c5..2a2975c1978b 100644 --- a/pkg/workflows/create_test.go +++ b/pkg/workflows/create_test.go @@ -76,6 +76,26 @@ func newCreateTest(t *testing.T) *createTestSetup { } } +func newCreateWorkloadClusterTest(t *testing.T) *createTestSetup { + tt := newCreateTest(t) + + tt.bootstrapCluster = &types.Cluster{ + Name: "management-cluster", + KubeconfigFile: "kubeconfig.yaml", + } + + tt.workloadCluster = &types.Cluster{ + Name: "workload-cluster", + KubeconfigFile: "wl-kubeconfig.yaml", + } + + tt.clusterSpec.Cluster.Name = tt.workloadCluster.Name + tt.clusterSpec.Cluster.SetManagedBy(tt.bootstrapCluster.Name) + tt.clusterSpec.ManagementCluster = tt.bootstrapCluster + + return tt +} + func (c *createTestSetup) expectSetup() { c.provider.EXPECT().SetupAndValidateCreateCluster(c.ctx, c.clusterSpec) c.provider.EXPECT().Name() @@ -226,7 +246,7 @@ 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("cluster-name-eks-a-cluster.yaml", gomock.Any(), gomock.Any()), + c.writer.EXPECT().Write(c.clusterSpec.Cluster.Name+"-eks-a-cluster.yaml", gomock.Any(), gomock.Any()), ) } @@ -343,18 +363,7 @@ func TestCreateRunSuccessForceCleanup(t *testing.T) { } func TestCreateWorkloadClusterRunSuccess(t *testing.T) { - managementKubeconfig := "test.kubeconfig" - test := newCreateTest(t) - - test.bootstrapCluster.ExistingManagement = true - test.bootstrapCluster.KubeconfigFile = managementKubeconfig - test.bootstrapCluster.Name = "cluster-name" - - test.clusterSpec.ManagementCluster = &types.Cluster{ - Name: test.bootstrapCluster.Name, - KubeconfigFile: managementKubeconfig, - ExistingManagement: true, - } + test := newCreateWorkloadClusterTest(t) test.expectSetup() test.expectCreateWorkloadSkipCAPI() @@ -373,18 +382,7 @@ func TestCreateWorkloadClusterRunSuccess(t *testing.T) { } func TestCreateWorkloadClusterRunAWSIamConfigSuccess(t *testing.T) { - managementKubeconfig := "test.kubeconfig" - test := newCreateTest(t) - - test.bootstrapCluster.ExistingManagement = true - test.bootstrapCluster.KubeconfigFile = managementKubeconfig - test.bootstrapCluster.Name = "cluster-name" - - test.clusterSpec.ManagementCluster = &types.Cluster{ - Name: test.bootstrapCluster.Name, - KubeconfigFile: managementKubeconfig, - ExistingManagement: true, - } + test := newCreateWorkloadClusterTest(t) // Adding AWSIAMConfig to cluster spec. test.clusterSpec.AWSIamConfig = &v1alpha1.AWSIamConfig{} @@ -408,18 +406,7 @@ func TestCreateWorkloadClusterRunAWSIamConfigSuccess(t *testing.T) { func TestCreateWorkloadClusterRunAWSIamConfigFail(t *testing.T) { wantError := errors.New("test error") - managementKubeconfig := "test.kubeconfig" - test := newCreateTest(t) - - test.bootstrapCluster.ExistingManagement = true - test.bootstrapCluster.KubeconfigFile = managementKubeconfig - test.bootstrapCluster.Name = "cluster-name" - - test.clusterSpec.ManagementCluster = &types.Cluster{ - Name: test.bootstrapCluster.Name, - KubeconfigFile: managementKubeconfig, - ExistingManagement: true, - } + test := newCreateWorkloadClusterTest(t) // Adding AWSIAMConfig to cluster spec. test.clusterSpec.AWSIamConfig = &v1alpha1.AWSIamConfig{} @@ -435,7 +422,7 @@ func TestCreateWorkloadClusterRunAWSIamConfigFail(t *testing.T) { } func TestCreateWorkloadClusterTaskCreateWorkloadClusterFailure(t *testing.T) { - test := newCreateTest(t) + test := newCreateWorkloadClusterTest(t) commandContext := task.CommandContext{ BootstrapCluster: test.bootstrapCluster, ClusterSpec: test.clusterSpec, @@ -462,7 +449,7 @@ func TestCreateWorkloadClusterTaskCreateWorkloadClusterFailure(t *testing.T) { } func TestCreateWorkloadClusterTaskRunPostCreateWorkloadClusterFailure(t *testing.T) { - test := newCreateTest(t) + test := newCreateWorkloadClusterTest(t) commandContext := task.CommandContext{ BootstrapCluster: test.bootstrapCluster, ClusterSpec: test.clusterSpec, diff --git a/pkg/workflows/delete.go b/pkg/workflows/delete.go index de994be404ee..0122870b644d 100644 --- a/pkg/workflows/delete.go +++ b/pkg/workflows/delete.go @@ -98,7 +98,7 @@ func (s *setupAndValidate) Checkpoint() *task.CompletedTask { } func (s *createManagementCluster) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { - if commandContext.BootstrapCluster != nil && commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsManaged() { return &deleteWorkloadCluster{} } logger.Info("Creating management cluster") @@ -228,7 +228,7 @@ func (s *cleanupGitRepo) Checkpoint() *task.CompletedTask { } func (s *deletePackageResources) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { - if !commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsSelfManaged() { return &deleteManagementCluster{} } @@ -263,7 +263,7 @@ func (s *deleteManagementCluster) Run(ctx context.Context, commandContext *task. collector := &CollectMgmtClusterDiagnosticsTask{} collector.Run(ctx, commandContext) } - if commandContext.BootstrapCluster != nil && !commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsSelfManaged() { if err := commandContext.Bootstrapper.DeleteBootstrapCluster(ctx, commandContext.BootstrapCluster, constants.Delete, false); err != nil { commandContext.SetError(err) } diff --git a/pkg/workflows/delete_test.go b/pkg/workflows/delete_test.go index b5a00a7d777f..ad067695f7a9 100644 --- a/pkg/workflows/delete_test.go +++ b/pkg/workflows/delete_test.go @@ -170,7 +170,6 @@ func TestDeleteWorkloadRunSuccess(t *testing.T) { test.clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } test.clusterSpec.Cluster.SetManagedBy(test.clusterSpec.ManagementCluster.Name) test.expectDeleteWorkload(test.clusterSpec.ManagementCluster) @@ -192,7 +191,6 @@ func TestDeleteWorkloadDeletePackageResourceError(t *testing.T) { test.clusterSpec.ManagementCluster = &types.Cluster{ Name: "management-cluster", KubeconfigFile: "kc.kubeconfig", - ExistingManagement: true, } test.clusterSpec.Cluster.SetManagedBy(test.clusterSpec.ManagementCluster.Name) test.expectDeleteWorkload(test.clusterSpec.ManagementCluster) diff --git a/pkg/workflows/management/upgrade_management_components_test.go b/pkg/workflows/management/upgrade_management_components_test.go index 7578fdb144c3..09c07265c7c2 100644 --- a/pkg/workflows/management/upgrade_management_components_test.go +++ b/pkg/workflows/management/upgrade_management_components_test.go @@ -84,7 +84,6 @@ func TestRunnerHappyPath(t *testing.T) { managementCluster := &types.Cluster{ Name: clusterSpec.Cluster.Name, KubeconfigFile: kubeconfig.FromClusterName(clusterSpec.Cluster.Name), - ExistingManagement: clusterSpec.Cluster.IsSelfManaged(), } ctx := context.Background() @@ -135,7 +134,6 @@ func TestRunnerStopsWhenValidationFailed(t *testing.T) { managementCluster := &types.Cluster{ Name: clusterSpec.Cluster.Name, KubeconfigFile: kubeconfig.FromClusterName(clusterSpec.Cluster.Name), - ExistingManagement: clusterSpec.Cluster.IsSelfManaged(), } ctx := context.Background() diff --git a/pkg/workflows/upgrade.go b/pkg/workflows/upgrade.go index e5d4bd5b0e15..b2380913fa58 100644 --- a/pkg/workflows/upgrade.go +++ b/pkg/workflows/upgrade.go @@ -376,7 +376,7 @@ func (s *createBootstrapClusterTask) Run(ctx context.Context, commandContext *ta return nil } } - if commandContext.ManagementCluster != nil && commandContext.ManagementCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsManaged() { return &upgradeWorkloadClusterTask{} } logger.Info("Creating bootstrap cluster") @@ -425,7 +425,7 @@ func (s *createBootstrapClusterTask) Restore(ctx context.Context, commandContext return nil, err } commandContext.BootstrapCluster = s.bootstrapCluster - if commandContext.ManagementCluster != nil && commandContext.ManagementCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsManaged() { return &upgradeWorkloadClusterTask{}, nil } return &installCAPITask{}, nil @@ -510,7 +510,7 @@ func (s *moveManagementToBootstrapTask) Restore(ctx context.Context, commandCont func (s *upgradeWorkloadClusterTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { eksaManagementCluster := commandContext.WorkloadCluster - if commandContext.ManagementCluster != nil && commandContext.ManagementCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsManaged() { eksaManagementCluster = commandContext.ManagementCluster } @@ -559,7 +559,7 @@ func (s *upgradeWorkloadClusterTask) Restore(ctx context.Context, commandContext } func (s *moveManagementToWorkloadTask) Run(ctx context.Context, commandContext *task.CommandContext) task.Task { - if commandContext.ManagementCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsManaged() { return &reconcileClusterDefinitions{eksaSpecDiff: true} } logger.Info("Moving cluster management from bootstrap to workload cluster") @@ -591,7 +591,7 @@ func (s *moveManagementToWorkloadTask) Checkpoint() *task.CompletedTask { } func (s *moveManagementToWorkloadTask) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) { - if !commandContext.ManagementCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsSelfManaged() { commandContext.ManagementCluster = commandContext.WorkloadCluster } return &reconcileClusterDefinitions{eksaSpecDiff: true}, nil @@ -687,7 +687,7 @@ func (s *deleteBootstrapClusterTask) Run(ctx context.Context, commandContext *ta c := CollectDiagnosticsTask{} c.Run(ctx, commandContext) } - if commandContext.BootstrapCluster != nil && !commandContext.BootstrapCluster.ExistingManagement { + if commandContext.ClusterSpec.Cluster.IsSelfManaged() { if err := commandContext.Bootstrapper.DeleteBootstrapCluster(ctx, commandContext.BootstrapCluster, constants.Upgrade, false); err != nil { commandContext.SetError(err) } diff --git a/pkg/workflows/upgrade_test.go b/pkg/workflows/upgrade_test.go index 476219114764..90079a5262d9 100644 --- a/pkg/workflows/upgrade_test.go +++ b/pkg/workflows/upgrade_test.go @@ -105,9 +105,8 @@ func (c *upgradeTestSetup) WithForceCleanup() *upgradeTestSetup { func newUpgradeSelfManagedClusterTest(t *testing.T) *upgradeTestSetup { tt := newUpgradeTest(t) tt.bootstrapCluster = &types.Cluster{ - Name: "bootstrap", - ExistingManagement: false, - KubeconfigFile: "kubeconfig.yaml", + Name: "bootstrap", + KubeconfigFile: "kubeconfig.yaml", } tt.managementCluster = tt.workloadCluster return tt @@ -116,13 +115,12 @@ func newUpgradeSelfManagedClusterTest(t *testing.T) *upgradeTestSetup { func newUpgradeManagedClusterTest(t *testing.T) *upgradeTestSetup { tt := newUpgradeTest(t) tt.managementCluster = &types.Cluster{ - Name: "management-cluster", - ExistingManagement: true, - KubeconfigFile: "kubeconfig.yaml", + Name: "management-cluster", + KubeconfigFile: "kubeconfig.yaml", } tt.workloadCluster.KubeconfigFile = "wl-kubeconfig.yaml" - tt.newClusterSpec.Cluster.SetSelfManaged() + tt.newClusterSpec.Cluster.SetManagedBy(tt.managementCluster.Name) tt.newClusterSpec.ManagementCluster = tt.managementCluster return tt } @@ -246,7 +244,7 @@ func (c *upgradeTestSetup) expectUpgradeWorkload(managementCluster *types.Cluste c.expectUpgradeWorkloadToReturn(managementCluster, workloadCluster, nil), } - if managementCluster != nil && managementCluster.ExistingManagement { + if c.newClusterSpec.Cluster.IsManaged() { calls = append(calls, c.clusterManager.EXPECT().ApplyBundles(c.ctx, c.newClusterSpec, managementCluster), c.clusterManager.EXPECT().ApplyReleases(c.ctx, c.newClusterSpec, managementCluster), diff --git a/test/e2e/certmanager.go b/test/e2e/certmanager.go index 4df41c12c8d1..b04709abdfdd 100644 --- a/test/e2e/certmanager.go +++ b/test/e2e/certmanager.go @@ -40,6 +40,5 @@ func withMgmtClusterSetup(cluster *framework.ClusterE2ETest) *types.Cluster { return &types.Cluster{ Name: cluster.ClusterName, KubeconfigFile: filepath.Join(cluster.ClusterName, fmt.Sprintf("%s-eks-a-cluster.kubeconfig", cluster.ClusterName)), - ExistingManagement: true, } } diff --git a/test/e2e/curatedpackages.go b/test/e2e/curatedpackages.go index fc229e7282a6..c8fc86a7a105 100644 --- a/test/e2e/curatedpackages.go +++ b/test/e2e/curatedpackages.go @@ -219,7 +219,6 @@ func withMgmtCluster(cluster *framework.ClusterE2ETest) *types.Cluster { return &types.Cluster{ Name: cluster.ClusterName, KubeconfigFile: filepath.Join(cluster.ClusterName, fmt.Sprintf("%s-eks-a-cluster.kubeconfig", cluster.ClusterName)), - ExistingManagement: true, } }