Skip to content

Commit

Permalink
adopt ktf latest version; resolve CI failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ccfish2 committed Jul 9, 2021
1 parent 888d730 commit 6f3d50c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 60 deletions.
3 changes: 2 additions & 1 deletion railgun/test/performance/perf_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kong/kubernetes-ingress-controller/pkg/annotations"
generators "github.com/kong/kubernetes-testing-framework/pkg/generators/k8s"
"github.com/kong/kubernetes-testing-framework/pkg/utils/kubernetes/generators"
)

func TestIngressPerformance(t *testing.T) {
t.Log("setting up the TestIngressPerf")

ctx := context.Background()
cluster := env.Cluster()
cnt := 1
cost := 0
for cnt <= max_ingress {
Expand Down
20 changes: 10 additions & 10 deletions railgun/test/performance/perf_knative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"fmt"
"testing"

"github.com/kong/kubernetes-testing-framework/pkg/clusters"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
Expand All @@ -25,8 +26,6 @@ import (
"knative.dev/pkg/apis"
knservingv1 "knative.dev/serving/pkg/apis/serving/v1"
knativeversioned "knative.dev/serving/pkg/client/clientset/versioned"

"github.com/kong/kubernetes-testing-framework/pkg/kind"
)

const (
Expand All @@ -35,11 +34,12 @@ const (
)

func TestPerfKnativePerformance(t *testing.T) {
proxy := KongInfo.ProxyURL.Hostname()
proxy := proxyURL.Hostname()
assert.NotEmpty(t, proxy)
t.Logf("proxy url %s", proxy)

ctx := context.Background()
cluster := env.Cluster()

t.Log("Deploying all resources that are required to run knative")
require.NoError(t, deployManifest(knativeCrds, ctx, t))
Expand All @@ -59,7 +59,7 @@ func TestPerfKnativePerformance(t *testing.T) {

t.Logf("Install knative service into namespace %s", namespace)
require.Eventually(t, func() bool {
err := perfInstallKnativeSrv(ctx, t, namespace)
err := perfInstallKnativeSrv(ctx, t, namespace, cluster)
if err != nil {
t.Logf("checking knativing webhook readiness.")
return false
Expand All @@ -68,7 +68,7 @@ func TestPerfKnativePerformance(t *testing.T) {
}, 30*time.Second, 2*time.Second, true)

t.Logf("Test knative service using kong within namespace %s.", namespace)
require.True(t, perfaccessKnativeSrv(ctx, proxy, t, namespace, &cost), true)
require.True(t, perfaccessKnativeSrv(ctx, proxy, t, namespace, &cost, cluster), true)
cnt++
}
t.Logf("knative ingress cost %d", cost/max_ingress)
Expand Down Expand Up @@ -98,7 +98,7 @@ func perfcheckIPAddress(ip string, t *testing.T) bool {
}
}

func perfconfigKnativeNetwork(ctx context.Context, cluster kind.Cluster, t *testing.T) error {
func perfconfigKnativeNetwork(ctx context.Context, cluster clusters.Cluster, t *testing.T) error {
payloadBytes := []byte(fmt.Sprintf("{\"data\": {\"ingress.class\": \"%s\"}}", "kong"))
_, err := cluster.Client().CoreV1().ConfigMaps("knative-serving").Patch(ctx, "config-network", types.MergePatchType, payloadBytes, metav1.PatchOptions{})
if err != nil {
Expand All @@ -110,7 +110,7 @@ func perfconfigKnativeNetwork(ctx context.Context, cluster kind.Cluster, t *test
return nil
}

func perfInstallKnativeSrv(ctx context.Context, t *testing.T, namespace string) error {
func perfInstallKnativeSrv(ctx context.Context, t *testing.T, namespace string, cluster clusters.Cluster) error {
tobeDeployedService := &knservingv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "helloworld-go",
Expand Down Expand Up @@ -147,7 +147,7 @@ func perfInstallKnativeSrv(ctx context.Context, t *testing.T, namespace string)
return nil
}

func perfconfigKnativeDomain(ctx context.Context, proxy string, cluster kind.Cluster, t *testing.T) error {
func perfconfigKnativeDomain(ctx context.Context, proxy string, cluster clusters.Cluster, t *testing.T) error {
configMapData := make(map[string]string, 0)
configMapData[proxy] = ""
labels := make(map[string]string)
Expand All @@ -173,7 +173,7 @@ func perfconfigKnativeDomain(ctx context.Context, proxy string, cluster kind.Clu
return nil
}

func perfaccessKnativeSrv(ctx context.Context, proxy string, t *testing.T, namesapce string, cost *int) bool {
func perfaccessKnativeSrv(ctx context.Context, proxy string, t *testing.T, namesapce string, cost *int, cluster clusters.Cluster) bool {
knativeCli, err := knativenetworkingversioned.NewForConfig(cluster.Config())
if err != nil {
return false
Expand Down Expand Up @@ -230,7 +230,7 @@ func perfaccessKnativeSrv(ctx context.Context, proxy string, t *testing.T, names
}, 120*time.Second, 1*time.Second)
}

func isKnativeReady(ctx context.Context, cluster kind.Cluster, t *testing.T) bool {
func isKnativeReady(ctx context.Context, cluster clusters.Cluster, t *testing.T) bool {
return assert.Eventually(t, func() bool {
podList, err := cluster.Client().CoreV1().Pods("knative-serving").List(ctx, metav1.ListOptions{})
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion railgun/test/performance/perf_tcpingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import (
"github.com/kong/kubernetes-ingress-controller/pkg/annotations"
kongv1beta1 "github.com/kong/kubernetes-ingress-controller/railgun/apis/configuration/v1beta1"
"github.com/kong/kubernetes-ingress-controller/railgun/pkg/clientset"
generators "github.com/kong/kubernetes-testing-framework/pkg/generators/k8s"
"github.com/kong/kubernetes-testing-framework/pkg/utils/kubernetes/generators"
)

func TestTCPIngressPerformance(t *testing.T) {

t.Log("setting up the TestTCPPerformance tests")
cluster := env.Cluster()
c, err := clientset.NewForConfig(cluster.Config())
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), ingressWait)
Expand Down
3 changes: 2 additions & 1 deletion railgun/test/performance/perf_udpingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import (
"github.com/kong/kubernetes-ingress-controller/railgun/apis/configuration/v1beta1"
kongv1beta1 "github.com/kong/kubernetes-ingress-controller/railgun/apis/configuration/v1beta1"
"github.com/kong/kubernetes-ingress-controller/railgun/pkg/clientset"
generators "github.com/kong/kubernetes-testing-framework/pkg/generators/k8s"
"github.com/kong/kubernetes-testing-framework/pkg/utils/kubernetes/generators"
)

func TestUDPIngressPerformance(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), ingressWait)
cluster := env.Cluster()
defer cancel()

cnt := 1
Expand Down
116 changes: 69 additions & 47 deletions railgun/test/performance/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,96 @@ import (
"testing"
"time"

ktfkind "github.com/kong/kubernetes-testing-framework/pkg/kind"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/types/kind"
"github.com/kong/kubernetes-testing-framework/pkg/environments"
"github.com/stretchr/testify/assert"
)

const (
controllerNamespace = "kong-system"
clusterDeployWait = time.Minute * 5
max_ingress = 500
httpBinImage = "kennethreitz/httpbin"
ingressClass = "kong"
ingressWait = time.Minute * 3
waitTick = time.Second * 1
httpcTimeout = time.Second * 3
clusterDeployWait = time.Minute * 5
waitTick = time.Second * 1
ingressWait = time.Minute * 3
httpcTimeout = time.Second * 3
httpBinImage = "kennethreitz/httpbin"
ingressClass = "kongtests"
max_ingress = 500
)

var (
cluster ktfkind.Cluster
KongInfo *ktfkind.ProxyReadinessEvent
httpc = http.Client{Timeout: httpcTimeout}
httpc = http.Client{Timeout: httpcTimeout}
env environments.Environment
proxyURL *url.URL
proxyAdminURL *url.URL
proxyUDPURL *url.URL
)

func TestMain(m *testing.M) {
var err error
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(clusterDeployWait))
defer cancel()

var err error
var existingClusterInUse bool
fmt.Println("INFO: configuring testing environment")
kongAddon := kong.New()
builder := environments.NewBuilder().WithAddons(metallb.New(), kongAddon)
if existingClusterName := os.Getenv("KIND_CLUSTER"); existingClusterName != "" {
existingClusterInUse = true
cluster, err = ktfkind.GetExistingCluster(existingClusterName)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(10)
}
KongInfo = &ktfkind.ProxyReadinessEvent{}
svcs, err := cluster.Client().CoreV1().Services(controllerNamespace).List(ctx, metav1.ListOptions{})
fmt.Printf("INFO: using existing cluster %s\n", existingClusterName)
cluster, err := kind.NewFromExisting(existingClusterName)
if err != nil {
return
}
for _, svc := range svcs.Items {
if svc.Name == "ingress-controller-kong-proxy" && len(svc.Status.LoadBalancer.Ingress) == 1 {
proxyURL, _ := url.Parse(fmt.Sprintf("http://%s:%d", svc.Status.LoadBalancer.Ingress[0].IP, 80))
KongInfo.ProxyURL = proxyURL
}
if svc.Name == "ingress-controller-kong-admin" && len(svc.Status.LoadBalancer.Ingress) == 1 {
proxyAdminURL, _ := url.Parse(fmt.Sprintf("http://%s:%d", svc.Status.LoadBalancer.Ingress[0].IP, 8001))
KongInfo.ProxyAdminURL = proxyAdminURL
}
if svc.Name == "ingress-controller-kong-udp" && len(svc.Status.LoadBalancer.Ingress) == 1 {
proxyUDPUrl, _ := url.Parse(fmt.Sprintf("udp://%s:9999", svc.Status.LoadBalancer.Ingress[0].IP))
KongInfo.ProxyUDPUrl = proxyUDPUrl
}
fmt.Fprintf(os.Stderr, "Error: could not use existing cluster for test env: %s", err.Error())
os.Exit(24)
}
builder = builder.WithExistingCluster(cluster)
}

code := m.Run()
if !existingClusterInUse {
cluster.Cleanup()
fmt.Println("INFO: building test environment (note: can take some time)")
env, err = builder.Build(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: could not create testing environment: %s", err.Error())
os.Exit(25)
}
fmt.Printf(
"INFO: environment built CLUSTER_NAME=(%s) CLUSTER_TYPE=(%s) ADDONS=(metallb, kong)\n",
env.Cluster().Name(), env.Cluster().Type(),
)
defer env.Cleanup(ctx)

fmt.Printf("INFO: waiting for cluster %s and all addons to become ready\n", env.Cluster().Name())
if err := <-env.WaitForReady(ctx); err != nil {
fmt.Fprintf(os.Stderr, "Error: testing environment never became ready: %s", err.Error())
os.Exit(26)
}

fmt.Printf("INFO: collecting Kong Proxy URLs from cluster %s for tests to make HTTP calls\n", env.Cluster().Name())
proxyURL, err = kongAddon.ProxyURL(ctx, env.Cluster())
if err != nil {
fmt.Fprintf(os.Stderr, "Error: could not get proxy URL from Kong Addon: %s", err.Error())
os.Exit(27)
}
proxyAdminURL, err = kongAddon.ProxyAdminURL(ctx, env.Cluster())
if err != nil {
fmt.Fprintf(os.Stderr, "Error: could not get proxy URL from Kong Addon: %s", err.Error())
os.Exit(28)
}
proxyUDPURL, err = kongAddon.ProxyUDPURL(ctx, env.Cluster())
if err != nil {
fmt.Fprintf(os.Stderr, "Error: could not get proxy URL from Kong Addon: %s", err.Error())
os.Exit(29)
}

fmt.Println("INFO: testing environment is ready, running tests")
code := m.Run()
os.Exit(code)
}

// CreateNamespace create customized namespace
func CreateNamespace(ctx context.Context, namespace string, t *testing.T) error {
assert.Eventually(t, func() bool {
nsList, err := cluster.Client().CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
nsList, err := env.Cluster().Client().CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return false
}
Expand Down Expand Up @@ -106,7 +128,7 @@ func CreateNamespace(ctx context.Context, namespace string, t *testing.T) error
}

if needDelete {
cluster.Client().CoreV1().Namespaces().Delete(ctx, namespace, metav1.DeleteOptions{})
env.Cluster().Client().CoreV1().Namespaces().Delete(ctx, namespace, metav1.DeleteOptions{})
return false

}
Expand All @@ -121,12 +143,12 @@ func CreateNamespace(ctx context.Context, namespace string, t *testing.T) error
}

t.Logf("creating namespace %s.", namespace)
_, err := cluster.Client().CoreV1().Namespaces().Create(context.Background(), nsName, metav1.CreateOptions{})
_, err := env.Cluster().Client().CoreV1().Namespaces().Create(context.Background(), nsName, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed creating namespace %s, err %v", namespace, err)
}

nsList, err := cluster.Client().CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
nsList, err := env.Cluster().Client().CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
assert.NoError(t, err)
for _, item := range nsList.Items {
if item.Name == namespace && item.Status.Phase == corev1.NamespaceActive {
Expand All @@ -139,7 +161,7 @@ func CreateNamespace(ctx context.Context, namespace string, t *testing.T) error
}

func CleanUpNamespace(ctx context.Context, namespace string, t *testing.T) error {
nsList, err := cluster.Client().CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
nsList, err := env.Cluster().Client().CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return err
}
Expand All @@ -156,7 +178,7 @@ func CleanUpNamespace(ctx context.Context, namespace string, t *testing.T) error
}

if needDelete {
cluster.Client().CoreV1().Namespaces().Delete(ctx, namespace, metav1.DeleteOptions{})
env.Cluster().Client().CoreV1().Namespaces().Delete(ctx, namespace, metav1.DeleteOptions{})
return nil
}
return nil
Expand Down

0 comments on commit 6f3d50c

Please sign in to comment.