Skip to content

Commit d8664f9

Browse files
committed
feat(test): run conformance for Hybrid Gateway
1 parent 93258be commit d8664f9

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

test/conformance/conformance_test.go

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"sigs.k8s.io/gateway-api/pkg/features"
2222

2323
operatorv2beta1 "github.com/kong/kong-operator/api/gateway-operator/v2beta1"
24+
konnectv1alpha1 "github.com/kong/kong-operator/api/konnect/v1alpha1"
25+
"github.com/kong/kong-operator/api/konnect/v1alpha2"
2426
gwtypes "github.com/kong/kong-operator/internal/types"
2527
"github.com/kong/kong-operator/modules/manager/metadata"
2628
"github.com/kong/kong-operator/pkg/consts"
@@ -86,18 +88,24 @@ func TestGatewayConformance(t *testing.T) {
8688
t.Logf("using the following Kong router flavor for the conformance tests: %s", kongRouterFlavor)
8789

8890
t.Log("creating GatewayConfiguration and GatewayClass for gateway conformance tests")
89-
gwconf := createGatewayConfiguration(ctx, t, kongRouterFlavor)
91+
92+
gatewayType := standardGateway
93+
if test.KonnectAccessToken() != "" {
94+
gatewayType = hybridGateway
95+
}
96+
97+
gwconf := createGatewayConfiguration(ctx, t, kongRouterFlavor, gatewayType)
9098
gwc := createGatewayClass(ctx, t, gwconf)
9199

92100
// There are no explicit conformance tests for GatewayClass, but we can
93101
// still run the conformance test suite setup to ensure that the
94102
// GatewayClass gets accepted.
95-
t.Log("configuring the Gateway API conformance test suite")
103+
t.Logf("configuring the Gateway API (%s) conformance test suite", gatewayType)
96104
// Currently mode only relies on the KongRouterFlavor, but in the future
97105
// we may want to add more modes.
98106
mode := string(kongRouterFlavor)
99107
metadata := metadata.Metadata()
100-
reportFileName := fmt.Sprintf("experimental-%s-%s-report.yaml", metadata.Release, mode)
108+
reportFileName := fmt.Sprintf("experimental-%s-%s-%s-report.yaml", metadata.Release, mode, gatewayType)
101109

102110
// Set looser timeouts to avoid flakiness.
103111
timeoutConfig := conformanceconfig.DefaultTimeoutConfig()
@@ -134,11 +142,21 @@ func TestGatewayConformance(t *testing.T) {
134142
conformance.RunConformanceWithOptions(t, opts)
135143
}
136144

137-
func createGatewayConfiguration(ctx context.Context, t *testing.T, kongRouterFlavor consts.RouterFlavor) *operatorv2beta1.GatewayConfiguration {
145+
type gatewayType string
146+
147+
const (
148+
standardGateway gatewayType = "standard"
149+
hybridGateway gatewayType = "hybrid"
150+
)
151+
152+
func createGatewayConfiguration(
153+
ctx context.Context, t *testing.T, kongRouterFlavor consts.RouterFlavor, gatewayType gatewayType,
154+
) *operatorv2beta1.GatewayConfiguration {
155+
const namespace = "default"
138156
gwconf := operatorv2beta1.GatewayConfiguration{
139157
ObjectMeta: metav1.ObjectMeta{
140158
GenerateName: "ko-gwconf-conformance-",
141-
Namespace: "default",
159+
Namespace: namespace,
142160
},
143161
Spec: operatorv2beta1.GatewayConfigurationSpec{
144162
DataPlaneOptions: &operatorv2beta1.GatewayConfigDataPlaneOptions{
@@ -185,6 +203,33 @@ func createGatewayConfiguration(ctx context.Context, t *testing.T, kongRouterFla
185203
},
186204
}
187205

206+
if gatewayType == hybridGateway {
207+
t.Log("configuring GatewayConfiguration with Konnect access token - Hybrid Gateway")
208+
kapi := konnectv1alpha1.KonnectAPIAuthConfiguration{
209+
ObjectMeta: metav1.ObjectMeta{
210+
GenerateName: "api-auth-config-",
211+
Namespace: namespace,
212+
},
213+
Spec: konnectv1alpha1.KonnectAPIAuthConfigurationSpec{
214+
Type: konnectv1alpha1.KonnectAPIAuthTypeToken,
215+
Token: test.KonnectAccessToken(),
216+
ServerURL: test.KonnectServerURL(),
217+
},
218+
}
219+
require.NoError(t, clients.MgrClient.Create(ctx, &kapi))
220+
t.Cleanup(func() {
221+
require.NoError(t, clients.MgrClient.Delete(ctx, &kapi))
222+
})
223+
224+
gwconf.Spec.Konnect = &operatorv2beta1.KonnectOptions{
225+
APIAuthConfigurationRef: &v1alpha2.KonnectAPIAuthConfigurationRef{
226+
Name: kapi.Name,
227+
},
228+
}
229+
} else {
230+
t.Log("no Konnect access token provided - deploying GatewayConfiguration as a traditional Gateway")
231+
}
232+
188233
require.NoError(t, clients.MgrClient.Create(ctx, &gwconf))
189234
t.Cleanup(func() {
190235
require.NoError(t, clients.MgrClient.Delete(ctx, &gwconf))

0 commit comments

Comments
 (0)