Skip to content

Commit

Permalink
refactor: bump KTF to v0.46.0 and adjust code accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 committed Mar 21, 2024
1 parent 02dca39 commit 7b5ac98
Show file tree
Hide file tree
Showing 31 changed files with 323 additions and 266 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/kong/go-database-reconciler v1.8.0
github.com/kong/go-kong v0.51.1-0.20240125175037-0c077f5b9ac7
github.com/kong/kubernetes-telemetry v0.1.3
github.com/kong/kubernetes-testing-framework v0.45.0
github.com/kong/kubernetes-testing-framework v0.45.1-0.20240321125901-65e92eb5b071
github.com/lithammer/dedent v1.1.0
github.com/miekg/dns v1.1.58
github.com/mitchellh/mapstructure v1.5.0
Expand Down Expand Up @@ -225,6 +225,6 @@ require (
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
sigs.k8s.io/e2e-framework v0.3.1-0.20231113122213-262cac32d35e
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kind v0.21.0 // indirect
sigs.k8s.io/kind v0.22.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ github.com/kong/go-kong v0.51.1-0.20240125175037-0c077f5b9ac7 h1:/iV93Gwv410lIeJ
github.com/kong/go-kong v0.51.1-0.20240125175037-0c077f5b9ac7/go.mod h1:YNkLvjxfOqS+BZ1J2YWOy/83wc26JM5QJbAukoeg1sY=
github.com/kong/kubernetes-telemetry v0.1.3 h1:Hz2tkHGIIUqbn1x46QRDmmNjbEtJyxyOvHSPne3uPto=
github.com/kong/kubernetes-telemetry v0.1.3/go.mod h1:wB7o8dOKa5R396CyiU0sPa8am/g3c5DKd/qrn/Vmb+k=
github.com/kong/kubernetes-testing-framework v0.45.0 h1:6tFqpDcA1v9AfnUKgFF5aQeRm1Hx3o72SRIbXxjGqMI=
github.com/kong/kubernetes-testing-framework v0.45.0/go.mod h1:lmdBKPdsOc/YMafv+8eF/4CiM2MOuiGCvacDQfD+muI=
github.com/kong/kubernetes-testing-framework v0.45.1-0.20240321125901-65e92eb5b071 h1:XxZ05+AIeFLfDPshaCaMKT2KbneVGah+W82mo5/nR3g=
github.com/kong/kubernetes-testing-framework v0.45.1-0.20240321125901-65e92eb5b071/go.mod h1:O6jnDHf+8jKc3g3G7mwjA5oxaB/R2AEPKM6BLoKrqII=
github.com/kong/semver/v4 v4.0.1 h1:DIcNR8W3gfx0KabFBADPalxxsp+q/5COwIFkkhrFQ2Y=
github.com/kong/semver/v4 v4.0.1/go.mod h1:LImQ0oT15pJvSns/hs2laLca2zcYoHu5EsSNY0J6/QA=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -679,8 +679,8 @@ sigs.k8s.io/gateway-api v1.0.0 h1:iPTStSv41+d9p0xFydll6d7f7MOBGuqXM6p2/zVYMAs=
sigs.k8s.io/gateway-api v1.0.0/go.mod h1:4cUgr0Lnp5FZ0Cdq8FdRwCvpiWws7LVhLHGIudLlf4c=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/kind v0.21.0 h1:QgkVrW35dMXNLkWlUkq2uFQNQbPLr0Z6RgRH5P/NzZU=
sigs.k8s.io/kind v0.21.0/go.mod h1:aBlbxg08cauDgZ612shr017/rZwqd7AS563FvpWKPVs=
sigs.k8s.io/kind v0.22.0 h1:z/+yr/azoOfzsfooqRsPw1wjJlqT/ukXP0ShkHwNlsI=
sigs.k8s.io/kind v0.22.0/go.mod h1:aBlbxg08cauDgZ612shr017/rZwqd7AS563FvpWKPVs=
sigs.k8s.io/kustomize/api v0.16.0 h1:/zAR4FOQDCkgSDmVzV2uiFbuy9bhu3jEzthrHCuvm1g=
sigs.k8s.io/kustomize/api v0.16.0/go.mod h1:MnFZ7IP2YqVyVwMWoRxPtgl/5hpA+eCCrQR/866cm5c=
sigs.k8s.io/kustomize/kyaml v0.16.0 h1:6J33uKSoATlKZH16unr2XOhDI+otoe2sR3M8PDzW3K0=
Expand Down
2 changes: 1 addition & 1 deletion internal/util/test/controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func DeployControllerManagerForCluster(

// render all controller manager flag options
controllerManagerFlags := []string{
fmt.Sprintf("--kong-admin-url=http://%s:8001", proxyAdminURL.Hostname()),
fmt.Sprintf("--kong-admin-url=%s", proxyAdminURL.String()),
fmt.Sprintf("--kubeconfig=%s", kubeconfig.Name()),
"--election-id=integrationtests.konghq.com",
"--log-format=text",
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/kong/go-database-reconciler/pkg/dump"
"github.com/kong/go-kong/kong"
"github.com/kong/kubernetes-testing-framework/pkg/clusters"
ktfkong "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/loadimage"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/types/gke"
Expand Down Expand Up @@ -70,7 +71,7 @@ const (
namespace = "kong"
adminServiceName = "kong-admin-lb"

tcpListenerPort = 8888
tcpListenerPort = ktfkong.DefaultTCPServicePort

// controllerDeploymentName is the name of the controller deployment in all manifests variants.
controllerDeploymentName = "ingress-kong"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestIstioWithKongIngressGateway(t *testing.T) {
require.NoError(t, clusters.DeployIngress(ctx, env.Cluster(), namespace.Name, ingress))

t.Log("retrieving the kong proxy URL")
proxyURL, err := kongAddon.ProxyURL(ctx, env.Cluster())
proxyURL, err := kongAddon.ProxyHTTPURL(ctx, env.Cluster())
require.NoError(t, err)

t.Log("waiting for routes from Ingress to be operational")
Expand Down
4 changes: 2 additions & 2 deletions test/integration/consumer_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func TestConsumerGroup(t *testing.T) {
t.Log("checking if consumer has plugin configured correctly based on consumer group membership")
for _, consumer := range consumers {
require.Eventually(t, func() bool {
req := helpers.MustHTTPRequest(t, http.MethodGet, proxyURL.Host, "/", map[string]string{
req := helpers.MustHTTPRequest(t, http.MethodGet, proxyHTTPURL.Host, "/", map[string]string{
"apikey": consumer.Name,
})
resp, err := helpers.DefaultHTTPClientWithProxy(proxyURL).Do(req)
resp, err := helpers.DefaultHTTPClientWithProxy(proxyHTTPURL).Do(req)
if err != nil {
t.Logf("WARNING: consumer %q failed to make a request: %v", consumer.Name, err)
return false
Expand Down
16 changes: 8 additions & 8 deletions test/integration/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func TestConsumerCredential(t *testing.T) {

t.Log("waiting for routes from Ingress to be operational")
require.Eventually(t, func() bool {
resp, err := helpers.DefaultHTTPClient().Get(fmt.Sprintf("%s/test_consumer_credential", proxyURL))
resp, err := helpers.DefaultHTTPClient().Get(fmt.Sprintf("%s/test_consumer_credential", proxyHTTPURL))
if err != nil {
t.Logf("WARNING: error while waiting for %s: %v", proxyURL, err)
t.Logf("WARNING: error while waiting for %s: %v", proxyHTTPURL, err)
return false
}
defer resp.Body.Close()
Expand Down Expand Up @@ -98,9 +98,9 @@ func TestConsumerCredential(t *testing.T) {

t.Logf("validating that plugin %s was successfully configured", kongplugin.Name)
assert.Eventually(t, func() bool {
resp, err := helpers.DefaultHTTPClient().Get(fmt.Sprintf("%s/test_consumer_credential", proxyURL))
resp, err := helpers.DefaultHTTPClient().Get(fmt.Sprintf("%s/test_consumer_credential", proxyHTTPURL))
if err != nil {
t.Logf("WARNING: error while waiting for %s: %v", proxyURL, err)
t.Logf("WARNING: error while waiting for %s: %v", proxyHTTPURL, err)
return false
}
defer resp.Body.Close()
Expand Down Expand Up @@ -140,9 +140,9 @@ func TestConsumerCredential(t *testing.T) {

t.Logf("validating that consumer has access")
assert.Eventually(t, func() bool {
req := helpers.MustHTTPRequest(t, http.MethodGet, proxyURL.Host, "/test_consumer_credential", nil)
req := helpers.MustHTTPRequest(t, http.MethodGet, proxyHTTPURL.Host, "/test_consumer_credential", nil)
req.SetBasicAuth("test_consumer_credential", "test_consumer_credential")
resp, err := helpers.DefaultHTTPClientWithProxy(proxyURL).Do(req)
resp, err := helpers.DefaultHTTPClientWithProxy(proxyHTTPURL).Do(req)
if err != nil {
return false
}
Expand All @@ -157,7 +157,7 @@ func TestConsumerCredential(t *testing.T) {
_, err = env.Cluster().Client().CoreV1().Secrets(ns.Name).Update(ctx, credential, metav1.UpdateOptions{})
require.NoError(t, err)
assert.Eventually(t, func() bool {
req := helpers.MustHTTPRequest(t, "GET", proxyURL.String(), "/test_consumer_credential", nil)
req := helpers.MustHTTPRequest(t, "GET", proxyHTTPURL.String(), "/test_consumer_credential", nil)
req.SetBasicAuth("new_consumer_credential", "test_consumer_credential")
resp, err := helpers.DefaultHTTPClient().Do(req)
if err != nil {
Expand All @@ -169,5 +169,5 @@ func TestConsumerCredential(t *testing.T) {

t.Log("deleting Ingress and waiting for routes to be torn down")
require.NoError(t, clusters.DeleteIngress(ctx, env.Cluster(), ns.Name, ingress))
helpers.EventuallyExpectHTTP404WithNoRoute(t, proxyURL, proxyURL.Host, "/test_plugin_essentials", ingressWait, waitTick, nil)
helpers.EventuallyExpectHTTP404WithNoRoute(t, proxyHTTPURL, proxyHTTPURL.Host, "/test_plugin_essentials", ingressWait, waitTick, nil)
}
13 changes: 7 additions & 6 deletions test/integration/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"testing"

"github.com/kong/kubernetes-testing-framework/pkg/clusters"
ktfkong "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestTCPRouteExample(t *testing.T) {

t.Log("verifying that TCPRoute becomes routable")
require.Eventually(t, func() bool {
return test.EchoResponds(test.ProtocolTCP, fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTCPServicePort), "tcproute-example-manifest") == nil
return test.EchoResponds(test.ProtocolTCP, proxyTCPURL, "tcproute-example-manifest") == nil
}, ingressWait, waitTick)
}

Expand All @@ -124,9 +123,11 @@ func TestTLSRouteExample(t *testing.T) {
cleaner.AddManifest(string(b))

t.Log("verifying that TLSRoute becomes routable")
require.Eventually(t, func() bool {
return tlsEchoResponds(fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultTLSServicePort),
"tlsroute-example-manifest", "tlsroute.kong.example", "tlsroute.kong.example", true) == nil
require.EventuallyWithT(t, func(c *assert.CollectT) {
err := tlsEchoResponds(
proxyTLSURL, "tlsroute-example-manifest", "tlsroute.kong.example", "tlsroute.kong.example", true,
)
assert.NoError(c, err)
}, ingressWait, waitTick)
}

Expand Down Expand Up @@ -211,7 +212,7 @@ func TestUDPIngressExample(t *testing.T) {
t.Log("verifying that the UDPIngress resource becomes routable")
dnsUDPClient := new(dns.Client)
assert.Eventually(t, func() bool {
_, _, err := dnsUDPClient.Exchange(query, fmt.Sprintf("%s:9999", proxyUDPURL.Hostname()))
_, _, err := dnsUDPClient.Exchange(query, proxyUDPURL)
return err == nil
}, ingressWait, waitTick)
}
Expand Down
21 changes: 11 additions & 10 deletions test/integration/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/google/uuid"
"github.com/kong/go-kong/kong"
"github.com/kong/kubernetes-testing-framework/pkg/clusters"
ktfkong "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong"
"github.com/kong/kubernetes-testing-framework/pkg/utils/kubernetes/generators"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -251,12 +252,12 @@ func TestGatewayListenerConflicts(t *testing.T) {
{
Name: "http",
Protocol: gatewayapi.HTTPProtocolType,
Port: gatewayapi.PortNumber(80),
Port: gatewayapi.PortNumber(ktfkong.DefaultProxyHTTPPort),
},
{
Name: "tls",
Protocol: gatewayapi.TLSProtocolType,
Port: gatewayapi.PortNumber(8899),
Port: gatewayapi.PortNumber(ktfkong.DefaultTLSServicePort),
Hostname: &tlsHost,
TLS: &gatewayapi.GatewayTLSConfig{
CertificateRefs: []gatewayapi.SecretObjectReference{
Expand All @@ -269,7 +270,7 @@ func TestGatewayListenerConflicts(t *testing.T) {
{
Name: "https",
Protocol: gatewayapi.HTTPSProtocolType,
Port: gatewayapi.PortNumber(443),
Port: gatewayapi.PortNumber(ktfkong.DefaultProxyTLSServicePort),
Hostname: &httpsHost,
TLS: &gatewayapi.GatewayTLSConfig{
CertificateRefs: []gatewayapi.SecretObjectReference{
Expand All @@ -282,7 +283,7 @@ func TestGatewayListenerConflicts(t *testing.T) {
{
Name: "httphost",
Protocol: gatewayapi.HTTPProtocolType,
Port: gatewayapi.PortNumber(80),
Port: gatewayapi.PortNumber(ktfkong.DefaultProxyHTTPPort),
Hostname: &httphostHost,
},
}
Expand Down Expand Up @@ -426,9 +427,9 @@ func TestGatewayFilters(t *testing.T) {
require.Eventually(t, callback, ingressWait, waitTick)

t.Log("waiting for routes from HTTPRoute to become operational")
helpers.EventuallyGETPath(t, proxyURL, proxyURL.Host, "test_gateway_filters", http.StatusOK, "<title>httpbin.org</title>", emptyHeaderSet, ingressWait, waitTick)
helpers.EventuallyGETPath(t, proxyHTTPURL, proxyHTTPURL.Host, "test_gateway_filters", http.StatusOK, "<title>httpbin.org</title>", emptyHeaderSet, ingressWait, waitTick)
t.Log("waiting for routes from HTTPRoute in other namespace to become operational")
helpers.EventuallyGETPath(t, proxyURL, proxyURL.Host, "other_test_gateway_filters", http.StatusOK, "<title>httpbin.org</title>", emptyHeaderSet, ingressWait, waitTick)
helpers.EventuallyGETPath(t, proxyHTTPURL, proxyHTTPURL.Host, "other_test_gateway_filters", http.StatusOK, "<title>httpbin.org</title>", emptyHeaderSet, ingressWait, waitTick)

t.Log("changing to the same namespace filter")
require.Eventually(t, func() bool {
Expand All @@ -451,9 +452,9 @@ func TestGatewayFilters(t *testing.T) {
}, ingressWait, waitTick)

t.Log("confirming other namespace route becomes inaccessible")
helpers.EventuallyGETPath(t, proxyURL, proxyURL.Host, "other_test_gateway_filters", http.StatusNotFound, "no Route matched", emptyHeaderSet, ingressWait, waitTick)
helpers.EventuallyGETPath(t, proxyHTTPURL, proxyHTTPURL.Host, "other_test_gateway_filters", http.StatusNotFound, "no Route matched", emptyHeaderSet, ingressWait, waitTick)
t.Log("confirming same namespace route still operational")
helpers.EventuallyGETPath(t, proxyURL, proxyURL.Host, "test_gateway_filters", http.StatusOK, "<title>httpbin.org</title>", emptyHeaderSet, ingressWait, waitTick)
helpers.EventuallyGETPath(t, proxyHTTPURL, proxyHTTPURL.Host, "test_gateway_filters", http.StatusOK, "<title>httpbin.org</title>", emptyHeaderSet, ingressWait, waitTick)

t.Log("changing to a selector filter")
require.Eventually(t, func() bool {
Expand Down Expand Up @@ -482,7 +483,7 @@ func TestGatewayFilters(t *testing.T) {
}, ingressWait, waitTick)

t.Log("confirming wrong selector namespace route becomes inaccessible")
helpers.EventuallyGETPath(t, proxyURL, proxyURL.Host, "test_gateway_filters", http.StatusNotFound, "no Route matched", emptyHeaderSet, ingressWait, waitTick)
helpers.EventuallyGETPath(t, proxyHTTPURL, proxyHTTPURL.Host, "test_gateway_filters", http.StatusNotFound, "no Route matched", emptyHeaderSet, ingressWait, waitTick)
t.Log("confirming right selector namespace route becomes operational")
helpers.EventuallyGETPath(t, proxyURL, proxyURL.Host, "other_test_gateway_filters", http.StatusOK, "<title>httpbin.org</title>", emptyHeaderSet, ingressWait, waitTick)
helpers.EventuallyGETPath(t, proxyHTTPURL, proxyHTTPURL.Host, "other_test_gateway_filters", http.StatusOK, "<title>httpbin.org</title>", emptyHeaderSet, ingressWait, waitTick)
}
Loading

0 comments on commit 7b5ac98

Please sign in to comment.