Skip to content

Commit

Permalink
fix: postgres implementation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shaneutt committed Jul 13, 2021
1 parent dcbacb7 commit 25dc5e5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pkg/clusters/addons/kong/kong.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/kind_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
55 changes: 55 additions & 0 deletions test/integration/postgres_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 25dc5e5

Please sign in to comment.