mirror of https://github.com/status-im/consul.git
[OSS] Pull split ns/partition var out of testing file (#13337)
The api module previously had defaultPartition and defaultNamespace vars for when we need default/empty split usage between ent/oss respectively. This commit moves those two variables out of test code so that they can be used for the service exports config entry's `GetNamespace()` method. Previously `GetNamespace()` would return "default" in both OSS and enterprise, which can trip up automation that passes the result of this method as the namespace to write a config entry. The split vars are kept private to prevent external usage, and prefixed with `split` for more clarity about their behavior.
This commit is contained in:
parent
1b69366a39
commit
143dc75e0d
|
@ -363,7 +363,7 @@ func TestAPI_AgentServicesWithFilterOpts(t *testing.T) {
|
|||
}
|
||||
require.NoError(t, agent.ServiceRegister(reg))
|
||||
|
||||
opts := &QueryOptions{Namespace: defaultNamespace}
|
||||
opts := &QueryOptions{Namespace: splitDefaultNamespace}
|
||||
services, err := agent.ServicesWithFilterOpts("foo in Tags", opts)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, services, 1)
|
||||
|
@ -791,8 +791,8 @@ func TestAPI_AgentService(t *testing.T) {
|
|||
Warning: 1,
|
||||
},
|
||||
Meta: map[string]string{},
|
||||
Namespace: defaultNamespace,
|
||||
Partition: defaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Datacenter: "dc1",
|
||||
}
|
||||
require.Equal(t, expect, got)
|
||||
|
@ -932,7 +932,7 @@ func TestAPI_AgentUpdateTTLOpts(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
opts := &QueryOptions{Namespace: defaultNamespace}
|
||||
opts := &QueryOptions{Namespace: splitDefaultNamespace}
|
||||
|
||||
if err := agent.UpdateTTLOpts("service:foo", "foo", HealthWarning, opts); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -1007,7 +1007,7 @@ func TestAPI_AgentChecksWithFilterOpts(t *testing.T) {
|
|||
reg.TTL = "15s"
|
||||
require.NoError(t, agent.CheckRegister(reg))
|
||||
|
||||
opts := &QueryOptions{Namespace: defaultNamespace}
|
||||
opts := &QueryOptions{Namespace: splitDefaultNamespace}
|
||||
checks, err := agent.ChecksWithFilterOpts("Name == foo", opts)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, checks, 1)
|
||||
|
@ -1382,7 +1382,7 @@ func TestAPI_ServiceMaintenanceOpts(t *testing.T) {
|
|||
}
|
||||
|
||||
// Specify namespace in query option
|
||||
opts := &QueryOptions{Namespace: defaultNamespace}
|
||||
opts := &QueryOptions{Namespace: splitDefaultNamespace}
|
||||
|
||||
// Enable maintenance mode
|
||||
if err := agent.EnableServiceMaintenanceOpts("redis", "broken", opts); err != nil {
|
||||
|
@ -1701,7 +1701,7 @@ func TestAPI_AgentHealthServiceOpts(t *testing.T) {
|
|||
requireServiceHealthID := func(t *testing.T, serviceID, expected string, shouldExist bool) {
|
||||
msg := fmt.Sprintf("service id:%s, shouldExist:%v, expectedStatus:%s : bad %%s", serviceID, shouldExist, expected)
|
||||
|
||||
opts := &QueryOptions{Namespace: defaultNamespace}
|
||||
opts := &QueryOptions{Namespace: splitDefaultNamespace}
|
||||
state, out, err := agent.AgentHealthServiceByIDOpts(serviceID, opts)
|
||||
require.Nil(t, err, msg, "err")
|
||||
require.Equal(t, expected, state, msg, "state")
|
||||
|
@ -1715,7 +1715,7 @@ func TestAPI_AgentHealthServiceOpts(t *testing.T) {
|
|||
requireServiceHealthName := func(t *testing.T, serviceName, expected string, shouldExist bool) {
|
||||
msg := fmt.Sprintf("service name:%s, shouldExist:%v, expectedStatus:%s : bad %%s", serviceName, shouldExist, expected)
|
||||
|
||||
opts := &QueryOptions{Namespace: defaultNamespace}
|
||||
opts := &QueryOptions{Namespace: splitDefaultNamespace}
|
||||
state, outs, err := agent.AgentHealthServiceByNameOpts(serviceName, opts)
|
||||
require.Nil(t, err, msg, "err")
|
||||
require.Equal(t, expected, state, msg, "state")
|
||||
|
|
|
@ -51,7 +51,7 @@ func TestAPI_CatalogNodes(t *testing.T) {
|
|||
{
|
||||
ID: s.Config.NodeID,
|
||||
Node: s.Config.NodeName,
|
||||
Partition: defaultPartition,
|
||||
Partition: splitDefaultPartition,
|
||||
Address: "127.0.0.1",
|
||||
Datacenter: "dc1",
|
||||
TaggedAddresses: map[string]string{
|
||||
|
@ -1152,8 +1152,8 @@ func TestAPI_CatalogGatewayServices_Terminating(t *testing.T) {
|
|||
|
||||
expect := []*GatewayService{
|
||||
{
|
||||
Service: CompoundServiceName{Name: "api", Namespace: defaultNamespace, Partition: defaultPartition},
|
||||
Gateway: CompoundServiceName{Name: "terminating", Namespace: defaultNamespace, Partition: defaultPartition},
|
||||
Service: CompoundServiceName{Name: "api", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
|
||||
Gateway: CompoundServiceName{Name: "terminating", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
|
||||
GatewayKind: ServiceKindTerminatingGateway,
|
||||
CAFile: "api/ca.crt",
|
||||
CertFile: "api/client.crt",
|
||||
|
@ -1161,8 +1161,8 @@ func TestAPI_CatalogGatewayServices_Terminating(t *testing.T) {
|
|||
SNI: "my-domain",
|
||||
},
|
||||
{
|
||||
Service: CompoundServiceName{Name: "redis", Namespace: defaultNamespace, Partition: defaultPartition},
|
||||
Gateway: CompoundServiceName{Name: "terminating", Namespace: defaultNamespace, Partition: defaultPartition},
|
||||
Service: CompoundServiceName{Name: "redis", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
|
||||
Gateway: CompoundServiceName{Name: "terminating", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
|
||||
GatewayKind: ServiceKindTerminatingGateway,
|
||||
CAFile: "ca.crt",
|
||||
CertFile: "client.crt",
|
||||
|
@ -1220,15 +1220,15 @@ func TestAPI_CatalogGatewayServices_Ingress(t *testing.T) {
|
|||
|
||||
expect := []*GatewayService{
|
||||
{
|
||||
Service: CompoundServiceName{Name: "api", Namespace: defaultNamespace, Partition: defaultPartition},
|
||||
Gateway: CompoundServiceName{Name: "ingress", Namespace: defaultNamespace, Partition: defaultPartition},
|
||||
Service: CompoundServiceName{Name: "api", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
|
||||
Gateway: CompoundServiceName{Name: "ingress", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
|
||||
GatewayKind: ServiceKindIngressGateway,
|
||||
Protocol: "tcp",
|
||||
Port: 8888,
|
||||
},
|
||||
{
|
||||
Service: CompoundServiceName{Name: "redis", Namespace: defaultNamespace, Partition: defaultPartition},
|
||||
Gateway: CompoundServiceName{Name: "ingress", Namespace: defaultNamespace, Partition: defaultPartition},
|
||||
Service: CompoundServiceName{Name: "redis", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
|
||||
Gateway: CompoundServiceName{Name: "ingress", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
|
||||
GatewayKind: ServiceKindIngressGateway,
|
||||
Protocol: "tcp",
|
||||
Port: 9999,
|
||||
|
|
|
@ -139,8 +139,8 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
|||
entry: &ServiceResolverConfigEntry{
|
||||
Kind: ServiceResolver,
|
||||
Name: "test-failover",
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
DefaultSubset: "v1",
|
||||
Subsets: map[string]ServiceResolverSubset{
|
||||
"v1": {
|
||||
|
@ -156,7 +156,7 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
|||
},
|
||||
"v1": {
|
||||
Service: "alternate",
|
||||
Namespace: defaultNamespace,
|
||||
Namespace: splitDefaultNamespace,
|
||||
},
|
||||
},
|
||||
ConnectTimeout: 5 * time.Second,
|
||||
|
@ -172,12 +172,12 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
|||
entry: &ServiceResolverConfigEntry{
|
||||
Kind: ServiceResolver,
|
||||
Name: "test-redirect",
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
Redirect: &ServiceResolverRedirect{
|
||||
Service: "test-failover",
|
||||
ServiceSubset: "v2",
|
||||
Namespace: defaultNamespace,
|
||||
Namespace: splitDefaultNamespace,
|
||||
Datacenter: "d",
|
||||
},
|
||||
},
|
||||
|
@ -188,14 +188,14 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
|||
entry: &ServiceSplitterConfigEntry{
|
||||
Kind: ServiceSplitter,
|
||||
Name: "test-split",
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
Splits: []ServiceSplit{
|
||||
{
|
||||
Weight: 90,
|
||||
Service: "test-failover",
|
||||
ServiceSubset: "v1",
|
||||
Namespace: defaultNamespace,
|
||||
Namespace: splitDefaultNamespace,
|
||||
RequestHeaders: &HTTPHeaderModifiers{
|
||||
Set: map[string]string{
|
||||
"x-foo": "bar",
|
||||
|
@ -208,7 +208,7 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
|||
{
|
||||
Weight: 10,
|
||||
Service: "test-redirect",
|
||||
Namespace: defaultNamespace,
|
||||
Namespace: splitDefaultNamespace,
|
||||
},
|
||||
},
|
||||
Meta: map[string]string{
|
||||
|
@ -223,8 +223,8 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
|||
entry: &ServiceRouterConfigEntry{
|
||||
Kind: ServiceRouter,
|
||||
Name: "test-route",
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
Routes: []ServiceRoute{
|
||||
{
|
||||
Match: &ServiceRouteMatch{
|
||||
|
@ -241,8 +241,8 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
|
|||
Destination: &ServiceRouteDestination{
|
||||
Service: "test-failover",
|
||||
ServiceSubset: "v2",
|
||||
Namespace: defaultNamespace,
|
||||
Partition: defaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
PrefixRewrite: "/",
|
||||
RequestTimeout: 5 * time.Second,
|
||||
NumRetries: 5,
|
||||
|
@ -334,8 +334,8 @@ func TestAPI_ConfigEntry_ServiceResolver_LoadBalancer(t *testing.T) {
|
|||
entry: &ServiceResolverConfigEntry{
|
||||
Kind: ServiceResolver,
|
||||
Name: "test-least-req",
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
LoadBalancer: &LoadBalancer{
|
||||
Policy: "least_request",
|
||||
LeastRequestConfig: &LeastRequestConfig{ChoiceCount: 10},
|
||||
|
@ -348,8 +348,8 @@ func TestAPI_ConfigEntry_ServiceResolver_LoadBalancer(t *testing.T) {
|
|||
entry: &ServiceResolverConfigEntry{
|
||||
Kind: ServiceResolver,
|
||||
Name: "test-ring-hash",
|
||||
Namespace: defaultNamespace,
|
||||
Partition: defaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
LoadBalancer: &LoadBalancer{
|
||||
Policy: "ring_hash",
|
||||
RingHashConfig: &RingHashConfig{
|
||||
|
|
|
@ -57,7 +57,7 @@ type ServiceConsumer struct {
|
|||
func (e *ExportedServicesConfigEntry) GetKind() string { return ExportedServices }
|
||||
func (e *ExportedServicesConfigEntry) GetName() string { return e.Name }
|
||||
func (e *ExportedServicesConfigEntry) GetPartition() string { return e.Name }
|
||||
func (e *ExportedServicesConfigEntry) GetNamespace() string { return IntentionDefaultNamespace }
|
||||
func (e *ExportedServicesConfigEntry) GetNamespace() string { return splitDefaultNamespace }
|
||||
func (e *ExportedServicesConfigEntry) GetMeta() map[string]string { return e.Meta }
|
||||
func (e *ExportedServicesConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
|
||||
func (e *ExportedServicesConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestAPI_ConfigEntries_ExportedServices(t *testing.T) {
|
|||
testutil.RunStep(t, "set and get", func(t *testing.T) {
|
||||
exports := &ExportedServicesConfigEntry{
|
||||
Name: PartitionDefaultName,
|
||||
Partition: defaultPartition,
|
||||
Partition: splitDefaultPartition,
|
||||
Meta: map[string]string{
|
||||
"gir": "zim",
|
||||
},
|
||||
|
@ -48,7 +48,7 @@ func TestAPI_ConfigEntries_ExportedServices(t *testing.T) {
|
|||
Services: []ExportedService{
|
||||
{
|
||||
Name: "db",
|
||||
Namespace: defaultNamespace,
|
||||
Namespace: splitDefaultNamespace,
|
||||
Consumers: []ServiceConsumer{
|
||||
{
|
||||
PeerName: "alpha",
|
||||
|
@ -60,7 +60,7 @@ func TestAPI_ConfigEntries_ExportedServices(t *testing.T) {
|
|||
"foo": "bar",
|
||||
"gir": "zim",
|
||||
},
|
||||
Partition: defaultPartition,
|
||||
Partition: splitDefaultPartition,
|
||||
}
|
||||
|
||||
_, wm, err := entries.Set(updated, nil)
|
||||
|
|
|
@ -213,8 +213,8 @@ func TestAPI_ConfigEntries(t *testing.T) {
|
|||
"foo": "bar",
|
||||
"gir": "zim",
|
||||
},
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
}
|
||||
ce := c.ConfigEntries()
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ func TestAPI_CoordinateUpdate(t *testing.T) {
|
|||
newCoord.Height = 0.5
|
||||
entry := &CoordinateEntry{
|
||||
Node: node,
|
||||
Partition: defaultPartition,
|
||||
Partition: splitDefaultPartition,
|
||||
Coord: newCoord,
|
||||
}
|
||||
_, err = coord.Update(entry, nil)
|
||||
|
|
|
@ -223,8 +223,8 @@ func TestAPI_HealthChecks(t *testing.T) {
|
|||
ServiceName: "foo",
|
||||
ServiceTags: []string{"bar"},
|
||||
Type: "ttl",
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
//go:build !consulent
|
||||
// +build !consulent
|
||||
|
||||
package api
|
||||
|
||||
// The following defaults return "default" in enterprise and "" in OSS.
|
||||
// This constant is useful when a default value is needed for an
|
||||
// operation that will reject non-empty values in OSS.
|
||||
const splitDefaultNamespace = ""
|
||||
const splitDefaultPartition = ""
|
|
@ -1,7 +0,0 @@
|
|||
//go:build !consulent
|
||||
// +build !consulent
|
||||
|
||||
package api
|
||||
|
||||
var defaultNamespace = ""
|
||||
var defaultPartition = ""
|
|
@ -153,7 +153,7 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
CreateIndex: ret.Results[0].KV.CreateIndex,
|
||||
ModifyIndex: ret.Results[0].KV.ModifyIndex,
|
||||
Namespace: ret.Results[0].KV.Namespace,
|
||||
Partition: defaultPartition,
|
||||
Partition: splitDefaultPartition,
|
||||
},
|
||||
},
|
||||
&TxnResult{
|
||||
|
@ -165,14 +165,14 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
CreateIndex: ret.Results[1].KV.CreateIndex,
|
||||
ModifyIndex: ret.Results[1].KV.ModifyIndex,
|
||||
Namespace: ret.Results[0].KV.Namespace,
|
||||
Partition: defaultPartition,
|
||||
Partition: splitDefaultPartition,
|
||||
},
|
||||
},
|
||||
&TxnResult{
|
||||
Node: &Node{
|
||||
ID: nodeID,
|
||||
Node: "foo",
|
||||
Partition: defaultPartition,
|
||||
Partition: splitDefaultPartition,
|
||||
Address: "2.2.2.2",
|
||||
Datacenter: "dc1",
|
||||
CreateIndex: ret.Results[2].Node.CreateIndex,
|
||||
|
@ -184,8 +184,8 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
ID: "foo1",
|
||||
CreateIndex: ret.Results[3].Service.CreateIndex,
|
||||
ModifyIndex: ret.Results[3].Service.CreateIndex,
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
},
|
||||
},
|
||||
&TxnResult{
|
||||
|
@ -203,8 +203,8 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
DeregisterCriticalServiceAfterDuration: 20 * time.Second,
|
||||
},
|
||||
Type: "tcp",
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
CreateIndex: ret.Results[4].Check.CreateIndex,
|
||||
ModifyIndex: ret.Results[4].Check.CreateIndex,
|
||||
},
|
||||
|
@ -224,8 +224,8 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
DeregisterCriticalServiceAfterDuration: 160 * time.Second,
|
||||
},
|
||||
Type: "tcp",
|
||||
Partition: defaultPartition,
|
||||
Namespace: defaultNamespace,
|
||||
Partition: splitDefaultPartition,
|
||||
Namespace: splitDefaultNamespace,
|
||||
CreateIndex: ret.Results[4].Check.CreateIndex,
|
||||
ModifyIndex: ret.Results[4].Check.CreateIndex,
|
||||
},
|
||||
|
@ -266,14 +266,14 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
CreateIndex: ret.Results[0].KV.CreateIndex,
|
||||
ModifyIndex: ret.Results[0].KV.ModifyIndex,
|
||||
Namespace: ret.Results[0].KV.Namespace,
|
||||
Partition: defaultPartition,
|
||||
Partition: splitDefaultPartition,
|
||||
},
|
||||
},
|
||||
&TxnResult{
|
||||
Node: &Node{
|
||||
ID: s.Config.NodeID,
|
||||
Node: s.Config.NodeName,
|
||||
Partition: defaultPartition,
|
||||
Partition: splitDefaultPartition,
|
||||
Address: "127.0.0.1",
|
||||
Datacenter: "dc1",
|
||||
TaggedAddresses: map[string]string{
|
||||
|
|
Loading…
Reference in New Issue