Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/4619.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:improvement
cli: new flags for `waypoint install` on Nomad:
-nomad-service-address and -nomad-network-mode
```
43 changes: 38 additions & 5 deletions internal/serverinstall/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ type nomadConfig struct {
namespace string `hcl:"namespace,optional"`
serviceAnnotations map[string]string `hcl:"service_annotations,optional"`

serviceProvider string `hcl:"service_provider,optional"`
serviceUITags []string `hcl:"service_ui_tags:optional"`
serviceBackendTags []string `hcl:"service_backend_tags:optional"`
serviceProvider string `hcl:"service_provider,optional"`
serviceUITags []string `hcl:"service_ui_tags:optional"`
serviceBackendTags []string `hcl:"service_backend_tags:optional"`
serviceAddress string `hcl:"service_address,optional"`
networkMode string `hcl:"network_mode,optional"`

consulService bool `hcl:"consul_service,optional"`
consulServiceUITags []string `hcl:"consul_service_ui_tags:optional"`
consulServiceBackendTags []string `hcl:"consul_service_backend_tags:optional"`
Expand Down Expand Up @@ -819,6 +822,17 @@ func (i *NomadInstaller) waitForEvaluation(
}
}

func dockerNetworkMode(nomadNetworkMode string) string {
// if explicit network{mode="host"} then docker config needs network_mode="host"
// if network{} or network{mode="bridge"} then docker needs not to have anything
// default to empty.
switch nomadNetworkMode {
case "host":
return "host"
}
return ""
}

// waypointNomadJob takes in a nomadConfig and returns a Nomad Job per the
// Nomad API
func waypointNomadJob(c nomadConfig, rawRunFlags []string, upgrade bool) *api.Job {
Expand Down Expand Up @@ -858,12 +872,14 @@ func waypointNomadJob(c nomadConfig, rawRunFlags []string, upgrade bool) *api.Jo
services = []*api.Service{
{
Name: waypointUIServiceName,
Address: c.serviceAddress,
PortLabel: "ui",
Tags: uiTags,
Provider: "consul",
},
{
Name: waypointBackendServiceName,
Address: c.serviceAddress,
PortLabel: "server",
Tags: backendTags,
Provider: "consul",
Expand All @@ -873,12 +889,14 @@ func waypointNomadJob(c nomadConfig, rawRunFlags []string, upgrade bool) *api.Jo
services = []*api.Service{
{
Name: waypointUIServiceName,
Address: c.serviceAddress,
PortLabel: "ui",
Tags: c.serviceUITags,
Provider: "nomad",
},
{
Name: waypointBackendServiceName,
Address: c.serviceAddress,
PortLabel: "server",
Tags: c.serviceBackendTags,
Provider: "nomad",
Expand All @@ -889,7 +907,7 @@ func waypointNomadJob(c nomadConfig, rawRunFlags []string, upgrade bool) *api.Jo

tg.Networks = []*api.NetworkResource{
{
Mode: "host",
Mode: c.networkMode,
// currently set to static; when ui command can be dynamic - update this
ReservedPorts: []api.Port{
{
Expand Down Expand Up @@ -950,6 +968,7 @@ func waypointNomadJob(c nomadConfig, rawRunFlags []string, upgrade bool) *api.Jo
"ports": []string{"server", "ui"},
"args": ras,
"auth_soft_fail": c.authSoftFail,
"network_mode": dockerNetworkMode(c.networkMode),
}
task.Env = map[string]string{
"PORT": defaultGrpcPort,
Expand Down Expand Up @@ -983,7 +1002,7 @@ func waypointRunnerNomadJob(c nomadConfig, opts *InstallRunnerOpts) *api.Job {
tg.Networks = []*api.NetworkResource{
{
// Host mode so we can communicate to our server.
Mode: "host",
Mode: c.networkMode,
},
}
job.AddTaskGroup(tg)
Expand All @@ -997,6 +1016,7 @@ func waypointRunnerNomadJob(c nomadConfig, opts *InstallRunnerOpts) *api.Job {
"-vv",
},
"auth_soft_fail": c.authSoftFail,
"network_mode": dockerNetworkMode(c.networkMode),
}

cpu := defaultResourcesCPU
Expand Down Expand Up @@ -1148,6 +1168,13 @@ func (i *NomadInstaller) InstallFlags(set *flag.Set) {
Usage: "Namespace to install the Waypoint server into for Nomad.",
})

set.StringVar(&flag.StringVar{
Name: "nomad-network-mode",
Target: &i.config.networkMode,
Usage: "Nomad task group network mode.",
Default: "host",
})

set.StringVar(&flag.StringVar{
Name: "nomad-odr-image",
Target: &i.config.odrImage,
Expand Down Expand Up @@ -1183,6 +1210,12 @@ func (i *NomadInstaller) InstallFlags(set *flag.Set) {
Default: strconv.Itoa(defaultResourcesMemory),
})

set.StringVar(&flag.StringVar{
Name: "nomad-service-address",
Target: &i.config.serviceAddress,
Usage: "Address for the Nomad services.",
})

set.StringVar(&flag.StringVar{
Name: "nomad-runner-cpu",
Target: &i.config.runnerResourcesCPU,
Expand Down
2 changes: 2 additions & 0 deletions website/content/commands/install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ and disable the UI, the command would be:
- `-nomad-dc=<string>` - Datacenters to install to for Nomad. The default is dc1.
- `-nomad-host=<string>` - Hostname of the Nomad server to use, like for launching on-demand tasks. The default is http://localhost:4646.
- `-nomad-namespace=<string>` - Namespace to install the Waypoint server into for Nomad. The default is default.
- `-nomad-network-mode=<string>` - Nomad task group network mode. The default is host.
- `-nomad-odr-image=<string>` - Docker image for the on-demand runners. If not specified, it defaults to the server image name + '-odr' (i.e. 'hashicorp/waypoint-odr:latest').
- `-nomad-policy-override` - Override the Nomad sentinel policy for enterprise Nomad. The default is false.
- `-nomad-region=<string>` - Region to install to for Nomad. The default is global.
- `-nomad-server-cpu=<string>` - CPU required to run this task in MHz. The default is 200.
- `-nomad-server-memory=<string>` - MB of Memory to allocate to the Server job task. The default is 600.
- `-nomad-service-address=<string>` - Address for the Nomad services.
- `-nomad-runner-cpu=<string>` - CPU required to run this task in MHz. The default is 200.
- `-nomad-runner-memory=<string>` - MB of Memory to allocate to the runner job task. The default is 600.
- `-nomad-runner-host-volume=<string>` - Name of the host volume to use for the Waypoint runner.
Expand Down
2 changes: 2 additions & 0 deletions website/content/commands/server-install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ and disable the UI, the command would be:
- `-nomad-dc=<string>` - Datacenters to install to for Nomad. The default is dc1.
- `-nomad-host=<string>` - Hostname of the Nomad server to use, like for launching on-demand tasks. The default is http://localhost:4646.
- `-nomad-namespace=<string>` - Namespace to install the Waypoint server into for Nomad. The default is default.
- `-nomad-network-mode=<string>` - Nomad task group network mode. The default is host.
- `-nomad-odr-image=<string>` - Docker image for the on-demand runners. If not specified, it defaults to the server image name + '-odr' (i.e. 'hashicorp/waypoint-odr:latest').
- `-nomad-policy-override` - Override the Nomad sentinel policy for enterprise Nomad. The default is false.
- `-nomad-region=<string>` - Region to install to for Nomad. The default is global.
- `-nomad-server-cpu=<string>` - CPU required to run this task in MHz. The default is 200.
- `-nomad-server-memory=<string>` - MB of Memory to allocate to the Server job task. The default is 600.
- `-nomad-service-address=<string>` - Address for the Nomad services.
- `-nomad-runner-cpu=<string>` - CPU required to run this task in MHz. The default is 200.
- `-nomad-runner-memory=<string>` - MB of Memory to allocate to the runner job task. The default is 600.
- `-nomad-runner-host-volume=<string>` - Name of the host volume to use for the Waypoint runner.
Expand Down