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