Skip to content

Commit

Permalink
test(conformance): gatewayclassGenerationBump pass (#4645)
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
  • Loading branch information
mlavacca committed Sep 12, 2023
1 parent 8d149dc commit 896edff
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/controllers/gateway/gateway_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func isObjectUnmanaged(anns map[string]string) bool {
// isGatewayClassControlledAndUnmanaged returns boolean if the GatewayClass
// is controlled by this controller and is configured for unmanaged mode.
func isGatewayClassControlledAndUnmanaged(gatewayClass *GatewayClass) bool {
isUnamanaged := isObjectUnmanaged(gatewayClass.Annotations)
return gatewayClass.Spec.ControllerName == GetControllerName() && isUnamanaged
isUnmanaged := isObjectUnmanaged(gatewayClass.Annotations)
return gatewayClass.Spec.ControllerName == GetControllerName() && isUnmanaged
}

// pruneGatewayStatusConds cleans out old status conditions if the Gateway currently has more
Expand Down
39 changes: 34 additions & 5 deletions test/conformance/gateway_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
package conformance

import (
"context"
"testing"
"time"

"github.com/stretchr/testify/require"
k8stypes "k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
"sigs.k8s.io/gateway-api/conformance/tests"
"sigs.k8s.io/gateway-api/conformance/utils/suite"

"github.com/kong/kubernetes-ingress-controller/v2/internal/annotations"
"github.com/kong/kubernetes-ingress-controller/v2/test/internal/testenv"
)

Expand All @@ -17,8 +24,6 @@ var commonSkippedTests = []string{
// https://github.com/Kong/kubernetes-ingress-controller/issues/4563
tests.GatewayWithAttachedRoutesWithPort8080.ShortName,
tests.HTTPRouteRedirectPortAndScheme.ShortName,
// https://github.com/Kong/kubernetes-ingress-controller/issues/3680
tests.GatewayClassObservedGenerationBump.ShortName,
// https://github.com/Kong/kubernetes-ingress-controller/issues/3679
tests.HTTPRouteQueryParamMatching.ShortName,
// https://github.com/Kong/kubernetes-ingress-controller/issues/3681
Expand Down Expand Up @@ -62,7 +67,7 @@ func TestGatewayConformance(t *testing.T) {
t.Skip("skipping standard conformance tests")
}

client, gatewayClassName := prepareEnvForGatewayConformanceTests(t)
k8sClient, gatewayClassName := prepareEnvForGatewayConformanceTests(t)
// Conformance tests are run for both configs with and without
// KONG_TEST_EXPRESSION_ROUTES='true'.
skipTests := skippedTestsForTraditionalRoutes
Expand All @@ -71,7 +76,7 @@ func TestGatewayConformance(t *testing.T) {
}

cSuite := suite.New(suite.Options{
Client: client,
Client: k8sClient,
GatewayClassName: gatewayClassName,
Debug: true,
CleanupBaseResources: !testenv.IsCI(),
Expand All @@ -83,9 +88,33 @@ func TestGatewayConformance(t *testing.T) {
t.Log("starting the gateway conformance test suite")
cSuite.Setup(t)

// We need to wait for the GatewayClass created by the test GatewayClassObservedGenerationBump
// and patch it with the unmanaged annotation to make it reconciled by the GatewayClass
// controller. The timeout and the tick are pretty loose because of the indeterministic
// test order execution.
go require.Eventually(t, func() bool {
return ensureTestGatewayClassIsUnmanaged(ctx, k8sClient)
}, 10*time.Minute, 10*time.Second)

// To work with individual tests only, you can disable the normal Run call and construct a slice containing a
// single test only, e.g.:
//
//cSuite.Run(t, []suite.ConformanceTest{tests.HTTPRouteRedirectPortAndScheme})
//cSuite.Run(t, []suite.ConformanceTest{tests.GatewayClassObservedGenerationBump})
cSuite.Run(t, tests.ConformanceTests)
}

func ensureTestGatewayClassIsUnmanaged(ctx context.Context, k8sClient client.Client) bool {
gwcNamespacedName := k8stypes.NamespacedName{Name: "gatewayclass-observed-generation-bump"}
gwc := &gatewayv1beta1.GatewayClass{}
if err := k8sClient.Get(ctx, gwcNamespacedName, gwc); err != nil {
return false
}
if gwc.Annotations == nil {
gwc.Annotations = map[string]string{}
}
gwc.Annotations[annotations.GatewayClassUnmanagedAnnotation] = annotations.GatewayClassUnmanagedAnnotationValuePlaceholder
if err := k8sClient.Update(ctx, gwc); err != nil {
return false
}
return true
}

0 comments on commit 896edff

Please sign in to comment.