Skip to content

Commit

Permalink
test(e2e): upgrade KIC (backport of #9157) (#12348)
Browse files Browse the repository at this point in the history
Automatic cherry-pick of #9157 for branch release-2.6

Generated by
[action](https://github.com/kumahq/kuma/actions/runs/12415814401)

cherry-picked commit 6cf0b3e
⚠️ ⚠️ ⚠️ Conflicts happened when cherry-picking!
⚠️ ⚠️ ⚠️
```
On branch release-2.6
Your branch is up to date with 'origin/release-2.6'.

You are currently cherry-picking commit 6cf0b3e.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   test/e2e_env/kubernetes/gateway/delegated.go
	modified:   test/e2e_env/kubernetes/kic/kong_ingress.go
	modified:   test/e2e_env/kubernetes/kubernetes_suite_test.go
	modified:   test/framework/deployments/kic/deployment.go

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   test/e2e_env/kubernetes/gateway/delegated_meshproxypatch.go
	both modified:   test/framework/deployments/kic/kubernetes.go

```

---------

Signed-off-by: Jakub Dyszkiewicz <[email protected]>
Signed-off-by: Lukasz Dziedziak <[email protected]>
Co-authored-by: Jakub Dyszkiewicz <[email protected]>
Co-authored-by: Lukasz Dziedziak <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 0e34794 commit 3ea2f55
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 69 deletions.
8 changes: 6 additions & 2 deletions test/e2e_env/kubernetes/gateway/delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ func Delegated() {
testserver.WithName("test-server"),
)).
Install(kic.KongIngressController(
kic.WithName("delegated"),
kic.WithNamespace(config.namespace),
kic.WithMesh(config.mesh),
)).
Install(kic.KongIngressService(kic.WithNamespace(config.namespace))).
Install(kic.KongIngressService(
kic.WithName("delegated"),
kic.WithNamespace(config.namespace),
)).
Install(YamlK8s(fmt.Sprintf(`
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: %s
name: %s-ingress
annotations:
kubernetes.io/ingress.class: kong
kubernetes.io/ingress.class: delegated
spec:
rules:
- http:
Expand Down
105 changes: 78 additions & 27 deletions test/e2e_env/kubernetes/kic/kong_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ func KICKubernetes() {
Install(democlient.Install(democlient.WithNamespace(namespaceOutsideMesh))). // this will not be in the mesh
Install(kic.KongIngressController(
kic.WithNamespace(namespace),
kic.WithName("kic"),
kic.WithMesh(mesh),
)).
Install(kic.KongIngressService(kic.WithNamespace(namespace))).
Install(kic.KongIngressService(
kic.WithNamespace(namespace),
kic.WithName("kic"),
)).
Install(testserver.Install(
testserver.WithNamespace(namespace),
testserver.WithMesh(mesh),
Expand All @@ -67,24 +71,48 @@ func KICKubernetes() {

It("should route to service using Kube DNS", func() {
ingress := `
apiVersion: networking.k8s.io/v1
kind: Ingress
---
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: kic
annotations:
konghq.com/gatewayclass-unmanaged: 'true'
spec:
controllerName: konghq.com/kic-gateway-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: kong
namespace: kic
spec:
gatewayClassName: kic
listeners:
- name: proxy
port: 80
protocol: HTTP
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: echo
namespace: kic
name: kube-dns-ingress
annotations:
kubernetes.io/ingress.class: kong
konghq.com/strip-path: 'true'
spec:
parentRefs:
- name: kong
namespace: kic
rules:
- http:
paths:
- path: /test-server
pathType: Prefix
backend:
service:
name: test-server
port:
number: 80
- matches:
- path:
type: PathPrefix
value: /test-server
backendRefs:
- name: test-server
kind: Service
port: 80
`
Expect(kubernetes.Cluster.Install(YamlK8s(ingress))).To(Succeed())

Expand All @@ -100,6 +128,27 @@ spec:
It("should route to service using Kuma DNS", func() {
const ingressMeshDNS = `
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: echo
namespace: kic
annotations:
konghq.com/strip-path: 'true'
spec:
parentRefs:
- name: kong
namespace: kic
rules:
- matches:
- path:
type: PathPrefix
value: /test-server
backendRefs:
- name: test-server
kind: Service
port: 80
---
apiVersion: v1
kind: Service
metadata:
Expand All @@ -109,24 +158,26 @@ spec:
type: ExternalName
externalName: test-server.kic.svc.80.mesh
---
apiVersion: networking.k8s.io/v1
kind: Ingress
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
namespace: kic
name: k8s-ingress-dot-mesh
namespace: kic
annotations:
kubernetes.io/ingress.class: kong
konghq.com/strip-path: 'true'
spec:
parentRefs:
- name: kong
namespace: kic
rules:
- http:
paths:
- path: /dot-mesh
pathType: Prefix
backend:
service:
name: test-server-externalname
port:
number: 80
- matches:
- path:
type: PathPrefix
value: /dot-mesh
backendRefs:
- name: test-server-externalname
kind: Service
port: 80
`

Expect(kubernetes.Cluster.Install(YamlK8s(ingressMeshDNS))).To(Succeed())
Expand Down
4 changes: 2 additions & 2 deletions test/e2e_env/kubernetes/kubernetes_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var (
_ = Describe("Gateway - Gateway API", gateway.GatewayAPI, Ordered)
_ = Describe("Gateway - mTLS", gateway.Mtls, Ordered)
_ = Describe("Gateway - Resources", gateway.Resources, Ordered)
_ = Describe("Delegated Gateway", Label("kind-not-supported", "ipv6-not-supported", "arm-not-supported"), gateway.Delegated, Ordered)
_ = Describe("Delegated Gateway", Label("kind-not-supported", "ipv6-not-supported"), gateway.Delegated, Ordered)
_ = Describe("Graceful", graceful.Graceful, Ordered)
_ = Describe("Eviction", graceful.Eviction, Ordered)
_ = XDescribe("Change Service", graceful.ChangeService, Ordered)
Expand All @@ -75,7 +75,7 @@ var (
_ = Describe("External Services Permissive MTLS", externalservices.PermissiveMTLS, Ordered)
_ = Describe("ExternalName Services", externalname_services.ExternalNameServices, Ordered)
_ = Describe("Virtual Outbound", virtualoutbound.VirtualOutbound, Ordered)
_ = Describe("Kong Ingress Controller", Label("arm-not-supported"), kic.KICKubernetes, Ordered)
_ = Describe("Kong Ingress Controller", kic.KICKubernetes, Ordered)
_ = Describe("MeshTrafficPermission API", meshtrafficpermission.API, Ordered)
_ = Describe("MeshRateLimit API", meshratelimit.API, Ordered)
_ = Describe("MeshTimeout API", meshtimeout.MeshTimeout, Ordered)
Expand Down
12 changes: 10 additions & 2 deletions test/framework/deployments/kic/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Deployment interface {
type deployOptions struct {
namespace string
mesh string
name string
}

type deployOptionsFunc func(*deployOptions)
Expand All @@ -47,6 +48,7 @@ func Install(fs ...deployOptionsFunc) framework.InstallFunc {
deployment = &k8sDeployment{
ingressNamespace: opts.namespace,
mesh: opts.mesh,
name: opts.name,
}
default:
return errors.New("invalid cluster")
Expand All @@ -67,6 +69,12 @@ func WithMesh(mesh string) deployOptionsFunc {
}
}

func WithName(name string) deployOptionsFunc {
return func(o *deployOptions) {
o.name = name
}
}

func KongIngressController(fs ...deployOptionsFunc) framework.InstallFunc {
return Install(fs...)
}
Expand All @@ -85,7 +93,7 @@ metadata:
spec:
type: ClusterIP
selector:
app: ingress-kong
app: %s-gateway
ports:
- name: proxy
targetPort: 8000
Expand All @@ -94,5 +102,5 @@ spec:
targetPort: 8443
port: 443
`
return framework.YamlK8s(fmt.Sprintf(svc, opts.namespace))
return framework.YamlK8s(fmt.Sprintf(svc, opts.namespace, opts.name))
}
79 changes: 43 additions & 36 deletions test/framework/deployments/kic/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"time"

"github.com/gruntwork-io/terratest/modules/helm"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/gruntwork-io/terratest/modules/retry"
"github.com/pkg/errors"
Expand All @@ -16,62 +17,68 @@ import (
type k8sDeployment struct {
ingressNamespace string
mesh string
name string
}

var _ Deployment = &k8sDeployment{}

var ingressApp = "ingress-kong"

func (t *k8sDeployment) Name() string {
return DeploymentName
}

func (t *k8sDeployment) Deploy(cluster framework.Cluster) error {
var yaml string
var err error
if t.ingressNamespace == "" {
t.ingressNamespace = framework.Config.DefaultGatewayNamespace
}
yaml, err = cluster.GetKumactlOptions().RunKumactlAndGetOutputV(framework.Verbose,
"install", "gateway", "kong",
opts := helm.Options{
KubectlOptions: cluster.GetKubectlOptions(t.ingressNamespace),
}
_, err = helm.RunHelmCommandAndGetStdOutE(cluster.GetTesting(), &opts, "install", t.name,
"--namespace", t.ingressNamespace,
"--mesh", t.mesh,
"--repo", "https://charts.konghq.com",
"--set", "controller.ingressController.ingressClass="+t.name,
"--set", "controller.podAnnotations.kuma\\.io/mesh="+t.mesh,
"--set", "gateway.podAnnotations.kuma\\.io/mesh="+t.mesh,
"ingress",
)
if err != nil {
return err
}

err = k8s.KubectlApplyFromStringE(cluster.GetTesting(),
cluster.GetKubectlOptions(),
yaml)
if err != nil {
return err
for _, app := range []string{fmt.Sprintf("%s-controller", t.name), fmt.Sprintf("%s-gateway", t.name)} {
err := k8s.WaitUntilNumPodsCreatedE(cluster.GetTesting(),
cluster.GetKubectlOptions(t.ingressNamespace),
metav1.ListOptions{
LabelSelector: fmt.Sprintf("app=%s", app),
},
1,
framework.DefaultRetries,
framework.DefaultTimeout)
if err != nil {
return err
}

pods := k8s.ListPods(cluster.GetTesting(),
cluster.GetKubectlOptions(t.ingressNamespace),
metav1.ListOptions{
LabelSelector: fmt.Sprintf("app=%s", app),
},
)
if len(pods) != 1 {
return errors.Errorf("counting KIC pods. Got: %d. Expected: 1", len(pods))
}

err = k8s.WaitUntilPodAvailableE(cluster.GetTesting(),
cluster.GetKubectlOptions(t.ingressNamespace),
pods[0].Name,
framework.DefaultRetries*3, // KIC is fetched from the internet. Increase the timeout to prevent long downloads of images.
framework.DefaultTimeout)
if err != nil {
return err
}
}

k8s.WaitUntilNumPodsCreated(cluster.GetTesting(),
cluster.GetKubectlOptions(t.ingressNamespace),
metav1.ListOptions{
LabelSelector: fmt.Sprintf("app=%s", ingressApp),
},
1,
framework.DefaultRetries,
framework.DefaultTimeout)

pods := k8s.ListPods(cluster.GetTesting(),
cluster.GetKubectlOptions(t.ingressNamespace),
metav1.ListOptions{
LabelSelector: fmt.Sprintf("app=%s", ingressApp),
},
)
if len(pods) != 1 {
return errors.Errorf("counting KIC pods. Got: %d. Expected: 1", len(pods))
}

return k8s.WaitUntilPodAvailableE(cluster.GetTesting(),
cluster.GetKubectlOptions(t.ingressNamespace),
pods[0].Name,
framework.DefaultRetries,
framework.DefaultTimeout)
return nil
}

func (t *k8sDeployment) Delete(cluster framework.Cluster) error {
Expand Down

0 comments on commit 3ea2f55

Please sign in to comment.