Add -host flag to expose command

pull/8040/head
Kyle Havlovitz 2020-06-08 16:59:47 -07:00
parent 5958328552
commit edab5588d8
3 changed files with 15 additions and 3 deletions

View File

@ -30,6 +30,7 @@ type cmd struct {
service string service string
port int port int
protocol string protocol string
hosts flags.AppendSliceValue
} }
func (c *cmd) init() { func (c *cmd) init() {
@ -48,6 +49,9 @@ func (c *cmd) init() {
c.flags.StringVar(&c.protocol, "protocol", "tcp", c.flags.StringVar(&c.protocol, "protocol", "tcp",
"The protocol for the service. Defaults to '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{} c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags()) flags.Merge(c.flags, c.http.ClientFlags())
flags.Merge(c.flags, c.http.ServerFlags()) 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{ ingressConf.Listeners[listenerIdx].Services = append(ingressConf.Listeners[listenerIdx].Services, api.IngressService{
Name: svc, Name: svc,
Namespace: svcNamespace, Namespace: svcNamespace,
Hosts: c.hosts,
}) })
} else { } else {
ingressConf.Listeners = append(ingressConf.Listeners, api.IngressListener{ ingressConf.Listeners = append(ingressConf.Listeners, api.IngressListener{
@ -153,6 +158,7 @@ func (c *cmd) Run(args []string) int {
{ {
Name: svc, Name: svc,
Namespace: svcNamespace, Namespace: svcNamespace,
Hosts: c.hosts,
}, },
}, },
}) })

View File

@ -279,6 +279,8 @@ func TestConnectExpose_existingConfig(t *testing.T) {
"-ingress-gateway=ingress", "-ingress-gateway=ingress",
"-port=9999", "-port=9999",
"-protocol=http", "-protocol=http",
"-host=foo.com",
"-host=foo.net",
} }
code := c.Run(args) code := c.Run(args)
@ -291,7 +293,8 @@ func TestConnectExpose_existingConfig(t *testing.T) {
require.NoError(err) require.NoError(err)
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",
Hosts: []string{"foo.com", "foo.net"},
}) })
ingressConf.CreateIndex = entry.GetCreateIndex() ingressConf.CreateIndex = entry.GetCreateIndex()
ingressConf.ModifyIndex = entry.GetModifyIndex() ingressConf.ModifyIndex = entry.GetModifyIndex()

View File

@ -40,12 +40,15 @@ Usage: consul connect expose [options]
- `-port` - (Required) The listener port to use for the service on the Ingress - `-port` - (Required) The listener port to use for the service on the Ingress
gateway. gateway.
- `-protocol` - The protocol for the service. Defaults to 'tcp'.
- `-service` - (Required) The name of destination service to expose. A namespace - `-service` - (Required) The name of destination service to expose. A namespace
can optionally be specified as a prefix via the 'namespace/service' can optionally be specified as a prefix via the 'namespace/service'
format. 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 ## Examples
The example below shows using the `expose` command to make the `foo` service available The example below shows using the `expose` command to make the `foo` service available