Browse Source

Add -host flag to expose command

pull/8040/head
Kyle Havlovitz 5 years ago
parent
commit
edab5588d8
  1. 6
      command/connect/expose/expose.go
  2. 3
      command/connect/expose/expose_test.go
  3. 7
      website/pages/docs/commands/connect/expose.mdx

6
command/connect/expose/expose.go

@ -30,6 +30,7 @@ type cmd struct {
service string
port int
protocol string
hosts flags.AppendSliceValue
}
func (c *cmd) init() {
@ -48,6 +49,9 @@ func (c *cmd) init() {
c.flags.StringVar(&c.protocol, "protocol", "tcp",
"The protocol for the service. Defaults to 'tcp'.")
c.flags.Var(&c.hosts, "host", "Additional DNS hostname to use for routing to this service."+
"Can be specified multiple times.")
c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags())
flags.Merge(c.flags, c.http.ServerFlags())
@ -144,6 +148,7 @@ func (c *cmd) Run(args []string) int {
ingressConf.Listeners[listenerIdx].Services = append(ingressConf.Listeners[listenerIdx].Services, api.IngressService{
Name: svc,
Namespace: svcNamespace,
Hosts: c.hosts,
})
} else {
ingressConf.Listeners = append(ingressConf.Listeners, api.IngressListener{
@ -153,6 +158,7 @@ func (c *cmd) Run(args []string) int {
{
Name: svc,
Namespace: svcNamespace,
Hosts: c.hosts,
},
},
})

3
command/connect/expose/expose_test.go

@ -279,6 +279,8 @@ func TestConnectExpose_existingConfig(t *testing.T) {
"-ingress-gateway=ingress",
"-port=9999",
"-protocol=http",
"-host=foo.com",
"-host=foo.net",
}
code := c.Run(args)
@ -292,6 +294,7 @@ func TestConnectExpose_existingConfig(t *testing.T) {
ingressConf.Listeners[1].Services = append(ingressConf.Listeners[1].Services, api.IngressService{
Name: "zoo",
Hosts: []string{"foo.com", "foo.net"},
})
ingressConf.CreateIndex = entry.GetCreateIndex()
ingressConf.ModifyIndex = entry.GetModifyIndex()

7
website/pages/docs/commands/connect/expose.mdx

@ -40,12 +40,15 @@ Usage: consul connect expose [options]
- `-port` - (Required) The listener port to use for the service on the Ingress
gateway.
- `-protocol` - The protocol for the service. Defaults to 'tcp'.
- `-service` - (Required) The name of destination service to expose. A namespace
can optionally be specified as a prefix via the 'namespace/service'
format.
- `-protocol` - The protocol for the service. Defaults to 'tcp'.
- `-host` - Additional DNS hostname to use for routing to this service. Can be
specified multiple times.
## Examples
The example below shows using the `expose` command to make the `foo` service available

Loading…
Cancel
Save