Fix a CLI test failure with namespaces in enterprise
This commit is contained in:
parent
0c23eaf943
commit
11486ac2a1
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/consul/agent"
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
"github.com/hashicorp/consul/api"
|
||||
"github.com/hashicorp/consul/command/flags"
|
||||
"github.com/hashicorp/consul/command/intention/create"
|
||||
|
@ -145,7 +146,7 @@ func (c *cmd) Run(args []string) int {
|
|||
|
||||
// Make sure the service isn't already exposed in this gateway
|
||||
for j, service := range listener.Services {
|
||||
if service.Name == svc && service.Namespace == svcNamespace {
|
||||
if service.Name == svc && namespaceMatch(service.Namespace, svcNamespace) {
|
||||
serviceIdx = j
|
||||
c.UI.Output(fmt.Sprintf("Updating service definition for %q on listener with port %d", c.service, listener.Port))
|
||||
break
|
||||
|
@ -220,6 +221,19 @@ func (c *cmd) Run(args []string) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func namespaceMatch(a, b string) bool {
|
||||
namespaceA := a
|
||||
namespaceB := b
|
||||
if namespaceA == "" {
|
||||
namespaceA = structs.IntentionDefaultNamespace
|
||||
}
|
||||
if namespaceB == "" {
|
||||
namespaceB = structs.IntentionDefaultNamespace
|
||||
}
|
||||
|
||||
return namespaceA == namespaceB
|
||||
}
|
||||
|
||||
func (c *cmd) Synopsis() string {
|
||||
return synopsis
|
||||
}
|
||||
|
|
|
@ -38,9 +38,11 @@ func TestConnectExpose(t *testing.T) {
|
|||
// Make sure the config entry and intention have been created.
|
||||
entry, _, err := client.ConfigEntries().Get(api.IngressGateway, "ingress", nil)
|
||||
require.NoError(err)
|
||||
ns := entry.(*api.IngressGatewayConfigEntry).Namespace
|
||||
expected := &api.IngressGatewayConfigEntry{
|
||||
Kind: api.IngressGateway,
|
||||
Name: "ingress",
|
||||
Namespace: ns,
|
||||
Listeners: []api.IngressListener{
|
||||
{
|
||||
Port: 8888,
|
||||
|
@ -48,6 +50,7 @@ func TestConnectExpose(t *testing.T) {
|
|||
Services: []api.IngressService{
|
||||
{
|
||||
Name: "foo",
|
||||
Namespace: ns,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -87,6 +90,7 @@ func TestConnectExpose(t *testing.T) {
|
|||
Services: []api.IngressService{
|
||||
{
|
||||
Name: "foo",
|
||||
Namespace: ns,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -254,6 +258,7 @@ func TestConnectExpose_existingConfig(t *testing.T) {
|
|||
entry, _, err := client.ConfigEntries().Get(api.IngressGateway, "ingress", nil)
|
||||
require.NoError(err)
|
||||
|
||||
entryConf := entry.(*api.IngressGatewayConfigEntry)
|
||||
ingressConf.Listeners = append(ingressConf.Listeners, api.IngressListener{
|
||||
Port: 10000,
|
||||
Protocol: "tcp",
|
||||
|
@ -263,6 +268,10 @@ func TestConnectExpose_existingConfig(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
ingressConf.Namespace = entryConf.Namespace
|
||||
for i, listener := range ingressConf.Listeners {
|
||||
listener.Services[0].Namespace = entryConf.Listeners[i].Services[0].Namespace
|
||||
}
|
||||
ingressConf.CreateIndex = entry.GetCreateIndex()
|
||||
ingressConf.ModifyIndex = entry.GetModifyIndex()
|
||||
require.Equal(ingressConf, entry)
|
||||
|
@ -292,8 +301,10 @@ func TestConnectExpose_existingConfig(t *testing.T) {
|
|||
entry, _, err := client.ConfigEntries().Get(api.IngressGateway, "ingress", nil)
|
||||
require.NoError(err)
|
||||
|
||||
entryConf := entry.(*api.IngressGatewayConfigEntry)
|
||||
ingressConf.Listeners[1].Services = append(ingressConf.Listeners[1].Services, api.IngressService{
|
||||
Name: "zoo",
|
||||
Namespace: entryConf.Listeners[1].Services[1].Namespace,
|
||||
Hosts: []string{"foo.com", "foo.net"},
|
||||
})
|
||||
ingressConf.CreateIndex = entry.GetCreateIndex()
|
||||
|
|
Loading…
Reference in New Issue