Skip to content

Commit

Permalink
commenting out prepared query to validate why acceptance tests are fa…
Browse files Browse the repository at this point in the history
…iling
  • Loading branch information
thisisnotashwin committed Jun 4, 2023
1 parent 2c38012 commit 729fd20
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 43 deletions.
28 changes: 14 additions & 14 deletions acceptance/tests/config-entries/config_entries_namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestControllerNamespaces(t *testing.T) {
require.Equal(r, "sni", terminatingGatewayEntry.Services[0].SNI)

// jwt-provider
entry, _, err = consulClient.ConfigEntries().Get(api.JWTProvider, "jwt-provider", nil)
entry, _, err = consulClient.ConfigEntries().Get(api.JWTProvider, "jwt-provider", defaultOpts)
require.NoError(r, err)
jwtProviderConfigEntry, ok := entry.(*api.JWTProviderConfigEntry)
require.True(r, ok, "could not cast to JWTProviderConfigEntry")
Expand All @@ -227,7 +227,7 @@ func TestControllerNamespaces(t *testing.T) {
require.Equal(r, 15, jwtProviderConfigEntry.CacheConfig.Size)

// exported-services
entry, _, err = consulClient.ConfigEntries().Get(api.ExportedServices, "default", nil)
entry, _, err = consulClient.ConfigEntries().Get(api.ExportedServices, "default", defaultOpts)
require.NoError(r, err)
exportedServicesConfigEntry, ok := entry.(*api.ExportedServicesConfigEntry)
require.True(r, ok, "could not cast to ExportedServicesConfigEntry")
Expand All @@ -238,7 +238,7 @@ func TestControllerNamespaces(t *testing.T) {
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)
entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "controlplanerequestlimit", defaultOpts)
require.NoError(r, err)
rateLimitIPConfigEntry, ok := entry.(*api.RateLimitIPConfigEntry)
require.True(r, ok, "could not cast to RateLimitIPConfigEntry")
Expand All @@ -265,12 +265,12 @@ func TestControllerNamespaces(t *testing.T) {
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.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)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Txn.WriteRate)
})
}

Expand Down Expand Up @@ -318,7 +318,7 @@ func TestControllerNamespaces(t *testing.T) {
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")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "-n", KubeNS, "controlplanerequestlimit", "controlplanerequestlimit", "-p", `{"spec": {"mode": "disabled"}}`, "--type=merge")

counter := &retry.Counter{Count: 20, Wait: 2 * time.Second}
retry.RunWith(counter, t, func(r *retry.R) {
Expand Down Expand Up @@ -388,21 +388,21 @@ func TestControllerNamespaces(t *testing.T) {
require.Equal(r, patchSNI, terminatingGatewayEntry.Services[0].SNI)

// jwt-Provider
entry, _, err = consulClient.ConfigEntries().Get(api.JWTProvider, "jwt-provider", nil)
entry, _, err = consulClient.ConfigEntries().Get(api.JWTProvider, "jwt-provider", defaultOpts)
require.NoError(r, err)
jwtProviderConfigEntry, ok := entry.(*api.JWTProviderConfigEntry)
require.True(r, ok, "could not cast to JWTProviderConfigEntry")
require.Equal(r, patchIssuer, jwtProviderConfigEntry.Issuer)

// exported-services
entry, _, err = consulClient.ConfigEntries().Get(api.ExportedServices, "default", nil)
entry, _, err = consulClient.ConfigEntries().Get(api.ExportedServices, "default", defaultOpts)
require.NoError(r, err)
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)
entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "controlplanerequestlimit", defaultOpts)
require.NoError(r, err)
rateLimitIPConfigEntry, ok := entry.(*api.RateLimitIPConfigEntry)
require.True(r, ok, "could not cast to RateLimitIPConfigEntry")
Expand Down Expand Up @@ -446,7 +446,7 @@ func TestControllerNamespaces(t *testing.T) {
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")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "-n", KubeNS, "controlplanerequestlimit", "controlplanerequestlimit")

counter := &retry.Counter{Count: 20, Wait: 2 * time.Second}
retry.RunWith(counter, t, func(r *retry.R) {
Expand Down Expand Up @@ -496,17 +496,17 @@ func TestControllerNamespaces(t *testing.T) {
require.Contains(r, err.Error(), "404 (Config entry not found")

// jwt-provider
_, _, err = consulClient.ConfigEntries().Get(api.JWTProvider, "jwt-provider", nil)
_, _, err = consulClient.ConfigEntries().Get(api.JWTProvider, "jwt-provider", defaultOpts)
require.Error(r, err)
require.Contains(r, err.Error(), "404 (Config entry not found")

// exported-services
_, _, err = consulClient.ConfigEntries().Get(api.ExportedServices, "default", nil)
_, _, err = consulClient.ConfigEntries().Get(api.ExportedServices, "default", defaultOpts)
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)
_, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "controlplanerequestlimit", defaultOpts)
require.Error(r, err)
require.Contains(r, err.Error(), "404 (Config entry not found")
})
Expand Down
14 changes: 7 additions & 7 deletions acceptance/tests/config-entries/config_entries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestController(t *testing.T) {
require.Equal(r, "groupName", exportedServicesConfigEntry.Services[0].Consumers[1].SamenessGroup)

// control-plane-request-limit
entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil)
entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "controlplanerequestlimit", nil)
require.NoError(r, err)
rateLimitIPConfigEntry, ok := entry.(*api.RateLimitIPConfigEntry)
require.True(r, ok, "could not cast to RateLimitIPConfigEntry")
Expand All @@ -232,8 +232,8 @@ func TestController(t *testing.T) {
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.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)
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestController(t *testing.T) {
k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "exportedservices", "default", "-p", fmt.Sprintf(`{"spec": {"services": [{"name": "frontend", "consumers": [{"peer": "%s"}, {"samenessGroup": "groupName"}]}]}}`, patchPeer), "--type=merge")

logger.Log(t, "patching control-plane-request-limit custom resource")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "controlplanerequestlimit", "control-plane-request-limit", "-p", `{"spec": {"mode": "disabled"}}`, "--type=merge")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "patch", "controlplanerequestlimit", "controlplanerequestlimit", "-p", `{"spec": {"mode": "disabled"}}`, "--type=merge")

counter := &retry.Counter{Count: 10, Wait: 500 * time.Millisecond}
retry.RunWith(counter, t, func(r *retry.R) {
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestController(t *testing.T) {
require.Equal(r, patchPeer, exportedServicesConfigEntry.Services[0].Consumers[0].Peer)

// control-plane-request-limit
entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "control-plane-request-limit", nil)
entry, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "controlplanerequestlimit", nil)
require.NoError(r, err)
rateLimitIPConfigEntry, ok := entry.(*api.RateLimitIPConfigEntry)
require.True(r, ok, "could not cast to RateLimitIPConfigEntry")
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestController(t *testing.T) {
k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "exportedservices", "default")

logger.Log(t, "deleting control-plane-request-limit custom resource")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "controlplanerequestlimit", "control-plane-request-limit")
k8s.RunKubectl(t, ctx.KubectlOptions(t), "delete", "controlplanerequestlimit", "controlplanerequestlimit")

counter := &retry.Counter{Count: 10, Wait: 500 * time.Millisecond}
retry.RunWith(counter, t, func(r *retry.R) {
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestController(t *testing.T) {
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)
_, _, err = consulClient.ConfigEntries().Get(api.RateLimitIPConfig, "controlplanerequestlimit", nil)
require.Error(r, err)
require.Contains(r, err.Error(), "404 (Config entry not found")
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
apiVersion: consul.hashicorp.com/v1alpha1
kind: ControlPlaneRequestLimit
metadata:
name: control-plane-request-limit
name: controlplanerequestlimit
spec:
mode: "permissive"
readRate: 100.0
Expand Down Expand Up @@ -39,9 +39,9 @@ spec:
tenancy:
readRate: 100.0
writeRate: 100.0
preparedQuery:
readRate: 100.0
writeRate: 100.0
# preparedQuery:
# readRate: 100.0
# writeRate: 100.0
session:
readRate: 100.0
writeRate: 100.0
Expand Down
4 changes: 2 additions & 2 deletions control-plane/api/v1alpha1/controlplanerequestlimit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ func (c *ControlPlaneRequestLimit) ConsulKind() string {
// ConsulGlobalResource returns if the resource exists in the default
// Consul namespace only.
func (c *ControlPlaneRequestLimit) ConsulGlobalResource() bool {
return false
return true
}

// ConsulMirroringNS returns the Consul namespace that the config entry should
// be created in if namespaces and mirroring are enabled.
func (c *ControlPlaneRequestLimit) ConsulMirroringNS() string {
return c.Namespace
return common.DefaultConsulNamespace
}

// KubeKind returns the Kube config entry kind, i.e. servicedefaults, not
Expand Down
33 changes: 17 additions & 16 deletions control-plane/api/v1alpha1/controlplanerequestlimit_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,21 @@ func TestControlPlaneRequestLimit_Validate(t *testing.T) {
Name: common.ControlPlaneRequestLimit,
},
Spec: ControlPlaneRequestLimitSpec{
Mode: "permissive",
ACL: validReadWriteRatesConfig,
Catalog: validReadWriteRatesConfig,
ConfigEntry: validReadWriteRatesConfig,
ConnectCA: validReadWriteRatesConfig,
Coordinate: validReadWriteRatesConfig,
DiscoveryChain: validReadWriteRatesConfig,
Health: validReadWriteRatesConfig,
Intention: validReadWriteRatesConfig,
KV: validReadWriteRatesConfig,
Tenancy: validReadWriteRatesConfig,
PreparedQuery: validReadWriteRatesConfig,
Session: validReadWriteRatesConfig,
Txn: validReadWriteRatesConfig,
Mode: "permissive",
ReadWriteRatesConfig: *validReadWriteRatesConfig,
ACL: validReadWriteRatesConfig,
Catalog: validReadWriteRatesConfig,
ConfigEntry: validReadWriteRatesConfig,
ConnectCA: validReadWriteRatesConfig,
Coordinate: validReadWriteRatesConfig,
DiscoveryChain: validReadWriteRatesConfig,
Health: validReadWriteRatesConfig,
Intention: validReadWriteRatesConfig,
KV: validReadWriteRatesConfig,
Tenancy: validReadWriteRatesConfig,
PreparedQuery: validReadWriteRatesConfig,
Session: validReadWriteRatesConfig,
Txn: validReadWriteRatesConfig,
},
},
expectedErrMsgs: []string{},
Expand Down Expand Up @@ -546,11 +547,11 @@ func TestControlPlaneRequestLimit_KubernetesName(t *testing.T) {
}

func TestControlPlaneRequestLimit_ConsulNamespace(t *testing.T) {
require.Equal(t, "bar", (&ControlPlaneRequestLimit{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "bar"}}).ConsulMirroringNS())
require.Equal(t, "default", (&ControlPlaneRequestLimit{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "bar"}}).ConsulMirroringNS())
}

func TestControlPlaneRequestLimit_ConsulGlobalResource(t *testing.T) {
require.False(t, (&ControlPlaneRequestLimit{}).ConsulGlobalResource())
require.True(t, (&ControlPlaneRequestLimit{}).ConsulGlobalResource())
}

func TestControlPlaneRequestLimit_ObjectMeta(t *testing.T) {
Expand Down

0 comments on commit 729fd20

Please sign in to comment.