Skip to content

Commit

Permalink
Skip generating AWS IAM Kubeconfig on cluster upgrade (#8851)
Browse files Browse the repository at this point in the history
* Skip generating AWS IAM kubeconfig on cluster upgrade

* Added unit test to validate GenerateAWSIAMKubeconfig is not called

* fix: update method name

Co-authored-by: Vivek Koppuru <[email protected]>

* fix: update method name

---------

Co-authored-by: Vivek Koppuru <[email protected]>
  • Loading branch information
jhaanvi5 and vivek-koppuru authored Oct 17, 2024
1 parent e93b1ef commit b1ebe82
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions pkg/workflows/workload/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ func (c *upgradeTestSetup) expectWriteWorkloadClusterConfig(err error) {
)
}

func (c *upgradeTestSetup) expectWithoutAWSIAMAuthKubeconfig(err error) {
c.clusterManager.EXPECT().GenerateAWSIAMKubeconfig(
c.ctx, c.clusterSpec.ManagementCluster).Return(err).Times(0)
}

func (c *upgradeTestSetup) expectDatacenterConfig() {
gomock.InOrder(
c.provider.EXPECT().DatacenterConfig(c.clusterSpec).Return(c.datacenterConfig).AnyTimes(),
Expand Down Expand Up @@ -189,6 +194,26 @@ func TestUpgradeRunSuccess(t *testing.T) {
}
}

func TestUpgradeRunWithAWSIAMSuccess(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newUpgradeTest(t)
test.clusterSpec.AWSIamConfig = &v1alpha1.AWSIamConfig{}
test.expectSetup()
test.expectPreflightValidationsToPass()
test.expectDatacenterConfig()
test.expectMachineConfigs()
test.expectBackupWorkloadFromCluster(nil)
test.expectUpgradeWorkloadCluster(nil)
test.expectBuildClientFromKubeconfig(nil)
test.expectWriteWorkloadClusterConfig(nil)
test.expectWithoutAWSIAMAuthKubeconfig(nil)
err := test.run()
if err != nil {
t.Fatalf("Upgrade.Run() err = %v, want err = nil", err)
}
}

func TestUpgradeRunUpgradeFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
Expand Down
3 changes: 2 additions & 1 deletion pkg/workflows/workload/writeclusterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func (s *writeClusterConfig) Run(ctx context.Context, commandContext *task.Comma

}

if commandContext.ClusterSpec.AWSIamConfig != nil {
// Generate AWS IAM kubeconfig only for cluster creation step
if commandContext.CurrentClusterSpec == nil && commandContext.ClusterSpec.AWSIamConfig != nil {
logger.Info("Generating the aws iam kubeconfig file")
err = commandContext.ClusterManager.GenerateAWSIAMKubeconfig(ctx, commandContext.ManagementCluster)
if err != nil {
Expand Down

0 comments on commit b1ebe82

Please sign in to comment.