Skip to content

Commit

Permalink
Revert "Remove feature flag for controller via CLI (#7546)" (#7554)
Browse files Browse the repository at this point in the history
This reverts commit 1034e51.
  • Loading branch information
mitalipaygude authored Feb 12, 2024
1 parent 4de7cda commit 43ef11f
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 2 deletions.
17 changes: 16 additions & 1 deletion cmd/eksctl-anywhere/cmd/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/aws/eks-anywhere/pkg/validations"
"github.com/aws/eks-anywhere/pkg/validations/createvalidations"
newManagement "github.com/aws/eks-anywhere/pkg/workflow/management"
"github.com/aws/eks-anywhere/pkg/workflows"
"github.com/aws/eks-anywhere/pkg/workflows/management"
"github.com/aws/eks-anywhere/pkg/workflows/workload"
)
Expand Down Expand Up @@ -207,6 +208,17 @@ func (cc *createClusterOptions) createCluster(cmd *cobra.Command, _ []string) er
return err
}

createCluster := workflows.NewCreate(
deps.UnAuthKubeClient,
deps.Bootstrapper,
deps.Provider,
deps.ClusterManager,
deps.GitOpsFlux,
deps.Writer,
deps.EksdInstaller,
deps.PackageInstaller,
)

mgmt := getManagementCluster(clusterSpec)

validationOpts := &validations.Opts{
Expand Down Expand Up @@ -261,8 +273,9 @@ func (cc *createClusterOptions) createCluster(cmd *cobra.Command, _ []string) er
)
err = createWorkloadCluster.Run(ctx, clusterSpec, createValidations)

} else if clusterSpec.Cluster.IsSelfManaged() {
} else if clusterSpec.Cluster.IsSelfManaged() && features.UseControllerViaCLIWorkflow().IsActive() {
logger.Info("Using the new workflow using the controller for management cluster create")

createMgmtCluster := management.NewCreate(
deps.Bootstrapper,
deps.Provider,
Expand All @@ -276,6 +289,8 @@ func (cc *createClusterOptions) createCluster(cmd *cobra.Command, _ []string) er
)

err = createMgmtCluster.Run(ctx, clusterSpec, createValidations)
} else {
err = createCluster.Run(ctx, clusterSpec, createValidations, cc.forceClean)
}

cleanup(deps, &err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/eksctl-anywhere/cmd/deletecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"

"github.com/aws/eks-anywhere/pkg/dependencies"
"github.com/aws/eks-anywhere/pkg/features"
"github.com/aws/eks-anywhere/pkg/kubeconfig"
"github.com/aws/eks-anywhere/pkg/logger"
"github.com/aws/eks-anywhere/pkg/providers/tinkerbell/hardware"
Expand Down Expand Up @@ -155,7 +156,7 @@ func (dc *deleteClusterOptions) deleteCluster(ctx context.Context) error {
}
}

if clusterSpec.Cluster.IsManaged() {
if features.UseControllerViaCLIWorkflow().IsActive() && clusterSpec.Cluster.IsManaged() {
deleteWorkload := workload.NewDelete(deps.Provider, deps.Writer, deps.ClusterManager, deps.ClusterDeleter, deps.GitOpsFlux)
err = deleteWorkload.Run(ctx, cluster, clusterSpec)
} else {
Expand Down
9 changes: 9 additions & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
CloudStackKubeVipDisabledEnvVar = "CLOUDSTACK_KUBE_VIP_DISABLED"
CheckpointEnabledEnvVar = "CHECKPOINT_ENABLED"
UseNewWorkflowsEnvVar = "USE_NEW_WORKFLOWS"
UseControllerForCli = "USE_CONTROLLER_FOR_CLI"
K8s129SupportEnvVar = "K8S_1_29_SUPPORT"
VSphereInPlaceEnvVar = "VSPHERE_IN_PLACE_UPGRADE"
)
Expand Down Expand Up @@ -48,6 +49,14 @@ func UseNewWorkflows() Feature {
}
}

// UseControllerViaCLIWorkflow is used for the controller behind the CLI workflow.
func UseControllerViaCLIWorkflow() Feature {
return Feature{
Name: "Use new workflow logic for cluster operations leveraging controller via CLI",
IsActive: globalFeatures.isActiveForEnvVar(UseControllerForCli),
}
}

// K8s129Support is the feature flag for Kubernetes 1.29 support.
func K8s129Support() Feature {
return Feature{
Expand Down
16 changes: 16 additions & 0 deletions pkg/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ func TestIsActiveWithFeatureGatesTrue(t *testing.T) {
g.Expect(IsActive(fakeFeatureWithGate())).To(BeTrue())
}

func TestUseControllerForCliFalse(t *testing.T) {
g := NewWithT(t)
setupContext(t)

t.Setenv(UseControllerForCli, "false")
g.Expect(UseControllerViaCLIWorkflow().IsActive()).To(BeFalse())
}

func TestUseControllerForCliTrue(t *testing.T) {
g := NewWithT(t)
setupContext(t)

t.Setenv(UseControllerForCli, "true")
g.Expect(UseControllerViaCLIWorkflow().IsActive()).To(BeTrue())
}

func TestWithK8s129FeatureFlag(t *testing.T) {
g := NewWithT(t)
setupContext(t)
Expand Down
7 changes: 7 additions & 0 deletions pkg/workflows/management/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/aws/eks-anywhere/pkg/bootstrapper"
clientmocks "github.com/aws/eks-anywhere/pkg/clients/kubernetes/mocks"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/features"
writermocks "github.com/aws/eks-anywhere/pkg/filewriter/mocks"
"github.com/aws/eks-anywhere/pkg/logger"
"github.com/aws/eks-anywhere/pkg/providers"
Expand Down Expand Up @@ -46,6 +47,8 @@ type createTestSetup struct {
}

func newCreateTest(t *testing.T) *createTestSetup {
featureEnvVars := []string{}
featureEnvVars = append(featureEnvVars, features.UseControllerForCli)
mockCtrl := gomock.NewController(t)
bootstrapper := mocks.NewMockBootstrapper(mockCtrl)
clusterManager := mocks.NewMockClusterManager(mockCtrl)
Expand Down Expand Up @@ -75,6 +78,10 @@ func newCreateTest(t *testing.T) *createTestSetup {
eksaInstaller,
)

for _, e := range featureEnvVars {
t.Setenv(e, "true")
}

clusterSpec := test.NewClusterSpec(func(s *cluster.Spec) { s.Cluster.Name = "test-cluster" })
managementComponents := cluster.ManagementComponentsFromBundles(clusterSpec.Bundles)

Expand Down
12 changes: 12 additions & 0 deletions pkg/workflows/workload/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workload_test
import (
"context"
"fmt"
"os"
"strings"
"testing"

Expand All @@ -11,6 +12,7 @@ import (
"github.com/aws/eks-anywhere/internal/test"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/features"
writermocks "github.com/aws/eks-anywhere/pkg/filewriter/mocks"
"github.com/aws/eks-anywhere/pkg/providers"
providermocks "github.com/aws/eks-anywhere/pkg/providers/mocks"
Expand Down Expand Up @@ -147,6 +149,8 @@ func (c *createTestSetup) expectWrite() {
}

func TestCreateRunSuccess(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newCreateTest(t)
test.expectSetup()
test.expectPreflightValidationsToPass()
Expand All @@ -163,6 +167,8 @@ func TestCreateRunSuccess(t *testing.T) {
}

func TestCreateRunFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newCreateTest(t)
test.expectSetup()
test.expectPreflightValidationsToPass()
Expand All @@ -178,6 +184,8 @@ func TestCreateRunFail(t *testing.T) {
}

func TestCreateRunValidateFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newCreateTest(t)
test.provider.EXPECT().Name()
test.gitOpsManager.EXPECT().Validations(test.ctx, test.clusterSpec)
Expand All @@ -192,6 +200,8 @@ func TestCreateRunValidateFail(t *testing.T) {
}

func TestCreateRunGitOpsConfigFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newCreateTest(t)
test.expectSetup()
test.expectPreflightValidationsToPass()
Expand All @@ -208,6 +218,8 @@ func TestCreateRunGitOpsConfigFail(t *testing.T) {
}

func TestCreateRunWriteClusterConfigFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newCreateTest(t)
test.expectSetup()
test.expectPreflightValidationsToPass()
Expand Down
10 changes: 10 additions & 0 deletions pkg/workflows/workload/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package workload_test
import (
"context"
"fmt"
"os"
"testing"

"github.com/golang/mock/gomock"

"github.com/aws/eks-anywhere/internal/test"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/features"
writermocks "github.com/aws/eks-anywhere/pkg/filewriter/mocks"
"github.com/aws/eks-anywhere/pkg/providers"
providermocks "github.com/aws/eks-anywhere/pkg/providers/mocks"
Expand Down Expand Up @@ -106,6 +108,8 @@ func (c *deleteTestSetup) expectCleanup(err error) {
}

func TestDeleteRunSuccess(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newDeleteTest(t)
test.expectSetup(nil)
test.expectDeleteWorkloadCluster(nil)
Expand All @@ -118,6 +122,8 @@ func TestDeleteRunSuccess(t *testing.T) {
}

func TestDeleteRunFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newDeleteTest(t)
test.expectSetup(nil)
test.expectDeleteWorkloadCluster(fmt.Errorf("Failure"))
Expand All @@ -130,6 +136,8 @@ func TestDeleteRunFail(t *testing.T) {
}

func TestDeleteRunFailSetup(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newDeleteTest(t)
test.expectSetup(fmt.Errorf("Failure"))
test.expectWrite()
Expand All @@ -141,6 +149,8 @@ func TestDeleteRunFailSetup(t *testing.T) {
}

func TestDeleteRunFailCleanup(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newDeleteTest(t)
test.expectSetup(nil)
test.expectDeleteWorkloadCluster(nil)
Expand Down
14 changes: 14 additions & 0 deletions pkg/workflows/workload/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"testing"
"time"

Expand All @@ -12,6 +13,7 @@ import (
"github.com/aws/eks-anywhere/internal/test"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/features"
writermocks "github.com/aws/eks-anywhere/pkg/filewriter/mocks"
"github.com/aws/eks-anywhere/pkg/providers"
providermocks "github.com/aws/eks-anywhere/pkg/providers/mocks"
Expand Down Expand Up @@ -155,6 +157,8 @@ func (c *upgradeTestSetup) expectWrite() {
}

func TestUpgradeRunSuccess(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newUpgradeTest(t)
test.expectSetup()
test.expectPreflightValidationsToPass()
Expand All @@ -171,6 +175,8 @@ func TestUpgradeRunSuccess(t *testing.T) {
}

func TestUpgradeRunUpgradeFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newUpgradeTest(t)
test.expectSetup()
test.expectPreflightValidationsToPass()
Expand All @@ -187,6 +193,8 @@ func TestUpgradeRunUpgradeFail(t *testing.T) {
}

func TestUpgradeRunGetCurrentClusterSpecFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newUpgradeTest(t)
test.clusterManager.EXPECT().GetCurrentClusterSpec(test.ctx, test.clusterSpec.ManagementCluster, test.clusterSpec.Cluster.Name).Return(nil, fmt.Errorf("boom"))
test.expectWrite()
Expand All @@ -198,6 +206,8 @@ func TestUpgradeRunGetCurrentClusterSpecFail(t *testing.T) {
}

func TestUpgradeRunValidateFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newUpgradeTest(t)
test.clusterManager.EXPECT().GetCurrentClusterSpec(test.ctx, test.clusterSpec.ManagementCluster, test.clusterSpec.Cluster.Name).AnyTimes().Return(test.currentClusterSpec, nil)
test.provider.EXPECT().Name().AnyTimes()
Expand All @@ -213,6 +223,8 @@ func TestUpgradeRunValidateFail(t *testing.T) {
}

func TestUpgradeWorkloadRunBackupFailed(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newUpgradeTest(t)
test.expectSetup()
test.expectPreflightValidationsToPass()
Expand All @@ -228,6 +240,8 @@ func TestUpgradeWorkloadRunBackupFailed(t *testing.T) {
}

func TestUpgradeRunWriteClusterConfigFail(t *testing.T) {
features.ClearCache()
os.Setenv(features.UseControllerForCli, "true")
test := newUpgradeTest(t)
test.expectSetup()
test.expectPreflightValidationsToPass()
Expand Down

0 comments on commit 43ef11f

Please sign in to comment.