From b10fa5a99272650f4b3dbae65cb072a959c9bbae Mon Sep 17 00:00:00 2001 From: Dan Bond Date: Fri, 2 Jun 2023 14:10:22 -0700 Subject: [PATCH] add namespace acceptance tests Signed-off-by: Dan Bond --- .../config_entries_namespaces_test.go | 53 +++++++++++++++++++ .../config-entries/config_entries_test.go | 5 ++ .../bases/crds-oss/kustomization.yaml | 2 + 3 files changed, 60 insertions(+) diff --git a/acceptance/tests/config-entries/config_entries_namespaces_test.go b/acceptance/tests/config-entries/config_entries_namespaces_test.go index c15277a6ee..7d7f16a480 100644 --- a/acceptance/tests/config-entries/config_entries_namespaces_test.go +++ b/acceptance/tests/config-entries/config_entries_namespaces_test.go @@ -216,6 +216,41 @@ func TestControllerNamespaces(t *testing.T) { require.Equal(r, "certFile", terminatingGatewayEntry.Services[0].CertFile) require.Equal(r, "keyFile", terminatingGatewayEntry.Services[0].KeyFile) require.Equal(r, "sni", terminatingGatewayEntry.Services[0].SNI) + + // control-plane-request-limit + entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil) + require.NoError(r, err) + rateLimitIPConfigEntry, ok := entry.(*api.RateLimitIPConfigEntry) + require.True(r, ok, "could not cast to RateLimitIPConfigEntry") + require.Equal(t, "permissive", rateLimitIPConfigEntry.Mode) + require.Equal(t, 100.0, rateLimitIPConfigEntry.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.ACL.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.ACL.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Catalog.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Catalog.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.ConfigEntry.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.ConfigEntry.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.ConnectCA.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.ConnectCA.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Coordinate.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Coordinate.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.DiscoveryChain.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.DiscoveryChain.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Health.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Health.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Intention.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Intention.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.KV.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.KV.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Tenancy.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Tenancy.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.PreparedQuery.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.PreparedQuery.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Session.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Session.WriteRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Txn.ReadRate) + require.Equal(t, 100.0, rateLimitIPConfigEntry.Txn.WriteRate, 100.0) }) } @@ -258,6 +293,9 @@ func TestControllerNamespaces(t *testing.T) { patchSNI := "patch-sni" k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "-n", KubeNS, "terminatinggateway", "terminating-gateway", "-p", fmt.Sprintf(`{"spec": {"services": [{"name":"name","caFile":"caFile","certFile":"certFile","keyFile":"keyFile","sni":"%s"}]}}`, patchSNI), "--type=merge") + logger.Log(t, "patching control-plane-request-limit custom resource") + k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "-n", KubeNS, "controlplanerequestlimit", "control-plane-request-limit", "-p", `{"spec": {"mode": "disabled"}}`, "--type=merge") + counter := &retry.Counter{Count: 20, Wait: 2 * time.Second} retry.RunWith(counter, t, func(r *retry.R) { // service-defaults @@ -331,6 +369,13 @@ func TestControllerNamespaces(t *testing.T) { terminatingGatewayEntry, ok := entry.(*api.TerminatingGatewayConfigEntry) require.True(r, ok, "could not cast to TerminatingGatewayConfigEntry") require.Equal(r, patchSNI, terminatingGatewayEntry.Services[0].SNI) + + // control-plane-request-limit + entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil) + require.NoError(r, err) + rateLimitIPConfigEntry, ok := entry.(*api.RateLimitIPConfigEntry) + require.True(r, ok, "could not cast to RateLimitIPConfigEntry") + require.Equal(r, rateLimitIPConfigEntry.Mode, "disabled") }) } @@ -366,6 +411,9 @@ func TestControllerNamespaces(t *testing.T) { logger.Log(t, "deleting terminating-gateway custom resource") k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "-n", KubeNS, "terminatinggateway", "terminating-gateway") + logger.Log(t, "deleting control-plane-request-limit custom resource") + k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "-n", KubeNS, "controlplanerequestlimit", "control-plane-request-limit") + counter := &retry.Counter{Count: 20, Wait: 2 * time.Second} retry.RunWith(counter, t, func(r *retry.R) { // service-defaults @@ -417,6 +465,11 @@ func TestControllerNamespaces(t *testing.T) { _, _, err = consulClient.ConfigEntries().Get(api.IngressGateway, "terminating-gateway", queryOpts) require.Error(r, err) require.Contains(r, err.Error(), "404 (Config entry not found") + + // control-plane-request-limit + _, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil) + require.Error(r, err) + require.Contains(r, err.Error(), "404 (Config entry not found") }) } }) diff --git a/acceptance/tests/config-entries/config_entries_test.go b/acceptance/tests/config-entries/config_entries_test.go index 4bda5623c8..cc34d22404 100644 --- a/acceptance/tests/config-entries/config_entries_test.go +++ b/acceptance/tests/config-entries/config_entries_test.go @@ -425,6 +425,11 @@ func TestController(t *testing.T) { _, _, err = consulClient.ConfigEntries().Get(api.TerminatingGateway, "terminating-gateway", nil) require.Error(r, err) require.Contains(r, err.Error(), "404 (Config entry not found") + + // control-plane-request-limit + _, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil) + require.Error(r, err) + require.Contains(r, err.Error(), "404 (Config entry not found") }) } }) diff --git a/acceptance/tests/fixtures/bases/crds-oss/kustomization.yaml b/acceptance/tests/fixtures/bases/crds-oss/kustomization.yaml index 1217d857c8..c3df6aba0f 100644 --- a/acceptance/tests/fixtures/bases/crds-oss/kustomization.yaml +++ b/acceptance/tests/fixtures/bases/crds-oss/kustomization.yaml @@ -11,3 +11,5 @@ resources: - servicerouter.yaml - servicesplitter.yaml - terminatinggateway.yaml + - jwtprovider.yaml + - controlplanerequestlimit.yaml