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 eaaf069 commit 452cc11
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 102 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.7.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.20240321103018-c68471cfcc40
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.20240321103018-c68471cfcc40 h1:izxh7sTW893MtdjSW0cCh8vOQ1pKYSu0fBBacb4Pnhw=
github.com/kong/kubernetes-testing-framework v0.45.1-0.20240321103018-c68471cfcc40/go.mod h1:6Gqi85cblebUBYcmJNp/Tilpt49+6yweDE+a+l689xk=
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
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
9 changes: 4 additions & 5 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.String(), "tcproute-example-manifest") == nil
}, ingressWait, waitTick)
}

Expand All @@ -125,8 +124,8 @@ func TestTLSRouteExample(t *testing.T) {

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
return tlsEchoResponds(
proxyTLSURL.String(), "tlsroute-example-manifest", "tlsroute.kong.example", "tlsroute.kong.example", true) == nil
}, ingressWait, waitTick)
}

Expand Down Expand Up @@ -211,7 +210,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.String())
return err == nil
}, ingressWait, waitTick)
}
Expand Down
9 changes: 5 additions & 4 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
32 changes: 32 additions & 0 deletions test/integration/isolated/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,38 @@ func GetUDPURLFromCtx(ctx context.Context) *url.URL {
return u.(*url.URL)
}

type _tlsURL struct{}

// SetTLSURLInCtx sets the TLS URL in the context.
func SetTLSURLInCtx(ctx context.Context, url *url.URL) context.Context {
return setInCtx(ctx, _tlsURL{}, url)
}

// GetTLSURLFromCtx gets the TLS URL from the context.
func GetTLSURLFromCtx(ctx context.Context) *url.URL {
u := ctx.Value(_tlsURL{})
if u == nil {
return nil
}
return u.(*url.URL)
}

type _tcpURL struct{}

// SetTCPURLInCtx sets the TCP URL in the context.
func SetTCPURLInCtx(ctx context.Context, url *url.URL) context.Context {
return setInCtx(ctx, _tcpURL{}, url)
}

// GetTCPURLFromCtx gets the TCP URL from the context.
func GetTCPURLFromCtx(ctx context.Context) *url.URL {
u := ctx.Value(_tcpURL{})
if u == nil {
return nil
}
return u.(*url.URL)
}

type _proxyURL struct{}

// SetProxyURLInCtx sets the proxy URL in the context.
Expand Down
12 changes: 5 additions & 7 deletions test/integration/isolated/examples_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

func TestGRPCRouteExample(t *testing.T) {
testGRPC := func(ctx context.Context, t *testing.T, manifestName string, gatewayPort int, hostname string, enableTLS bool) {
t.Helper()
cluster := GetClusterFromCtx(ctx)
proxyURL := GetProxyURLFromCtx(ctx)
manifestPath := examplesManifestPath(manifestName)
Expand All @@ -31,14 +32,11 @@ func TestGRPCRouteExample(t *testing.T) {
assert.NoError(t, clusters.ApplyManifestByYAML(ctx, cluster, manifest))

t.Log("verifying that GRPCRoute becomes routable")
assert.Eventually(t, func() bool {
if err := grpcEchoResponds(
assert.EventuallyWithT(t, func(c *assert.CollectT) {
err := grpcEchoResponds(
ctx, fmt.Sprintf("%s:%d", proxyURL.Hostname(), gatewayPort), hostname, "kong", enableTLS,
); err != nil {
t.Log(err)
return false
}
return true
)
assert.NoError(c, err)
}, consts.IngressWait, consts.WaitTick)

t.Logf("deleting yaml manifest %s", manifestPath)
Expand Down
3 changes: 1 addition & 2 deletions test/integration/isolated/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestGRPCRouteEssentials(t *testing.T) {
return ctx
}).
Assess("checking if GRPCRoute is linked correctly and client can connect properly to the exposed service", func(ctx context.Context, t *testing.T, _ *envconf.Config) context.Context {
proxyURL := GetProxyURLFromCtx(ctx)
grpcAddr := GetTLSURLFromCtx(ctx).String()
namespace := GetNamespaceForT(ctx, t)
gatewayClient := GetFromCtxForT[*gatewayclient.Clientset](ctx, t)
grpcRoute := GetFromCtxForT[*gatewayapi.GRPCRoute](ctx, t)
Expand All @@ -182,7 +182,6 @@ func TestGRPCRouteEssentials(t *testing.T) {
consts.IngressWait, consts.WaitTick,
)

grpcAddr := fmt.Sprintf("%s:%d", proxyURL.Hostname(), ktfkong.DefaultProxyTLSServicePort)
t.Log("waiting for routes from GRPCRoute to become operational")
assert.Eventually(t, func() bool {
err := grpcEchoResponds(ctx, grpcAddr, testHostname, "kong", true)
Expand Down
3 changes: 2 additions & 1 deletion test/integration/isolated/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ func TestIngressGRPC(t *testing.T) {
}, consts.StatusWait, consts.WaitTick)

verifyEchoResponds := func(hostname string) {
// Kong Gateway uses different ports for HTTP and HTTPS traffic.
// Kong Gateway uses different ports for HTTP and HTTPS traffic,
// but in typical setup both ports are exposed on the same IP address.
proxyPort := ktfkong.DefaultProxyTLSServicePort
tlsEnabled := true
if hostname == "" {
Expand Down
10 changes: 10 additions & 0 deletions test/integration/isolated/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ func featureSetup(opts ...featureSetupOpt) func(ctx context.Context, t *testing.
return ctx
}
ctx = SetUDPURLInCtx(ctx, proxyUDPURL)
proxyTCPURL, err := kongAddon.ProxyTCPURL(ctx, cluster)
if !assert.NoError(t, err) {
return ctx
}
ctx = SetTCPURLInCtx(ctx, proxyTCPURL)
proxyTLSURL, err := kongAddon.ProxyTLSURL(ctx, cluster)
if !assert.NoError(t, err) {
return ctx
}
ctx = SetTCPURLInCtx(ctx, proxyTLSURL)
proxyURL, err := kongAddon.ProxyURL(ctx, cluster)
if !assert.NoError(t, err) {
return ctx
Expand Down
10 changes: 4 additions & 6 deletions test/integration/isolated/tcproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package isolated
import (
"context"
"errors"
"fmt"
"io"
"syscall"
"testing"
Expand Down Expand Up @@ -194,8 +193,7 @@ func TestTCPRouteEssentials(t *testing.T) {
)

t.Log("verifying that the tcpecho is responding properly")
tcpGatewayURL := fmt.Sprintf("%s:%d", GetProxyURLFromCtx(ctx).Hostname(), ktfkong.DefaultTCPServicePort)
ctx = SetInCtxForT(ctx, t, tcpGatewayURL)
tcpGatewayURL := GetTCPURLFromCtx(ctx).String()
requireResponse(tcpGatewayURL, test1UUID)

return ctx
Expand All @@ -205,7 +203,7 @@ func TestTCPRouteEssentials(t *testing.T) {
gatewayClient := GetFromCtxForT[*gatewayclient.Clientset](ctx, t)
tcpRoute := GetFromCtxForT[*gatewayapi.TCPRoute](ctx, t)
namespace := GetNamespaceForT(ctx, t)
tcpGatewayURL := GetFromCtxForT[string](ctx, t)
tcpGatewayURL := GetTCPURLFromCtx(ctx).String()

oldParentRefs := tcpRoute.Spec.ParentRefs
assert.Eventually(t, func() bool {
Expand Down Expand Up @@ -252,7 +250,7 @@ func TestTCPRouteEssentials(t *testing.T) {
gatewayClient := GetFromCtxForT[*gatewayclient.Clientset](ctx, t)
namespace := GetNamespaceForT(ctx, t)
tcpRoute := GetFromCtxForT[*gatewayapi.TCPRoute](ctx, t)
tcpGatewayURL := GetFromCtxForT[string](ctx, t)
tcpGatewayURL := GetTCPURLFromCtx(ctx).String()

t.Log("deleting the GatewayClass")
assert.NoError(t, gatewayClient.GatewayV1().GatewayClasses().Delete(ctx, gatewayClassName, metav1.DeleteOptions{}))
Expand Down Expand Up @@ -342,7 +340,7 @@ func TestTCPRouteEssentials(t *testing.T) {
gatewayClient := GetFromCtxForT[*gatewayclient.Clientset](ctx, t)
namespace := GetNamespaceForT(ctx, t)
tcpRoute := GetFromCtxForT[*gatewayapi.TCPRoute](ctx, t)
tcpGatewayURL := GetFromCtxForT[string](ctx, t)
tcpGatewayURL := GetTCPURLFromCtx(ctx).String()

t.Log("adding an additional backendRef to the TCPRoute")
assert.Eventually(t, func() bool {
Expand Down
12 changes: 4 additions & 8 deletions test/integration/isolated/udproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ func TestUDPRouteEssentials(t *testing.T) {
)

t.Log("verifying that the udpecho is responding properly")
// GetUDPURLFromCtx returns the URL of the UDP service, but with http prefix
// http://<IP>:<PORT> (bug in KTF), taking the Host part trims scheme part.
// https://github.com/Kong/kubernetes-testing-framework/issues/1007
udpGatewayURL := GetUDPURLFromCtx(ctx).Host
ctx = SetInCtxForT(ctx, t, udpGatewayURL)
udpGatewayURL := GetUDPURLFromCtx(ctx).String()
requireResponse(udpGatewayURL, test1UUID)

return ctx
Expand All @@ -209,7 +205,7 @@ func TestUDPRouteEssentials(t *testing.T) {
gatewayClient := GetFromCtxForT[*gatewayclient.Clientset](ctx, t)
udpRoute := GetFromCtxForT[*gatewayapi.UDPRoute](ctx, t)
namespace := GetNamespaceForT(ctx, t)
udpGatewayURL := GetFromCtxForT[string](ctx, t)
udpGatewayURL := GetUDPURLFromCtx(ctx).String()

oldParentRefs := udpRoute.Spec.ParentRefs
assert.Eventually(t, func() bool {
Expand Down Expand Up @@ -256,7 +252,7 @@ func TestUDPRouteEssentials(t *testing.T) {
gatewayClient := GetFromCtxForT[*gatewayclient.Clientset](ctx, t)
namespace := GetNamespaceForT(ctx, t)
udpRoute := GetFromCtxForT[*gatewayapi.UDPRoute](ctx, t)
udpGatewayURL := GetFromCtxForT[string](ctx, t)
udpGatewayURL := GetUDPURLFromCtx(ctx).String()

t.Log("deleting the GatewayClass")
assert.NoError(t, gatewayClient.GatewayV1().GatewayClasses().Delete(ctx, gatewayClassName, metav1.DeleteOptions{}))
Expand Down Expand Up @@ -346,7 +342,7 @@ func TestUDPRouteEssentials(t *testing.T) {
gatewayClient := GetFromCtxForT[*gatewayclient.Clientset](ctx, t)
namespace := GetNamespaceForT(ctx, t)
udpRoute := GetFromCtxForT[*gatewayapi.UDPRoute](ctx, t)
udpGatewayURL := GetFromCtxForT[string](ctx, t)
udpGatewayURL := GetUDPURLFromCtx(ctx).String()

t.Log("adding an additional backendRef to the UDPRoute")
assert.Eventually(t, func() bool {
Expand Down
4 changes: 4 additions & 0 deletions test/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func TestMain(m *testing.M) {
helpers.ExitOnErr(ctx, err)
proxyAdminURL, err = kongAddon.ProxyAdminURL(ctx, env.Cluster())
helpers.ExitOnErr(ctx, err)
proxyTCPURL, err = kongAddon.ProxyTCPURL(ctx, env.Cluster())
helpers.ExitOnErr(ctx, err)
proxyTLSURL, err = kongAddon.ProxyTLSURL(ctx, env.Cluster())
helpers.ExitOnErr(ctx, err)
proxyUDPURL, err = kongAddon.ProxyUDPURL(ctx, env.Cluster())
helpers.ExitOnErr(ctx, err)

Expand Down
Loading

0 comments on commit 452cc11

Please sign in to comment.