Skip to content

Commit

Permalink
test: Set different feature gates for versions before 3.1.x
Browse files Browse the repository at this point in the history
Signed-off-by: Jintao Zhang <[email protected]>
  • Loading branch information
tao12345666333 committed Dec 21, 2023
1 parent 75e69ff commit dfb6908
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/e2e/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestDeployAllInOneDBLESSGateway(t *testing.T) {
for i, container := range controllerDeployment.Spec.Template.Spec.Containers {
if container.Name == controllerContainerName {
controllerDeployment.Spec.Template.Spec.Containers[i].Env = append(controllerDeployment.Spec.Template.Spec.Containers[i].Env,
corev1.EnvVar{Name: "CONTROLLER_FEATURE_GATES", Value: consts.DefaultFeatureGates})
corev1.EnvVar{Name: "CONTROLLER_FEATURE_GATES", Value: testenv.GetFeatureGates()})
}
}

Expand Down
29 changes: 27 additions & 2 deletions test/internal/testenv/feature_gates.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
package testenv

import "github.com/kong/kubernetes-ingress-controller/v3/test/consts"
import (
"github.com/blang/semver/v4"

func getFeatureGates() string {
"github.com/kong/kubernetes-ingress-controller/v3/test/consts"
)

func GetFeatureGates() string {
// Due to the possibility of running tests between different versions,
// it is necessary to adjust feature gates according to different KIC versions.
//
// Versions below 3.1.x cannot recognize the KongServiceFacade feature gate.
// We only need to set `GatewayAlpha=true`.
//
// https://github.com/Kong/kubernetes-ingress-controller/issues/5373
tag := ControllerTag()
if tag != "" {
// Currently, the latest version is 3.0.x, once 3.1.x is released,
// we can remove this logic.
if tag == "latest" {
return "GatewayAlpha=true"
}
if v, err := semver.Make(tag); err == nil {
minVersion, _ := semver.ParseRange("<3.1.x")
if minVersion(v) {
return "GatewayAlpha=true"
}
}
}
return consts.DefaultFeatureGates
}
3 changes: 1 addition & 2 deletions test/internal/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func ControllerImageTag() string {
return ""
}

// KongEffectiveVersion is the effective semver of kong gateway.
// KongEffectiveVersion is the effective semver of kong gateway.
// When testing against "nightly" image of kong gateway, we need to set the effective version for parsing semver in chart templates.
func KongEffectiveVersion() string {
Expand Down Expand Up @@ -205,7 +204,7 @@ func GithubRunID() string {
func ControllerFeatureGates() string {
featureGates := os.Getenv("KONG_CONTROLLER_FEATURE_GATES")
if featureGates == "" {
featureGates = getFeatureGates()
featureGates = GetFeatureGates()
}
return featureGates
}
Expand Down

0 comments on commit dfb6908

Please sign in to comment.