From bc9dd17781f64bf3a077a7077342f928700c7d69 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 | 3 +- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/acceptance/tests/config-entries/config_entries_namespaces_test.go b/acceptance/tests/config-entries/config_entries_namespaces_test.go index 507b1a07af..7dcc839226 100644 --- a/acceptance/tests/config-entries/config_entries_namespaces_test.go +++ b/acceptance/tests/config-entries/config_entries_namespaces_test.go @@ -236,6 +236,41 @@ func TestControllerNamespaces(t *testing.T) { require.Equal(r, "partitionName", exportedServicesConfigEntry.Services[0].Consumers[0].Partition) require.Equal(r, "peerName", exportedServicesConfigEntry.Services[0].Consumers[1].Peer) require.Equal(r, "groupName", exportedServicesConfigEntry.Services[0].Consumers[2].SamenessGroup) + + // 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) }) } @@ -282,6 +317,9 @@ func TestControllerNamespaces(t *testing.T) { patchPartition := "destination" k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "-n", KubeNS, "exportedservices", "default", "-p", fmt.Sprintf(`{"spec": {"services": [{"name": "frontend", "namespace": "frontend", "consumers": [{"partition": "%s"}, {"peer": "peerName"}, {"samenessGroup": "groupName"}]}]}}`, patchPartition), "--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 @@ -362,6 +400,13 @@ func TestControllerNamespaces(t *testing.T) { exportedServicesConfigEntry, ok := entry.(*api.ExportedServicesConfigEntry) require.True(r, ok, "could not cast to ExportedServicesConfigEntry") require.Equal(r, patchPartition, exportedServicesConfigEntry.Services[0].Consumers[0].Partition) + + // 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") }) } @@ -400,6 +445,9 @@ func TestControllerNamespaces(t *testing.T) { logger.Log(t, "deleting exported-services custom resource") k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "-n", KubeNS, "exportedservices", "default") + 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 @@ -456,6 +504,11 @@ func TestControllerNamespaces(t *testing.T) { _, _, err = consulClient.ConfigEntries().Get(api.ExportedServices, "default", 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/config-entries/config_entries_test.go b/acceptance/tests/config-entries/config_entries_test.go index 3d65d78b38..ff1698b7d0 100644 --- a/acceptance/tests/config-entries/config_entries_test.go +++ b/acceptance/tests/config-entries/config_entries_test.go @@ -505,6 +505,11 @@ func TestController(t *testing.T) { _, _, 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") + + // 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 de02de61e9..77afbc9522 100644 --- a/acceptance/tests/fixtures/bases/crds-oss/kustomization.yaml +++ b/acceptance/tests/fixtures/bases/crds-oss/kustomization.yaml @@ -12,4 +12,5 @@ resources: - servicesplitter.yaml - terminatinggateway.yaml - jwtprovider.yaml -- exportedservices.yaml \ No newline at end of file +- exportedservices.yaml +- controlplanerequestlimit.yaml \ No newline at end of file