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 5361066 commit ae0a388
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 2 deletions.
49 changes: 49 additions & 0 deletions pkg/curatedpackages/packagecontrollerclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,55 @@ func TestEnableWithEmptyProxy(t *testing.T) {
}
}

func TestEnableWithSkipWait(t *testing.T) {
for _, tt := range newPackageControllerTests(t) {
tt.command = curatedpackages.NewPackageControllerClient(
tt.chartManager, tt.kubectl, "billy", tt.kubeConfig, tt.chart,
tt.registryMirror,
curatedpackages.WithEksaSecretAccessKey(tt.eksaAccessKey),
curatedpackages.WithEksaRegion(tt.eksaRegion),
curatedpackages.WithEksaAccessKeyId(tt.eksaAccessID),
curatedpackages.WithSkipWait(),
curatedpackages.WithManagementClusterName(tt.clusterName),
curatedpackages.WithValuesFileWriter(tt.writer),
)
clusterName := fmt.Sprintf("clusterName=%s", "billy")
valueFilePath := filepath.Join("billy", filewriter.DefaultTmpFolder, valueFileName)
ociURI := fmt.Sprintf("%s%s", "oci://", tt.registryMirror.ReplaceRegistry(tt.chart.Image()))
sourceRegistry, defaultRegistry, defaultImageRegistry := tt.command.GetCuratedPackagesRegistries(context.Background())
sourceRegistry = fmt.Sprintf("sourceRegistry=%s", sourceRegistry)
defaultRegistry = fmt.Sprintf("defaultRegistry=%s", defaultRegistry)
defaultImageRegistry = fmt.Sprintf("defaultImageRegistry=%s", defaultImageRegistry)
if tt.registryMirror != nil {
t.Setenv("REGISTRY_USERNAME", "username")
t.Setenv("REGISTRY_PASSWORD", "password")
} else {
if tt.eksaRegion == "" {
tt.eksaRegion = "us-west-2"
}
defaultImageRegistry = strings.ReplaceAll(defaultImageRegistry, "us-west-2", tt.eksaRegion)
}
values := []string{sourceRegistry, defaultRegistry, defaultImageRegistry, clusterName}
if (tt.eksaAccessID == "" || tt.eksaAccessKey == "") && tt.registryMirror == nil {
values = append(values, "cronjob.suspend=true")
}
tt.chartManager.EXPECT().InstallChart(tt.ctx, tt.chart.Name, ociURI, tt.chart.Tag(), tt.kubeConfig, constants.EksaPackagesName, valueFilePath, false, values).Return(nil)
tt.kubectl.EXPECT().
GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(getPBCSuccess(t)).
AnyTimes()
tt.kubectl.EXPECT().
HasResource(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(func(_, _, _, _, _ interface{}) (bool, error) { return true, nil }).
AnyTimes()

err := tt.command.Enable(tt.ctx)
if err != nil {
t.Errorf("Install Controller Should succeed when installation passes")
}
}
}

func TestEnableFail(t *testing.T) {
for _, tt := range newPackageControllerTests(t) {
clusterName := fmt.Sprintf("clusterName=%s", "billy")
Expand Down
2 changes: 1 addition & 1 deletion pkg/dependencies/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ func (f *Factory) WithPackageControllerClient(spec *cluster.Spec, kubeConfig str
return f
}

// WithPackageInstallerWithoutWait builds a package controller client that doesn't wait for active bundles.
// WithPackageControllerClientWithoutWait builds a package controller client that doesn't wait for active bundles.
func (f *Factory) WithPackageControllerClientWithoutWait(spec *cluster.Spec, kubeConfig string) *Factory {
f.WithHelm(helm.WithInsecure()).WithKubectl()

Expand Down
4 changes: 4 additions & 0 deletions pkg/workflows/management/upgrade_curated_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/task"
"github.com/aws/eks-anywhere/pkg/utils/ptr"
"github.com/aws/eks-anywhere/pkg/workflows"
)

type upgradeCuratedPackagesTask struct{}
Expand All @@ -25,13 +26,15 @@ func (s *upgradeCuratedPackagesTask) Run(ctx context.Context, commandContext *ta
err = client.Get(ctx, "eks-anywhere-packages", constants.EksaPackagesName, packagesManager)
if err != nil {
commandContext.SetError(err)
return &workflows.CollectMgmtClusterDiagnosticsTask{}
}

replicas := packagesManager.Spec.Replicas
packagesManager.Spec.Replicas = ptr.Int32(0)
err = client.Update(ctx, packagesManager)
if err != nil {
commandContext.SetError(err)
return &workflows.CollectMgmtClusterDiagnosticsTask{}
}

packagesManager.Spec.Replicas = replicas
Expand All @@ -42,6 +45,7 @@ func (s *upgradeCuratedPackagesTask) Run(ctx context.Context, commandContext *ta
err = client.Update(ctx, packagesManager)
if err != nil {
commandContext.SetError(err)
return &workflows.CollectMgmtClusterDiagnosticsTask{}
}

return nil
Expand Down
77 changes: 76 additions & 1 deletion pkg/workflows/management/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,82 @@ func TestUpgradeManagementRunResumeClusterResourcesReconcileFailed(t *testing.T)
}
}

func TestUpgradeManagementRunSuccessUpgradeCuratedPackagesSuccess(t *testing.T) {
func TestUpgradeManagementRunUpgradePackagesFailGetDeployment(t *testing.T) {
os.Unsetenv(features.CheckpointEnabledEnvVar)
features.ClearCache()
tt := newUpgradeManagementClusterTest(t)
tt.newClusterSpec.Cluster.Spec.RegistryMirrorConfiguration = &v1alpha1.RegistryMirrorConfiguration{}
tt.client = test.NewFakeKubeClient(tt.currentClusterSpec.Cluster, tt.currentClusterSpec.EKSARelease, tt.currentClusterSpec.Bundles)
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)
tt.expectSaveLogs()
tt.expectWriteCheckpointFile()

err := tt.run()
if err == nil {
t.Fatal("UpgradeManagement.Run() err = nil, want err not nil")
}
}

func TestUpgradeManagementRunUpgradePackagesFailBuildClient(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(fmt.Errorf(""))
tt.expectWriteCheckpointFile()

err := tt.run()
if err == nil {
t.Fatal("UpgradeManagement.Run() err = nil, want err not nil")
}
}

func TestUpgradeManagementRunUpgradeCuratedPackagesSuccess(t *testing.T) {
os.Unsetenv(features.CheckpointEnabledEnvVar)
features.ClearCache()
tt := newUpgradeManagementClusterTest(t)
Expand Down

0 comments on commit ae0a388

Please sign in to comment.