Add -host flag to expose command

This commit is contained in:
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
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,
},
},
})

View File

@ -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()

View File

@ -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