Skip to content

Commit

Permalink
test(*) remove legacy test path and gates
Browse files Browse the repository at this point in the history
Remove the integration test functionality for starting a legacy (v1)
controller and test gates that skipped tests not applicable to v1.
  • Loading branch information
Travis Raines authored and rainest committed Jul 29, 2021
1 parent 2411efd commit 0a503e5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 114 deletions.
9 changes: 0 additions & 9 deletions test/integration/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ func TestHealthEndpoint(t *testing.T) {
}

func TestMetricsEndpoint(t *testing.T) {
if useLegacyKIC() {
t.Skip("metrics endpoint test does not apply to legacy KIC")
}
assert.Eventually(t, func() bool {
metricsURL := fmt.Sprintf("http://localhost:%v/metrics", manager.MetricsPort)
resp, err := httpc.Get(metricsURL)
Expand Down Expand Up @@ -58,9 +55,6 @@ func TestMetricsEndpoint(t *testing.T) {
}

func TestProfilingEndpoint(t *testing.T) {
if useLegacyKIC() {
t.Skip("profiling endpoint behaves differently in legacy KIC")
}
assert.Eventually(t, func() bool {
profilingURL := fmt.Sprintf("http://localhost:%v/debug/pprof/", manager.DiagnosticsPort)
resp, err := httpc.Get(profilingURL)
Expand All @@ -74,9 +68,6 @@ func TestProfilingEndpoint(t *testing.T) {
}

func TestConfigEndpoint(t *testing.T) {
if useLegacyKIC() {
t.Skip("config endpoint not available in legacy KIC")
}
assert.Eventually(t, func() bool {
successURL := fmt.Sprintf("http://localhost:%v/debug/config/successful", manager.DiagnosticsPort)
failURL := fmt.Sprintf("http://localhost:%v/debug/config/failed", manager.DiagnosticsPort)
Expand Down
3 changes: 0 additions & 3 deletions test/integration/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,6 @@ func TestIngressClassNameSpec(t *testing.T) {
}

func TestIngressNamespaces(t *testing.T) {
if useLegacyKIC() {
t.Skip("support for distinct namespace watches is not supported in legacy KIC")
}
ctx := context.Background()

// ensure the alternative namespace is created
Expand Down
4 changes: 0 additions & 4 deletions test/integration/knative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const (
)

func TestKnativeIngress(t *testing.T) {
if useLegacyKIC() {
t.Skip("knative is supported in KIC 1.3.x and skip in legacy KIC")
}

cluster := env.Cluster()
proxy := proxyURL.Hostname()
assert.NotEmpty(t, proxy)
Expand Down
124 changes: 34 additions & 90 deletions test/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -63,9 +62,6 @@ const (
// -----------------------------------------------------------------------------

var (
// LegacyControllerEnvVar indicates the environment variable which can be used to trigger tests against the legacy KIC controller-manager
LegacyControllerEnvVar = "KONG_LEGACY_CONTROLLER"

// httpc is the default HTTP client to use for tests
httpc = http.Client{Timeout: httpcTimeout}

Expand Down Expand Up @@ -223,14 +219,6 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

// -----------------------------------------------------------------------------
// Testing Helper Functions
// -----------------------------------------------------------------------------

func useLegacyKIC() bool {
return os.Getenv(LegacyControllerEnvVar) != ""
}

// -----------------------------------------------------------------------------
// Testing Main - Controller Deployment
// -----------------------------------------------------------------------------
Expand All @@ -245,7 +233,7 @@ var crds = []string{
knativeCrds,
}

// deployControllers ensures that relevant CRDs and controllers are deployed to the test cluster and supports legacy (KIC 1.x) clusters as well.
// deployControllers ensures that relevant CRDs and controllers are deployed to the test cluster
func deployControllers(ctx context.Context, namespace string) error {
// ensure the controller namespace is created
ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
Expand Down Expand Up @@ -285,86 +273,42 @@ func deployControllers(ctx context.Context, namespace string) error {
}
}

// if set, allow running the legacy controller for the tests instead of the current controller
var cmd *exec.Cmd
if useLegacyKIC() {
cmd = buildLegacyCommand(ctx, kubeconfig.Name())
stdout, stderr := new(bytes.Buffer), new(bytes.Buffer)
cmd.Stdout = io.MultiWriter(stdout, os.Stdout)
cmd.Stderr = io.MultiWriter(stderr, os.Stderr)
if err := cmd.Run(); err != nil {
fmt.Fprintln(os.Stdout, stdout.String())
panic(fmt.Errorf("%s: %w", stderr.String(), err))
}
} else {
config := manager.Config{}
flags := config.FlagSet()
if err := flags.Parse([]string{
fmt.Sprintf("--kong-admin-url=http://%s:8001", proxyAdminURL.Hostname()),
fmt.Sprintf("--kubeconfig=%s", kubeconfig.Name()),
"--controller-kongstate=enabled",
"--controller-ingress-networkingv1=enabled",
"--controller-ingress-networkingv1beta1=enabled",
"--controller-ingress-extensionsv1beta1=enabled",
"--controller-tcpingress=enabled",
"--controller-kongingress=enabled",
"--controller-knativeingress=enabled",
"--controller-kongclusterplugin=enabled",
"--controller-kongplugin=enabled",
"--controller-kongconsumer=disabled",
"--dump-config",
"--election-id=integrationtests.konghq.com",
"--publish-service=kong-system/ingress-controller-kong-proxy",
fmt.Sprintf("--watch-namespace=%s", watchNamespaces),
fmt.Sprintf("--ingress-class=%s", ingressClass),
"--log-level=trace",
"--log-format=text",
"--debug-log-reduce-redundancy",
"--admission-webhook-listen=172.17.0.1:49023",
fmt.Sprintf("--admission-webhook-cert=%s", admissionWebhookCert),
fmt.Sprintf("--admission-webhook-key=%s", admissionWebhookKey),
"--profiling",
}); err != nil {
panic(fmt.Errorf("could not parse controller manager flags: %w", err))
}
fmt.Fprintf(os.Stderr, "config: %+v\n", config)
config := manager.Config{}
flags := config.FlagSet()
if err := flags.Parse([]string{
fmt.Sprintf("--kong-admin-url=http://%s:8001", proxyAdminURL.Hostname()),
fmt.Sprintf("--kubeconfig=%s", kubeconfig.Name()),
"--controller-kongstate=enabled",
"--controller-ingress-networkingv1=enabled",
"--controller-ingress-networkingv1beta1=enabled",
"--controller-ingress-extensionsv1beta1=enabled",
"--controller-tcpingress=enabled",
"--controller-kongingress=enabled",
"--controller-knativeingress=enabled",
"--controller-kongclusterplugin=enabled",
"--controller-kongplugin=enabled",
"--controller-kongconsumer=disabled",
"--dump-config",
"--election-id=integrationtests.konghq.com",
"--publish-service=kong-system/ingress-controller-kong-proxy",
fmt.Sprintf("--watch-namespace=%s", watchNamespaces),
fmt.Sprintf("--ingress-class=%s", ingressClass),
"--log-level=trace",
"--log-format=text",
"--debug-log-reduce-redundancy",
"--admission-webhook-listen=172.17.0.1:49023",
fmt.Sprintf("--admission-webhook-cert=%s", admissionWebhookCert),
fmt.Sprintf("--admission-webhook-key=%s", admissionWebhookKey),
"--profiling",
}); err != nil {
panic(fmt.Errorf("could not parse controller manager flags: %w", err))
}
fmt.Fprintf(os.Stderr, "config: %+v\n", config)

if err := rootcmd.Run(ctx, &config); err != nil {
panic(fmt.Errorf("controller manager exited with error: %w", err))
}
if err := rootcmd.Run(ctx, &config); err != nil {
panic(fmt.Errorf("controller manager exited with error: %w", err))
}
}()

return nil
}

func buildLegacyCommand(ctx context.Context, kubeconfigPath string) *exec.Cmd {
fmt.Fprintln(os.Stderr, "WARNING: deploying legacy Kong Kubernetes Ingress Controller (KIC)")

// get the proxy pod
podList, err := env.Cluster().Client().CoreV1().Pods("kong-system").List(ctx, metav1.ListOptions{
LabelSelector: "app.kubernetes.io/component=app,app.kubernetes.io/instance=ingress-controller,app.kubernetes.io/name=kong",
})
if err != nil {
panic(err)
}
if len(podList.Items) != 1 {
panic(fmt.Errorf("expected 1 result, found %d", len(podList.Items)))
}
proxyPod := podList.Items[0].Name

// custom command for the legacy controller as there are several differences in flags.
cmd := exec.CommandContext(ctx, "go", "run", "../../../cli/ingress-controller/",
"--publish-service", "kong-system/ingress-controller-kong-proxy",
"--kubeconfig", kubeconfigPath,
"--kong-admin-url", fmt.Sprintf("http://%s:8001", proxyAdminURL.Hostname()),
"--ingress-class", ingressClass)

// set the environment according to the legacy controller's needs
cmd.Env = append(os.Environ(),
"POD_NAMESPACE=kong-system",
fmt.Sprintf("POD_NAME=%s", proxyPod),
)

return cmd
}
5 changes: 0 additions & 5 deletions test/integration/udpingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ import (
const testUDPIngressNamespace = "udpingress"

func TestUDPIngressEssentials(t *testing.T) {
// TODO: once KIC 2.0 lands and pre v2 is gone, we can remove this check
if useLegacyKIC() {
t.Skip("legacy KIC does not support UDPIngress, skipping")
}

testName := "minudp"
ctx, cancel := context.WithTimeout(context.Background(), ingressWait)
defer cancel()
Expand Down
3 changes: 0 additions & 3 deletions test/integration/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import (
const defaultNs = "default"

func TestValidationWebhook(t *testing.T) {
if useLegacyKIC() {
t.Skip("not testing validation webhook for KIC 1.x")
}
ctx := context.Background()

const webhookSvcName = "validations"
Expand Down

0 comments on commit 0a503e5

Please sign in to comment.