Skip to content

Commit

Permalink
remove unnecessary validations for upgrade management components
Browse files Browse the repository at this point in the history
  • Loading branch information
cxbrowne1207 committed Feb 14, 2024
1 parent 2e7f5ba commit 8fc5000
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 13 deletions.
9 changes: 9 additions & 0 deletions pkg/providers/cloudstack/cloudstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ func (p *cloudstackProvider) SetupAndValidateDeleteCluster(ctx context.Context,
return nil
}

// SetupAndValidateUpgradeManagementComponents performs necessary setup for upgrade management components operation.
func (p *cloudstackProvider) SetupAndValidateUpgradeManagementComponents(ctx context.Context, _ *cluster.Spec) error {
err := p.validateEnv(ctx)
if err != nil {
return fmt.Errorf("validating environment variables: %v", err)
}
return nil
}

func needsNewControlPlaneTemplate(oldSpec, newSpec *cluster.Spec, oldCsmc, newCsmc *v1alpha1.CloudStackMachineConfig, log logr.Logger) bool {
// Another option is to generate MachineTemplates based on the old and new eksa spec,
// remove the name field and compare them with DeepEqual
Expand Down
5 changes: 5 additions & 0 deletions pkg/providers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ func (p *Provider) SetupAndValidateUpgradeCluster(ctx context.Context, _ *types.
return nil
}

// SetupAndValidateUpgradeManagementComponents performs necessary setup for upgrade management components operation.
func (p *Provider) SetupAndValidateUpgradeManagementComponents(_ context.Context, _ *cluster.Spec) error {
return nil
}

// UpdateSecrets is a no-op. It implements providers.Provider.
func (p *Provider) UpdateSecrets(ctx context.Context, cluster *types.Cluster, _ *cluster.Spec) error {
// Not implemented
Expand Down
14 changes: 14 additions & 0 deletions pkg/providers/mocks/providers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion pkg/providers/nutanix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,20 @@ func (p *Provider) SetupAndValidateDeleteCluster(ctx context.Context, cluster *t

// SetupAndValidateUpgradeCluster - Performs necessary setup and validations for upgrade cluster operation.
func (p *Provider) SetupAndValidateUpgradeCluster(ctx context.Context, _ *types.Cluster, clusterSpec *cluster.Spec, _ *cluster.Spec) error {
// TODO(nutanix): Add validations when this is supported
if err := setupEnvVars(p.datacenterConfig); err != nil {
return fmt.Errorf("failed setup and validations: %v", err)
}

if err := p.validator.validateUpgradeRolloutStrategy(clusterSpec); err != nil {
return fmt.Errorf("failed setup and validations: %v", err)
}
// TODO(nutanix): Add validations when this is supported

return nil
}

// SetupAndValidateUpgradeManagementComponents performs necessary setup for upgrade management components operation.
func (p *Provider) SetupAndValidateUpgradeManagementComponents(_ context.Context, _ *cluster.Spec) error {
if err := setupEnvVars(p.datacenterConfig); err != nil {
return fmt.Errorf("failed setup and validations: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/providers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Provider interface {
SetupAndValidateCreateCluster(ctx context.Context, clusterSpec *cluster.Spec) error
SetupAndValidateDeleteCluster(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec) error
SetupAndValidateUpgradeCluster(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec, currentSpec *cluster.Spec) error
SetupAndValidateUpgradeManagementComponents(ctx context.Context, clusterSpec *cluster.Spec) error
UpdateSecrets(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec) error
GenerateCAPISpecForCreate(ctx context.Context, managementCluster *types.Cluster, clusterSpec *cluster.Spec) (controlPlaneSpec, workersSpec []byte, err error)
GenerateCAPISpecForUpgrade(ctx context.Context, bootstrapCluster, workloadCluster *types.Cluster, currrentSpec, newClusterSpec *cluster.Spec) (controlPlaneSpec, workersSpec []byte, err error)
Expand Down
5 changes: 5 additions & 0 deletions pkg/providers/snow/snow.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func (p *SnowProvider) SetupAndValidateUpgradeCluster(ctx context.Context, clust
return nil
}

// SetupAndValidateUpgradeManagementComponents performs necessary setup for upgrade management components operation.
func (p *SnowProvider) SetupAndValidateUpgradeManagementComponents(_ context.Context, _ *cluster.Spec) error {
return nil
}

func (p *SnowProvider) SetupAndValidateDeleteCluster(ctx context.Context, _ *types.Cluster, clusterSpec *cluster.Spec) error {
if err := SetupEksaCredentialsSecret(clusterSpec.Config); err != nil {
return fmt.Errorf("setting up credentials: %v", err)
Expand Down
5 changes: 5 additions & 0 deletions pkg/providers/tinkerbell/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (p *Provider) SetupAndValidateUpgradeCluster(ctx context.Context, cluster *
return nil
}

// SetupAndValidateUpgradeManagementComponents performs necessary setup for upgrade management components operation.
func (p *Provider) SetupAndValidateUpgradeManagementComponents(_ context.Context, _ *cluster.Spec) error {
return nil
}

func (p *Provider) validateAvailableHardwareForUpgrade(ctx context.Context, currentSpec, newClusterSpec *cluster.Spec) (err error) {
clusterSpecValidator := NewClusterSpecValidator(
HardwareSatisfiesOnlyOneSelectorAssertion(p.catalogue),
Expand Down
9 changes: 9 additions & 0 deletions pkg/providers/vsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,15 @@ func (p *vsphereProvider) SetupAndValidateUpgradeCluster(ctx context.Context, cl
return nil
}

// SetupAndValidateUpgradeManagementComponents performs necessary setup for upgrade management components operation.
func (p *vsphereProvider) SetupAndValidateUpgradeManagementComponents(ctx context.Context, clusterSpec *cluster.Spec) error {
if err := SetupEnvVars(clusterSpec.VSphereDatacenter); err != nil {
return fmt.Errorf("failed environment variable setup: %v", err)
}

return nil
}

func (p *vsphereProvider) validateMachineConfigsNameUniqueness(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec) error {
prevSpec, err := p.providerKubectlClient.GetEksaCluster(ctx, cluster, clusterSpec.Cluster.GetName())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/workflows/management/upgrade_management_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (s *setupAndValidateMC) Run(ctx context.Context, commandContext *task.Comma
runner.Register(
func() *validations.ValidationResult {
return &validations.ValidationResult{
Name: fmt.Sprintf("%s provider validation", commandContext.Provider.Name()),
Err: commandContext.Provider.SetupAndValidateUpgradeCluster(ctx, commandContext.ManagementCluster, commandContext.ClusterSpec, commandContext.CurrentClusterSpec),
Name: fmt.Sprintf("%s provider setup and validation", commandContext.Provider.Name()),
Err: commandContext.Provider.SetupAndValidateUpgradeManagementComponents(ctx, commandContext.ClusterSpec),
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestRunnerHappyPath(t *testing.T) {
gomock.InOrder(
mocks.validator.EXPECT().PreflightValidations(ctx).Return(nil),
mocks.provider.EXPECT().Name(),
mocks.provider.EXPECT().SetupAndValidateUpgradeCluster(ctx, gomock.Any(), newSpec, curSpec),
mocks.provider.EXPECT().SetupAndValidateUpgradeManagementComponents(ctx, newSpec),
mocks.provider.EXPECT().PreCoreComponentsUpgrade(gomock.Any(), gomock.Any(), newManagementComponents, gomock.Any()),
mocks.clientFactory.EXPECT().BuildClientFromKubeconfig(managementCluster.KubeconfigFile).Return(client, nil),
mocks.capiManager.EXPECT().Upgrade(ctx, managementCluster, mocks.provider, currentManagementComponents, newManagementComponents, newSpec).Return(capiChangeDiff, nil),
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestRunnerStopsWhenValidationFailed(t *testing.T) {
newSpec := test.NewClusterSpec()

mocks.provider.EXPECT().Name()
mocks.provider.EXPECT().SetupAndValidateUpgradeCluster(ctx, gomock.Any(), newSpec, curSpec)
mocks.provider.EXPECT().SetupAndValidateUpgradeManagementComponents(ctx, newSpec)
mocks.clusterManager.EXPECT().GetCurrentClusterSpec(ctx, gomock.Any(), managementCluster.Name).Return(curSpec, nil)
mocks.validator.EXPECT().PreflightValidations(ctx).Return(
[]validations.Validation{
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/cloudstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,12 @@ func TestCloudStackKubernetes129InstallGitFluxDuringUpgrade(t *testing.T) {
)
}

func TestCloudStackKubernetes128UpgradeManagementComponents(t *testing.T) {
release := latestMinorRelease(t)
provider := framework.NewCloudStack(t, framework.WithCloudStackRedhat9Kubernetes128())
runUpgradeManagementComponentsFlow(t, release, provider, v1alpha1.Kube128, framework.RedHat9)
}

// Labels
func TestCloudStackKubernetes125LabelsAndNodeNameRedhat(t *testing.T) {
test := framework.NewClusterE2ETest(
Expand Down
10 changes: 2 additions & 8 deletions test/e2e/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1358,14 +1358,8 @@ func TestDockerKubernetesRegionalCuratedPackages(t *testing.T) {

func TestDockerKubernetesUpgradeManagementComponents(t *testing.T) {
release := latestMinorRelease(t)
test := framework.NewClusterE2ETest(t, framework.NewDocker(t))

test.GenerateClusterConfig()
// create cluster with old eksa
test.CreateCluster(framework.ExecuteWithEksaRelease(release))
// upgrade management-components with new eksa
test.RunEKSA([]string{"upgrade", "management-components", "-f", test.ClusterConfigLocation, "-v", "99"})
test.DeleteCluster()
provider := framework.NewDocker(t)
runUpgradeManagementComponentsFlow(t, release, provider, v1alpha1.Kube128, "")
}

// etcd scale tests
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/tinkerbell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1478,3 +1478,30 @@ func TestTinkerbellSingleNode127To128UbuntuManagementCPUpgradeAPI(t *testing.T)
provider.WithKubeVersionAndOS(v1alpha1.Kube128, framework.Ubuntu2004, nil),
)
}

func TestTinkerbellKubernetes128UpgradeManagementComponents(t *testing.T) {
release := latestMinorRelease(t)
provider := framework.NewTinkerbell(t, framework.WithUbuntu128Tinkerbell())
test := framework.NewClusterE2ETest(
t,
provider,
framework.WithControlPlaneHardware(1),
framework.WithWorkerHardware(1),
)
// create cluster with old eksa
test.GenerateClusterConfigForVersion(release.Version, framework.ExecuteWithEksaRelease(release))
test.UpdateClusterConfig(
api.ClusterToConfigFiller(
api.WithKubernetesVersion(v1alpha1.Kube128),
api.WithControlPlaneCount(1),
api.WithWorkerNodeCount(1),
),
provider.WithKubeVersionAndOS(v1alpha1.Kube128, framework.Ubuntu2004, nil),
)

test.GenerateHardwareConfig(framework.ExecuteWithEksaRelease(release))
test.CreateCluster(framework.ExecuteWithEksaRelease(release), framework.WithControlPlaneWaitTimeout("20m"))
// upgrade management-components with new eksa
test.RunEKSA([]string{"upgrade", "management-components", "-f", test.ClusterConfigLocation, "-v", "99"})
test.DeleteCluster()
}
19 changes: 19 additions & 0 deletions test/e2e/upgrade_from_latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,22 @@ func runMulticlusterUpgradeFromReleaseFlowAPIWithFlux(test *framework.Multiclust

test.DeleteManagementCluster()
}

func runUpgradeManagementComponentsFlow(t *testing.T, release *releasev1.EksARelease, provider framework.Provider, kubeVersion anywherev1.KubernetesVersion, os framework.OS) {
test := framework.NewClusterE2ETest(t, provider)
// create cluster with old eksa
test.GenerateClusterConfigForVersion(release.Version, framework.ExecuteWithEksaRelease(release))
test.UpdateClusterConfig(
api.ClusterToConfigFiller(
api.WithKubernetesVersion(kubeVersion),
api.WithControlPlaneCount(1),
api.WithWorkerNodeCount(1),
),
provider.WithKubeVersionAndOS(kubeVersion, os, release),
)

test.CreateCluster(framework.ExecuteWithEksaRelease(release))
// upgrade management-components with new eksa
test.RunEKSA([]string{"upgrade", "management-components", "-f", test.ClusterConfigLocation, "-v", "99"})
test.DeleteCluster()
}
6 changes: 6 additions & 0 deletions test/e2e/vsphere_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,12 @@ func TestVSphereKubernetes128UbuntuInPlaceWorkerScaleDown2To1(t *testing.T) {
)
}

func TestVSphereKubernetes128UpgradeManagementComponents(t *testing.T) {
release := latestMinorRelease(t)
provider := framework.NewVSphere(t, framework.WithUbuntu128())
runUpgradeManagementComponentsFlow(t, release, provider, v1alpha1.Kube128, framework.Ubuntu2004)
}

// Workload API
func TestVSphereMulticlusterWorkloadClusterAPI(t *testing.T) {
vsphere := framework.NewVSphere(t)
Expand Down

0 comments on commit 8fc5000

Please sign in to comment.