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

tests(conformance): use router flavor instead of separate flag for enabling expressions router #5860

Merged
merged 2 commits into from
Apr 11, 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
6 changes: 3 additions & 3 deletions .github/workflows/_conformance_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
matrix:
include:
- name: traditional-compatible-router
expression_routes: "false"
router-flavor: traditional_compatible
- name: expressions-router
expression_routes: "true"
router-flavor: expressions
steps:
- name: checkout repository
uses: actions/checkout@v4
Expand All @@ -56,7 +56,7 @@ jobs:
run: make test.conformance
env:
JUNIT_REPORT: conformance-tests.xml
KONG_TEST_EXPRESSION_ROUTES: ${{ matrix.expression_routes }}
TEST_KONG_ROUTER_FLAVOR: ${{ matrix.router-flavor }}
TEST_KONG_KIC_MANAGER_LOG_OUTPUT: ${{ inputs.log-output-file }}

# upload logs when test failed
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/conformance_tests_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Run conformance tests
env:
TEST_KONG_HELM_CHART_VERSION: ${{ needs.dependencies-versions.outputs.helm-kong }}
KONG_TEST_EXPRESSION_ROUTES: "true"
TEST_KONG_ROUTER_FLAVOR: expressions
run: make test.conformance

# Generated report should be submitted to
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ test.conformance: _check.container.environment go-junit-report
TEST_KONG_HELM_CHART_VERSION="$(TEST_KONG_HELM_CHART_VERSION)" \
GOFLAGS="-tags=conformance_tests" \
go test \
-ldflags "$(LDFLAGS_METADATA)" \
-ldflags "$(LDFLAGS_COMMON) $(LDFLAGS_METADATA)" \
-v \
-race $(GOTESTFLAGS) \
-timeout $(INTEGRATION_TEST_TIMEOUT) \
Expand Down
21 changes: 14 additions & 7 deletions test/conformance/gateway_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/yaml"

dpconf "github.com/kong/kubernetes-ingress-controller/v3/internal/dataplane/config"
"github.com/kong/kubernetes-ingress-controller/v3/internal/manager/metadata"
"github.com/kong/kubernetes-ingress-controller/v3/test/internal/testenv"
)
Expand Down Expand Up @@ -45,15 +46,21 @@ var expressionRoutesSupportedFeatures = []suite.SupportedFeature{

func TestGatewayConformance(t *testing.T) {
k8sClient, gatewayClassName := prepareEnvForGatewayConformanceTests(t)
// Conformance tests are run for both configs with and without
// KONG_TEST_EXPRESSION_ROUTES='true'.
var skippedTests []string
var supportedFeatures []suite.SupportedFeature
if testenv.ExpressionRoutesEnabled() {
supportedFeatures = expressionRoutesSupportedFeatures
} else {

// Conformance tests are run for both available router flavours:
// traditional_compatible and expressions.
var (
skippedTests []string
supportedFeatures []suite.SupportedFeature
)
switch rf := testenv.KongRouterFlavor(); rf {
case dpconf.RouterFlavorTraditionalCompatible:
skippedTests = skippedTestsForTraditionalRoutes
supportedFeatures = traditionalRoutesSupportedFeatures
case dpconf.RouterFlavorExpressions:
supportedFeatures = expressionRoutesSupportedFeatures
default:
t.Fatalf("unsupported KongRouterFlavor: %s", rf)
}

cSuite, err := suite.NewExperimentalConformanceTestSuite(
Expand Down
5 changes: 3 additions & 2 deletions test/conformance/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/kong/kubernetes-ingress-controller/v3/internal/annotations"
"github.com/kong/kubernetes-ingress-controller/v3/internal/controllers/gateway"
dpconf "github.com/kong/kubernetes-ingress-controller/v3/internal/dataplane/config"
"github.com/kong/kubernetes-ingress-controller/v3/internal/gatewayapi"
testutils "github.com/kong/kubernetes-ingress-controller/v3/internal/util/test"
"github.com/kong/kubernetes-ingress-controller/v3/test"
Expand Down Expand Up @@ -75,9 +76,9 @@ func TestMain(m *testing.M) {
// In order to pass conformance tests, the expression router is required.
kongBuilder := kong.NewBuilder().WithControllerDisabled().WithProxyAdminServiceTypeLoadBalancer().
WithNamespace(consts.ControllerNamespace)
if testenv.ExpressionRoutesEnabled() {
if testenv.KongRouterFlavor() == dpconf.RouterFlavorExpressions {
fmt.Println("INFO: expression routes enabled")
kongBuilder = kongBuilder.WithProxyEnvVar("router_flavor", "expressions")
kongBuilder = kongBuilder.WithProxyEnvVar("router_flavor", string(dpconf.RouterFlavorExpressions))
}

// Pin the Helm chart version.
Expand Down
2 changes: 1 addition & 1 deletion test/integration/isolated/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func SkipIfRouterNotExpressions(ctx context.Context, t *testing.T, _ *envconf.Config) context.Context {
flavor := testenv.KongRouterFlavor()
if flavor != string(dpconf.RouterFlavorExpressions) {
if flavor != dpconf.RouterFlavorExpressions {
t.Skipf("skiping, %q router flavor specified via TEST_KONG_ROUTER_FLAVOR env but %q is required", flavor, "expressions")
}
return ctx
Expand Down
7 changes: 4 additions & 3 deletions test/internal/helpers/ktf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong"

dpconf "github.com/kong/kubernetes-ingress-controller/v3/internal/dataplane/config"
"github.com/kong/kubernetes-ingress-controller/v3/test/consts"
"github.com/kong/kubernetes-ingress-controller/v3/test/internal/testenv"
)
Expand Down Expand Up @@ -52,10 +53,10 @@ func GenerateKongBuilder(_ context.Context) (*kong.Builder, []string, error) {
}

flavor := testenv.KongRouterFlavor()
if flavor == "" {
flavor = "traditional"
if len(flavor) == 0 {
flavor = dpconf.RouterFlavorTraditional
}
kongbuilder = kongbuilder.WithProxyEnvVar("router_flavor", flavor)
kongbuilder = kongbuilder.WithProxyEnvVar("router_flavor", string(flavor))

kongbuilder.WithControllerDisabled()
kongbuilder.WithProxyAdminServiceTypeLoadBalancer()
Expand Down
13 changes: 4 additions & 9 deletions test/internal/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/tidwall/gjson"
"sigs.k8s.io/yaml"

dpconf "github.com/kong/kubernetes-ingress-controller/v3/internal/dataplane/config"
)

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -130,14 +132,14 @@ func KongHelmChartVersion() string {
// - `traditional`
// - `traditional_compatible`.
// - `expressions` (experimental, only for testing expression route related tests).
func KongRouterFlavor() string {
func KongRouterFlavor() dpconf.RouterFlavor {
rf := os.Getenv("TEST_KONG_ROUTER_FLAVOR")
if rf != "" && rf != "traditional" && rf != "traditional_compatible" && rf != "expressions" {
// TODO
os.Exit(1)
}

return rf
return dpconf.RouterFlavor(rf)
}

// KongPullUsername is the Docker username to use for the Kong image pull secret.
Expand Down Expand Up @@ -209,13 +211,6 @@ func ControllerFeatureGates() string {
return featureGates
}

// ExpressionRoutesEnabled indicates whether or not to enable expression routes
// for the Kong Gateway and the controller.
// If none specified, we fall back to default value - traditional_compatible.
func ExpressionRoutesEnabled() bool {
return os.Getenv("KONG_TEST_EXPRESSION_ROUTES") == "true"
}

// -----------------------------------------------------------------------------
// Environment variables related helpers
// -----------------------------------------------------------------------------
Expand Down
Loading