Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature flag for Kubernetes v1.31 support #8698

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/api/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ const (
Kube128 KubernetesVersion = "1.28"
Kube129 KubernetesVersion = "1.29"
Kube130 KubernetesVersion = "1.30"
Kube131 KubernetesVersion = "1.31"
)

// 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 @@ -8,6 +8,7 @@ const (
UseControllerForCli = "USE_CONTROLLER_FOR_CLI"
VSphereInPlaceEnvVar = "VSPHERE_IN_PLACE_UPGRADE"
APIServerExtraArgsEnabledEnvVar = "API_SERVER_EXTRA_ARGS_ENABLED"
K8s131SupportEnvVar = "K8S_1_31_SUPPORT"
)

func FeedGates(featureGates []string) {
Expand Down Expand Up @@ -64,3 +65,11 @@ func APIServerExtraArgsEnabled() Feature {
IsActive: globalFeatures.isActiveForEnvVar(APIServerExtraArgsEnabledEnvVar),
}
}

// K8s131Support is the feature flag for Kubernetes 1.31 support.
func K8s131Support() Feature {
return Feature{
Name: "Kubernetes version 1.31 support",
IsActive: globalFeatures.isActiveForEnvVar(K8s131SupportEnvVar),
}
}
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 TestAPIServerExtraArgsEnabledFeatureFlag(t *testing.T) {
g.Expect(os.Setenv(APIServerExtraArgsEnabledEnvVar, "true")).To(Succeed())
g.Expect(IsActive(APIServerExtraArgsEnabled())).To(BeTrue())
}

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

g.Expect(os.Setenv(K8s131SupportEnvVar, "true")).To(Succeed())
g.Expect(IsActive(K8s131Support())).To(BeTrue())
}
11 changes: 11 additions & 0 deletions pkg/validations/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/config"
"github.com/aws/eks-anywhere/pkg/constants"
"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/providers/common"
Expand Down Expand Up @@ -286,3 +287,13 @@ func ValidateBottlerocketKubeletConfig(spec *cluster.Spec) error {

return nil
}

// ValidateK8s131Support checks if the 1.31 feature flag is set when using k8s 1.31.
func ValidateK8s131Support(clusterSpec *cluster.Spec) error {
if !features.IsActive(features.K8s131Support()) {
if clusterSpec.Cluster.Spec.KubernetesVersion == v1alpha1.Kube131 {
return fmt.Errorf("kubernetes version %s is not enabled. Please set the env variable %v", v1alpha1.Kube131, features.K8s131SupportEnvVar)
}
}
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 @@ -16,6 +16,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 @@ -837,3 +838,18 @@ func TestValidateBottlerocketKC(t *testing.T) {
})
}
}

func TestValidateK8s131Support(t *testing.T) {
tt := newTest(t)
tt.clusterSpec.Cluster.Spec.KubernetesVersion = anywherev1.Kube131
tt.Expect(validations.ValidateK8s131Support(tt.clusterSpec)).To(
MatchError(ContainSubstring("kubernetes version 1.31 is not enabled. Please set the env variable K8S_1_31_SUPPORT")))
}

func TestValidateK8s131SupportActive(t *testing.T) {
tt := newTest(t)
tt.clusterSpec.Cluster.Spec.KubernetesVersion = anywherev1.Kube131
features.ClearCache()
os.Setenv(features.K8s131SupportEnvVar, "true")
tt.Expect(validations.ValidateK8s131Support(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 @@ -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/constants"
"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 @@ -50,6 +51,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.31 support",
Remediation: fmt.Sprintf("ensure %v env variable is set", features.K8s131SupportEnvVar),
Err: validations.ValidateK8s131Support(v.Opts.Spec),
Silent: true,
}
},
}

if len(v.Opts.Spec.VSphereMachineConfigs) != 0 {
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 @@ -9,6 +9,7 @@ import (
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/config"
"github.com/aws/eks-anywhere/pkg/constants"
"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 @@ -122,6 +123,14 @@ func (u *UpgradeValidations) PreflightValidations(ctx context.Context) []validat
Err: validations.ValidatePauseAnnotation(ctx, k, targetCluster, targetCluster.Name),
}
},
func() *validations.ValidationResult {
return &validations.ValidationResult{
Name: "validate kubernetes version 1.31 support",
Remediation: fmt.Sprintf("ensure %v env variable is set", features.K8s131SupportEnvVar),
Err: validations.ValidateK8s131Support(u.Opts.Spec),
Silent: true,
}
},
}

if len(u.Opts.Spec.VSphereMachineConfigs) != 0 {
Expand Down
4 changes: 3 additions & 1 deletion test/framework/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/executables"
"github.com/aws/eks-anywhere/pkg/features"
"github.com/aws/eks-anywhere/pkg/filewriter"
"github.com/aws/eks-anywhere/pkg/git"
"github.com/aws/eks-anywhere/pkg/providers/cloudstack/decoder"
Expand Down Expand Up @@ -2202,11 +2203,12 @@ func dumpFile(description, path string, t T) {
func (e *ClusterE2ETest) setFeatureFlagForUnreleasedKubernetesVersion(version v1alpha1.KubernetesVersion) {
// Update this variable to equal the feature flagged k8s version when applicable.
// For example, if k8s 1.26 is under a feature flag, we would set this to v1alpha1.Kube126
var unreleasedK8sVersion v1alpha1.KubernetesVersion
unreleasedK8sVersion := v1alpha1.Kube131

if version == unreleasedK8sVersion {
// Set feature flag for the unreleased k8s version when applicable
e.T.Logf("Setting k8s version support feature flag...")
os.Setenv(features.K8s131SupportEnvVar, "true")
}
}

Expand Down
Loading