From 25dc5e5e9f7f4faeaa03bbac8ecb837197c12e05 Mon Sep 17 00:00:00 2001 From: Shane Utt Date: Mon, 12 Jul 2021 21:53:38 -0400 Subject: [PATCH] fix: postgres implementation Patches a regression with our Kong addon Postgres that came around due to a typo in helm values. Adds integration tests for it so we're less likely to run into that again. --- pkg/clusters/addons/kong/kong.go | 10 ++--- test/integration/kind_cluster_test.go | 2 +- test/integration/postgres_test.go | 55 +++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 test/integration/postgres_test.go diff --git a/pkg/clusters/addons/kong/kong.go b/pkg/clusters/addons/kong/kong.go index c0ea4201..5011d2dc 100644 --- a/pkg/clusters/addons/kong/kong.go +++ b/pkg/clusters/addons/kong/kong.go @@ -114,10 +114,10 @@ func (a *Addon) Deploy(ctx context.Context, cluster clusters.Cluster) error { if a.dbmode == PostgreSQL { a.deployArgs = append(a.deployArgs, "--set", "env.database=postgres", - "--set", "PostgreSQL.enabled=true", - "--set", "PostgreSQL.PostgreSQLUsername=kong", - "--set", "PostgreSQL.PostgreSQLDatabase=kong", - "--set", "PostgreSQL.service.port=5432", + "--set", "postgresql.enabled=true", + "--set", "postgresql.postgresqlUsername=kong", + "--set", "postgresql.postgresqlDatabase=kong", + "--set", "postgresql.service.port=5432", ) } @@ -171,7 +171,7 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) (waitForObj } for _, service := range services.Items { - if len(service.Status.LoadBalancer.Ingress) < 1 { + if service.Spec.Type == corev1.ServiceTypeLoadBalancer && len(service.Status.LoadBalancer.Ingress) < 1 { waitForObjects = append(waitForObjects, &service) } } diff --git a/test/integration/kind_cluster_test.go b/test/integration/kind_cluster_test.go index cc65faa1..3f8e354e 100644 --- a/test/integration/kind_cluster_test.go +++ b/test/integration/kind_cluster_test.go @@ -16,7 +16,7 @@ import ( "github.com/kong/kubernetes-testing-framework/pkg/utils/kubernetes/generators" ) -func TestEnvironmentWithKindCluster(t *testing.T) { +func TestEnvWithKindCluster(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute*10) defer cancel() diff --git a/test/integration/postgres_test.go b/test/integration/postgres_test.go new file mode 100644 index 00000000..d3fb14a8 --- /dev/null +++ b/test/integration/postgres_test.go @@ -0,0 +1,55 @@ +//+build integration_tests + +package integration + +import ( + "context" + "net/http" + "testing" + "time" + + "github.com/stretchr/testify/require" + + kongaddon "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong" + metallbaddon "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb" + environment "github.com/kong/kubernetes-testing-framework/pkg/environments" +) + +func TestKongWithPostgresDBMode(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute*10) + defer cancel() + + t.Log("configuring the testing environment") + metallb := metallbaddon.New() + kong := kongaddon.NewBuilder().WithPostgreSQL().Build() + builder := environment.NewBuilder().WithAddons(kong, metallb) + + t.Log("building the testing environment and Kubernetes cluster") + env, err := builder.Build(ctx) + require.NoError(t, err) + + t.Logf("setting up the environment cleanup for environment %s and cluster %s", env.Name(), env.Cluster().Name()) + defer func() { + t.Logf("cleaning up environment %s and cluster %s", env.Name(), env.Cluster().Name()) + require.NoError(t, env.Cleanup(ctx)) + }() + + t.Log("waiting for environment to be ready") + require.NoError(t, <-env.WaitForReady(ctx)) + + t.Logf("verifying that the kong proxy admin service %s gets provisioned an IP address by metallb", kongaddon.DefaultAdminServiceName) + adminURL, err := kong.ProxyAdminURL(ctx, env.Cluster()) + require.NoError(t, err) + require.NotNil(t, adminURL) + + t.Logf("found url %s for proxy admin, now verifying it is routable", adminURL) + httpc := http.Client{Timeout: time.Second * 3} + require.Eventually(t, func() bool { + resp, err := httpc.Get(adminURL.String()) + if err != nil { + return false + } + defer resp.Body.Close() + return resp.StatusCode == http.StatusOK + }, time.Minute*1, time.Second*1) +}