Skip to content

Commit

Permalink
Add feature flag for Kubernetes v1.29 support (#7113)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna authored Dec 1, 2023
1 parent 6028fe5 commit 6dfb892
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/api/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ const (
Kube126 KubernetesVersion = "1.26"
Kube127 KubernetesVersion = "1.27"
Kube128 KubernetesVersion = "1.28"
Kube129 KubernetesVersion = "1.29"
)

// KubeVersionToSemver converts kube version to semver for comparisons.
Expand Down
9 changes: 9 additions & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const (
CheckpointEnabledEnvVar = "CHECKPOINT_ENABLED"
UseNewWorkflowsEnvVar = "USE_NEW_WORKFLOWS"
UseControllerForCli = "USE_CONTROLLER_FOR_CLI"
K8s129SupportEnvVar = "K8S_1_29_SUPPORT"
)

func FeedGates(featureGates []string) {

Check warning on line 12 in pkg/features/features.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported function FeedGates should have comment or be unexported (revive)
Expand Down Expand Up @@ -54,3 +55,11 @@ func UseControllerViaCLIWorkflow() Feature {
IsActive: globalFeatures.isActiveForEnvVar(UseControllerForCli),
}
}

// K8s129Support is the feature flag for Kubernetes 1.29 support.
func K8s129Support() Feature {
return Feature{
Name: "Kubernetes version 1.29 support",
IsActive: globalFeatures.isActiveForEnvVar(K8s129SupportEnvVar),
}
}
8 changes: 8 additions & 0 deletions pkg/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,11 @@ func TestUseControllerForCliTrue(t *testing.T) {
t.Setenv(UseControllerForCli, "true")
g.Expect(UseControllerViaCLIWorkflow().IsActive()).To(BeTrue())
}

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

g.Expect(os.Setenv(K8s129SupportEnvVar, "true")).To(Succeed())
g.Expect(IsActive(K8s129Support())).To(BeTrue())
}
11 changes: 11 additions & 0 deletions pkg/validations/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/config"
"github.com/aws/eks-anywhere/pkg/features"
"github.com/aws/eks-anywhere/pkg/logger"
"github.com/aws/eks-anywhere/pkg/providers"
"github.com/aws/eks-anywhere/pkg/semver"
Expand Down Expand Up @@ -204,3 +205,13 @@ func parseClusterEksaVersion(mgmtCluster, cluster *v1alpha1.Cluster) (*semver.Ve

return mVersion, wVersion, nil
}

// ValidateK8s129Support checks if the 1.29 feature flag is set when using k8s 1.29.
func ValidateK8s129Support(clusterSpec *cluster.Spec) error {
if !features.IsActive(features.K8s129Support()) {
if clusterSpec.Cluster.Spec.KubernetesVersion == v1alpha1.Kube129 {
return fmt.Errorf("kubernetes version %s is not enabled. Please set the env variable %v", v1alpha1.Kube129, features.K8s129SupportEnvVar)
}
}
return nil
}
16 changes: 16 additions & 0 deletions pkg/validations/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/aws/eks-anywhere/internal/test"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/features"
"github.com/aws/eks-anywhere/pkg/providers"
providermocks "github.com/aws/eks-anywhere/pkg/providers/mocks"
"github.com/aws/eks-anywhere/pkg/types"
Expand Down Expand Up @@ -508,3 +509,18 @@ func TestValidateManagementClusterEksaVersion(t *testing.T) {
})
}
}

func TestValidateK8s129Support(t *testing.T) {
tt := newTest(t)
tt.clusterSpec.Cluster.Spec.KubernetesVersion = anywherev1.Kube129
tt.Expect(validations.ValidateK8s129Support(tt.clusterSpec)).To(
MatchError(ContainSubstring("kubernetes version 1.29 is not enabled. Please set the env variable K8S_1_29_SUPPORT")))
}

func TestValidateK8s129SupportActive(t *testing.T) {
tt := newTest(t)
tt.clusterSpec.Cluster.Spec.KubernetesVersion = anywherev1.Kube129
features.ClearCache()
os.Setenv(features.K8s129SupportEnvVar, "true")
tt.Expect(validations.ValidateK8s129Support(tt.clusterSpec)).To(Succeed())
}
9 changes: 9 additions & 0 deletions pkg/validations/createvalidations/preflightvalidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/config"
"github.com/aws/eks-anywhere/pkg/features"
"github.com/aws/eks-anywhere/pkg/types"
"github.com/aws/eks-anywhere/pkg/validations"
)
Expand Down Expand Up @@ -48,6 +49,14 @@ func (v *CreateValidations) PreflightValidations(ctx context.Context) []validati
Err: validations.ValidateEksaVersion(ctx, v.Opts.CliVersion, v.Opts.Spec),
}
},
func() *validations.ValidationResult {
return &validations.ValidationResult{
Name: "validate kubernetes version 1.29 support",
Remediation: fmt.Sprintf("ensure %v env variable is set", features.K8s129SupportEnvVar),
Err: validations.ValidateK8s129Support(v.Opts.Spec),
Silent: true,
}
},
}

if v.Opts.Spec.Cluster.IsManaged() {
Expand Down
9 changes: 9 additions & 0 deletions pkg/validations/upgradevalidations/preflightvalidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/config"
"github.com/aws/eks-anywhere/pkg/features"
"github.com/aws/eks-anywhere/pkg/providers"
"github.com/aws/eks-anywhere/pkg/types"
"github.com/aws/eks-anywhere/pkg/validation"
Expand Down Expand Up @@ -113,6 +114,14 @@ func (u *UpgradeValidations) PreflightValidations(ctx context.Context) []validat
Err: validations.ValidateEksaVersion(ctx, u.Opts.CliVersion, u.Opts.Spec),
}
},
func() *validations.ValidationResult {
return &validations.ValidationResult{
Name: "validate kubernetes version 1.29 support",
Remediation: fmt.Sprintf("ensure %v env variable is set", features.K8s129SupportEnvVar),
Err: validations.ValidateK8s129Support(u.Opts.Spec),
Silent: true,
}
},
}

if u.Opts.Spec.Cluster.IsManaged() {
Expand Down

0 comments on commit 6dfb892

Please sign in to comment.