Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ExistingManagement field from Cluster type #7262

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cmd/eksctl-anywhere/cmd/deletecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/eksctl-anywhere/cmd/upgrademanagementcomponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@
)

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),

Check warning on line 85 in cmd/eksctl-anywhere/cmd/upgrademanagementcomponents.go

View check run for this annotation

Codecov / codecov/patch

cmd/eksctl-anywhere/cmd/upgrademanagementcomponents.go#L84-L85

Added lines #L84 - L85 were not covered by tests
}

validator := management.NewUMCValidator(managementCluster, deps.Kubectl)
Expand Down
1 change: 0 additions & 1 deletion pkg/cluster/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ func LoadManagement(kubeconfig string) (*types.Cluster, error) {
return &types.Cluster{
Name: kc.Clusters[0].Name,
KubeconfigFile: kubeconfig,
ExistingManagement: true,
}, nil
}
5 changes: 2 additions & 3 deletions pkg/clustermanager/cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
21 changes: 7 additions & 14 deletions pkg/clustermanager/cluster_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/gitops/flux/flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ 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
}

return f.fluxClient.BootstrapGithub(ctx, cluster, clusterSpec.FluxConfig)
}

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
}

Expand Down
112 changes: 110 additions & 2 deletions pkg/gitops/flux/flux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ 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"
"github.com/aws/eks-anywhere/pkg/git"
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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
})
}
}
25 changes: 10 additions & 15 deletions pkg/providers/cloudstack/cloudstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading