Skip to content

Commit

Permalink
fix lint and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tatlat committed Mar 21, 2024
1 parent 355fad8 commit 5361066
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
6 changes: 4 additions & 2 deletions pkg/dependencies/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,9 +1317,10 @@ func (f *Factory) WithPackageInstaller(spec *cluster.Spec, packagesLocation, kub
return f
}

// WithPackageInstallerWithoutWait builds a package installer that doesn't wait for active bundles.
func (f *Factory) WithPackageInstallerWithoutWait(spec *cluster.Spec, packagesLocation, kubeConfig string) *Factory {
f.WithKubectl().WithPackageControllerClientWithoutWait(spec, kubeConfig).WithPackageClient()
f.buildSteps = append(f.buildSteps, func(ctx context.Context) error {
f.buildSteps = append(f.buildSteps, func(_ context.Context) error {
if f.dependencies.PackageInstaller != nil {
return nil
}
Expand Down Expand Up @@ -1393,10 +1394,11 @@ func (f *Factory) WithPackageControllerClient(spec *cluster.Spec, kubeConfig str
return f
}

// WithPackageInstallerWithoutWait builds a package controller client that doesn't wait for active bundles.

Check warning on line 1397 in pkg/dependencies/factory.go

View workflow job for this annotation

GitHub Actions / lint

exported: comment on exported method Factory.WithPackageControllerClientWithoutWait should be of the form "WithPackageControllerClientWithoutWait ..." (revive)
func (f *Factory) WithPackageControllerClientWithoutWait(spec *cluster.Spec, kubeConfig string) *Factory {
f.WithHelm(helm.WithInsecure()).WithKubectl()

f.buildSteps = append(f.buildSteps, func(ctx context.Context) error {
f.buildSteps = append(f.buildSteps, func(_ context.Context) error {
if f.dependencies.PackageControllerClient != nil || spec == nil {
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/workflows/management/post_cluster_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func (s *postClusterUpgrade) Run(ctx context.Context, commandContext *task.Comma
logger.Info(fmt.Sprintf("management cluster CAPI backup file not found: %v", err))
}

return &upgradeCuratedPackagesTask{}
if commandContext.CurrentClusterSpec.Cluster.Spec.RegistryMirrorConfiguration != commandContext.ClusterSpec.Cluster.Spec.RegistryMirrorConfiguration {
return &upgradeCuratedPackagesTask{}
}

return nil
}

func (s *postClusterUpgrade) Name() string {
Expand Down
5 changes: 3 additions & 2 deletions pkg/workflows/management/upgrade_curated_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

appsv1 "k8s.io/api/apps/v1"

"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/task"
"github.com/aws/eks-anywhere/pkg/utils/ptr"
)
Expand All @@ -21,7 +22,7 @@ func (s *upgradeCuratedPackagesTask) Run(ctx context.Context, commandContext *ta

packagesManager := &appsv1.Deployment{}

err = client.Get(ctx, "eks-anywhere-packages", "eksa-packages", packagesManager)
err = client.Get(ctx, "eks-anywhere-packages", constants.EksaPackagesName, packagesManager)
if err != nil {
commandContext.SetError(err)
}
Expand Down Expand Up @@ -50,7 +51,7 @@ func (s *upgradeCuratedPackagesTask) Name() string {
return "install-curated-packages"
}

func (s *upgradeCuratedPackagesTask) Restore(ctx context.Context, commandContext *task.CommandContext, completedTask *task.CompletedTask) (task.Task, error) {
func (s *upgradeCuratedPackagesTask) Restore(_ context.Context, _ *task.CommandContext, _ *task.CompletedTask) (task.Task, error) {
return nil, nil
}

Expand Down
47 changes: 44 additions & 3 deletions pkg/workflows/management/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (

"github.com/golang/mock/gomock"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/aws/eks-anywhere/internal/test"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/clients/kubernetes"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/features"
writermocks "github.com/aws/eks-anywhere/pkg/filewriter/mocks"
"github.com/aws/eks-anywhere/pkg/providers"
Expand Down Expand Up @@ -312,9 +314,9 @@ func (c *upgradeManagementTestSetup) expectPreflightValidationsToPass() {
c.validator.EXPECT().PreflightValidations(c.ctx).Return(nil)
}

func (c *upgradeManagementTestSetup) expectPackagesUpgrade(err1, err2 error) {
c.packagesInstaller.EXPECT().InstallCuratedPackages(c.ctx).Return(err1)
c.clientFactory.EXPECT().BuildClientFromKubeconfig(c.managementCluster.KubeconfigFile).Return(c.client, err2)
func (c *upgradeManagementTestSetup) expectPackagesUpgrade(err error) {
c.packagesInstaller.EXPECT().InstallCuratedPackages(c.ctx)
c.clientFactory.EXPECT().BuildClientFromKubeconfig(c.managementCluster.KubeconfigFile).Return(c.client, err)
}

func TestUpgradeManagementRunUpdateSetupFailed(t *testing.T) {
Expand Down Expand Up @@ -739,6 +741,45 @@ func TestUpgradeManagementRunResumeClusterResourcesReconcileFailed(t *testing.T)
}
}

func TestUpgradeManagementRunSuccessUpgradeCuratedPackagesSuccess(t *testing.T) {
os.Unsetenv(features.CheckpointEnabledEnvVar)
features.ClearCache()
tt := newUpgradeManagementClusterTest(t)
tt.newClusterSpec.Cluster.Spec.RegistryMirrorConfiguration = &v1alpha1.RegistryMirrorConfiguration{}
packagesManager := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "eks-anywhere-packages",
Namespace: constants.EksaPackagesName,
},
}
tt.client = test.NewFakeKubeClient(tt.currentClusterSpec.Cluster, tt.currentClusterSpec.EKSARelease, tt.currentClusterSpec.Bundles, packagesManager)
tt.expectSetup()
tt.expectPreflightValidationsToPass()
tt.expectUpdateSecrets(nil)
tt.expectEnsureManagementEtcdCAPIComponentsExist(nil)
tt.expectUpgradeCoreComponents()
tt.expectPauseGitOpsReconcile(nil)
tt.expectBackupManagementFromCluster(nil)
tt.expectPauseCAPIWorkloadClusters(nil)
tt.expectDatacenterConfig()
tt.expectMachineConfigs()
tt.expectInstallEksdManifest(nil)
tt.expectApplyBundles(nil)
tt.expectApplyReleases(nil)
tt.expectUpgradeManagementCluster()
tt.expectResumeCAPIWorkloadClustersAPI(nil)
tt.expectUpdateGitEksaSpec(nil)
tt.expectForceReconcileGitRepo(nil)
tt.expectResumeGitOpsReconcile(nil)
tt.expectWriteManagementClusterConfig(nil)
tt.expectPackagesUpgrade(nil)

err := tt.run()
if err != nil {
t.Fatalf("UpgradeManagement.Run() err = %v, want err = nil", err)
}
}

func TestUpgradeManagementRunSuccess(t *testing.T) {
os.Unsetenv(features.CheckpointEnabledEnvVar)
features.ClearCache()
Expand Down

0 comments on commit 5361066

Please sign in to comment.