Skip to content

Commit

Permalink
chore(tests): introduce isolated TestHTTPRouteWithBrokenPluginFallback (
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 committed Jun 3, 2024
1 parent c24305a commit 5cefa9a
Show file tree
Hide file tree
Showing 5 changed files with 343 additions and 74 deletions.
171 changes: 171 additions & 0 deletions examples/gateway-httproute-broken-plugin-fallback.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# This configuration file presents fallback configuration (feature gate FallbackConfiguration=true),
# it contains a plugin that is misconfigured and will not work. The whole route /for-auth-users won't
# be configured. Only the route /httproute-testing will be configured.
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo-1
labels:
app: echo-1
spec:
selector:
matchLabels:
app: echo-1
template:
metadata:
labels:
app: echo-1
spec:
containers:
- name: echo-1
image: kong/go-echo:0.3.0
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
ports:
- containerPort: 80
resources:
limits:
memory: "64Mi"
cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
labels:
app: echo-1
name: echo-1
spec:
ports:
- port: 80
protocol: TCP
targetPort: 1027
selector:
app: echo-1
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo-2
labels:
app: echo-2
spec:
selector:
matchLabels:
app: echo-2
template:
metadata:
labels:
app: echo-2
spec:
containers:
- name: echo-2
image: kong/go-echo:0.3.0
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
ports:
- containerPort: 80
resources:
limits:
memory: "64Mi"
cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
labels:
app: echo-2
name: echo-2
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 1027
selector:
app: echo-2
type: ClusterIP
---
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: kong
annotations:
konghq.com/gatewayclass-unmanaged: "true"
spec:
controllerName: konghq.com/kic-gateway-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: kong
spec:
gatewayClassName: kong
listeners:
- name: http
protocol: HTTP
port: 80
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httproute-testing
annotations:
konghq.com/strip-path: "true"
spec:
parentRefs:
- name: kong
rules:
- matches:
- path:
type: PathPrefix
value: /httproute-testing
backendRefs:
- name: echo-1
kind: Service
port: 80
weight: 75
- name: echo-2
kind: Service
port: 8080
weight: 25
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httproute-testing2
annotations:
konghq.com/strip-path: "true"
konghq.com/plugins: key-auth
spec:
parentRefs:
- name: kong
rules:
- matches:
- path:
type: PathPrefix
value: /for-auth-users
backendRefs:
- name: echo-1
kind: Service
port: 80
weight: 75
- name: echo-2
kind: Service
port: 8080
weight: 25
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: key-auth
namespace: default
plugin: key-auth
config:
# Should be key_names, not keys.
keys: ["key"]
62 changes: 40 additions & 22 deletions examples/gateway-httproute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,91 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpbin
name: echo-1
labels:
app: httpbin
app: echo-1
spec:
selector:
matchLabels:
app: httpbin
app: echo-1
template:
metadata:
labels:
app: httpbin
app: echo-1
spec:
containers:
- name: httpbin
image: kong/httpbin:0.1.0
- name: echo-1
image: kong/go-echo:0.3.0
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
ports:
- containerPort: 80
resources:
limits:
memory: "64Mi"
cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
labels:
app: httpbin
name: httpbin
app: echo-1
name: echo-1
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
targetPort: 1027
selector:
app: httpbin
app: echo-1
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
name: echo-2
labels:
app: nginx
app: echo-2
spec:
selector:
matchLabels:
app: nginx
app: echo-2
template:
metadata:
labels:
app: nginx
app: echo-2
spec:
containers:
- name: nginx
image: nginx
- name: echo-2
image: kong/go-echo:0.3.0
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
ports:
- containerPort: 80
resources:
limits:
memory: "64Mi"
cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
labels:
app: nginx
name: nginx
app: echo-2
name: echo-2
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 80
targetPort: 1027
selector:
app: nginx
app: echo-2
type: ClusterIP
---
apiVersion: gateway.networking.k8s.io/v1
Expand Down Expand Up @@ -109,11 +127,11 @@ spec:
type: PathPrefix
value: /httproute-testing
backendRefs:
- name: httpbin
- name: echo-1
kind: Service
port: 80
weight: 75
- name: nginx
- name: echo-2
kind: Service
port: 8080
weight: 25
50 changes: 0 additions & 50 deletions test/integration/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,14 @@ import (
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gatewayclient "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"

"github.com/kong/kubernetes-ingress-controller/v3/internal/gatewayapi"
"github.com/kong/kubernetes-ingress-controller/v3/test"
"github.com/kong/kubernetes-ingress-controller/v3/test/consts"
"github.com/kong/kubernetes-ingress-controller/v3/test/internal/helpers"
)

const examplesDIR = "../../examples"

func TestHTTPRouteExample(t *testing.T) {
var (
httprouteExampleManifests = fmt.Sprintf("%s/gateway-httproute.yaml", examplesDIR)
ctx = context.Background()
)

_, cleaner := helpers.Setup(ctx, t, env)

t.Logf("configuring test and setting up API clients")
gwc, err := gatewayclient.NewForConfig(env.Cluster().Config())
require.NoError(t, err)

t.Logf("applying yaml manifest %s", httprouteExampleManifests)
b, err := os.ReadFile(httprouteExampleManifests)
require.NoError(t, err)
require.NoError(t, clusters.ApplyManifestByYAML(ctx, env.Cluster(), string(b)))
cleaner.AddManifest(string(b))

t.Logf("verifying that the Gateway receives listen addresses")
var gatewayIP string
require.Eventually(t, func() bool {
obj, err := gwc.GatewayV1().Gateways(corev1.NamespaceDefault).Get(ctx, "kong", metav1.GetOptions{})
if err != nil {
return false
}

for _, addr := range obj.Status.Addresses {
if addr.Type != nil && *addr.Type == gatewayapi.IPAddressType {
gatewayIP = addr.Value
return true
}
}

return false
}, gatewayUpdateWaitTime, waitTick)

require.NoError(t, err)
t.Logf("verifying that the HTTPRoute becomes routable")
helpers.EventuallyGETPath(
t, nil, gatewayIP, "/httproute-testing", http.StatusOK, "<title>httpbin.org</title>", nil, ingressWait, waitTick,
)

t.Logf("verifying that the backendRefs are being loadbalanced")
helpers.EventuallyGETPath(
t, nil, gatewayIP, "/httproute-testing", http.StatusOK, "<title>Welcome to nginx!</title>", nil, ingressWait, waitTick,
)
}

func TestTCPRouteExample(t *testing.T) {
RunWhenKongExpressionRouter(context.Background(), t)
t.Log("locking TCP port")
Expand Down
Loading

0 comments on commit 5cefa9a

Please sign in to comment.