I've developed support for the service stanza of Nomad. But I'm having a problem

In builtin/nomad/platform.go, I added code like below for using service tag:

if p.config.Service != nil {
	services := &api.Service{
		Name: p.config.Service.Name,
		Tags: p.config.Service.Tags,
		PortLabel: "waypoint",
	}
	job.TaskGroups[0].Tasks[0].Services = []*api.Service{services}
}

waypoint.hcl

app "app" {
...

deploy {
    use "nomad" {
      service_port = 8082
      service {
        name = "app"
        tags = [
          "traefik.enable=true",
          "traefik.tag=traefik",
          "traefik.http.routers.waypoint.entrypoints=http",
          "traefik.http.routers.waypoint.rule=Host(`hoge.com`) && Path(`/init`)"
        ]
      }
    }
  }
}

But there is an error:

* Task group app validation failed: 1 error occurred:
        * Task app validation failed: 1 error occurred:
        * 1 error occurred:
        * port label "waypoint" referenced by services app does not exist

So I removed PortLabel for checking job definition.

if p.config.Service != nil {
	services := &api.Service{
		Name: p.config.Service.Name,
		Tags: p.config.Service.Tags,
		// PortLabel: "waypoint",
	}
	job.TaskGroups[0].Tasks[0].Services = []*api.Service{services}
}

result is

{
  "Stop": false,
  "Region": "global",
  "Namespace": "default",
  "ID": "app",
  "ParentID": "",
  "Name": "app",
  "Type": "service",
  "Priority": 10,
  "AllAtOnce": false,
  "Datacenters": [
    "dc1"
  ],
  "Constraints": null,
  "Affinities": null,
  "Spreads": null,
  "TaskGroups": [
    {
      "Name": "app",
      "Count": 1,
      "Update": {
        "Stagger": 30000000000,
        "MaxParallel": 1,
        "HealthCheck": "checks",
        "MinHealthyTime": 10000000000,
        "HealthyDeadline": 300000000000,
        "ProgressDeadline": 600000000000,
        "AutoRevert": false,
        "AutoPromote": false,
        "Canary": 0
      },
      "Migrate": {
        "MaxParallel": 1,
        "HealthCheck": "checks",
        "MinHealthyTime": 10000000000,
        "HealthyDeadline": 300000000000
      },
      "Constraints": null,
      "Scaling": null,
      "RestartPolicy": {
        "Attempts": 2,
        "Interval": 1800000000000,
        "Delay": 15000000000,
        "Mode": "fail"
      },
      "Tasks": [
        {
          "Name": "app",
          "Driver": "docker",
          "User": "",
          "Config": {
            "ports": [
              "waypoint"
            ],
            "image": ":3"
          },
          "Env": {
            "WAYPOINT_SERVER_ADDR": "192.168.20.31:27328",
            "PORT": "8082",
            "WAYPOINT_DEPLOYMENT_ID": "01ENN4EW4GGZX7HCG58BS63CVP",
            "WAYPOINT_SERVER_TLS": "1",
            "WAYPOINT_CEB_INVITE_TOKEN": "4RmBPBvZ1Dke3ppuJieyjR7Lr8wopqSinzMDV9CBhbK1SCcBVQwdZFsTfyJ2yhzU6Fk8x8F4Afj43gFbV75LsPNyJt3jKmxAfDPD8CRp5sSsfg7ueCTDV9LmfweZNPsDqs2JGQgoHJWtzwmLRhhJ",
            "WAYPOINT_SERVER_TLS_SKIP_VERIFY": "1"
          },
          "Services": [
            {
              "Name": "app",
              "TaskName": "",
              "PortLabel": "",
              "AddressMode": "auto",
              "EnableTagOverride": false,
              "Tags": [
                "traefik.enable=true",
                "traefik.tag=traefik",
                "traefik.http.routers.waypoint.entrypoints=http",
                "traefik.http.routers.waypoint.rule=Host(`hoge.com`) && Path(`/init`)"
              ],
              "CanaryTags": null,
              "Checks": null,
              "Connect": null,
              "Meta": null,
              "CanaryMeta": null
            }
          ],
          "Vault": null,
          "Templates": null,
          "Constraints": null,
          "Affinities": null,
          "Resources": {
            "CPU": 100,
            "MemoryMB": 300,
            "DiskMB": 0,
            "IOPS": 0,
            "Networks": null,
            "Devices": null
          },
          "RestartPolicy": {
            "Attempts": 2,
            "Interval": 1800000000000,
            "Delay": 15000000000,
            "Mode": "fail"
          },
          "DispatchPayload": null,
          "Lifecycle": null,
          "Meta": null,
          "KillTimeout": 5000000000,
          "LogConfig": {
            "MaxFiles": 10,
            "MaxFileSizeMB": 10
          },
          "Artifacts": null,
          "Leader": false,
          "ShutdownDelay": 0,
          "VolumeMounts": null,
          "KillSignal": "",
          "Kind": "",
          "CSIPluginConfig": null
        }
      ],
      "EphemeralDisk": {
        "Sticky": false,
        "SizeMB": 300,
        "Migrate": false
      },
      "Meta": null,
      "ReschedulePolicy": {
        "Attempts": 0,
        "Interval": 0,
        "Delay": 30000000000,
        "DelayFunction": "exponential",
        "MaxDelay": 3600000000000,
        "Unlimited": true
      },
      "Affinities": null,
      "Spreads": null,
      "Networks": [
        {
          "Mode": "host",
          "Device": "",
          "CIDR": "",
          "IP": "",
          "MBits": 10,
          "DNS": null,
          "ReservedPorts": null,
          "DynamicPorts": [
            {
              "Label": "waypoint",
              "Value": 0,
              "To": 8082,
              "HostNetwork": "default"
            }
          ]
        }
      ],
      "Services": null,
      "Volumes": null,
      "ShutdownDelay": null,
      "StopAfterClientDisconnect": null
    }
  ],
  "Update": {
    "Stagger": 30000000000,
    "MaxParallel": 1,
    "HealthCheck": "",
    "MinHealthyTime": 0,
    "HealthyDeadline": 0,
    "ProgressDeadline": 0,
    "AutoRevert": false,
    "AutoPromote": false,
    "Canary": 0
  },
  "Multiregion": null,
  "Periodic": null,
  "ParameterizedJob": null,
  "Dispatched": false,
  "Payload": null,
  "Meta": {
    "waypoint.hashicorp.com/nonce": "2020-10-27T13:38:29.924855419Z",
    "waypoint.hashicorp.com/id": "01ENN4G4WT8ZE7JWR1ZZP6X25G"
  },
  "ConsulToken": "",
  "VaultToken": "",
  "VaultNamespace": "",
  "NomadTokenID": "",
  "Status": "running",
  "StatusDescription": "",
  "Stable": true,
  "Version": 0,
  "SubmitTime": 1603805868486658300,
  "CreateIndex": 4720439,
  "ModifyIndex": 4720448,
  "JobModifyIndex": 4720439
}

I am struggling with the code on Waypoint and the differences in the Nomad job files.
And it’s also due to my lack of familiarity with Nomad.
If anyone can figure it out, please let me know.

Hey there @rluisr! Thanks for asking the question. I think we’ve figured out how to answer your question to get the right PortLabel set. Rather than adding your services map there to the job config, we can instead add the service to the existing task group here:

So, you’ll probably end up with something that looks like this below line 113:

if p.config.ServiceName != "" {
			tg.Services = []*api.Service{{
				Name: p.config.ServiceName,
				Tags: p.config.ServiceTags,
				AddressMode: "host",
				PortLabel: "waypoint",
			}}
		}

Quick editing note: I learned a bit more about this after hitting send on my first post, so apologies if my first iteration of this was misleading! It turns out that adding AddressMode should work as expected. One thing to be aware of is that in Waypoint, we don’t destroy previous deployments automatically, so your existing Consul registrations will still be there. Since you’re registering against an existing service name, new deployments are going to be dropped in that service you are creating. If there are any old versions of the application you don’t want inside Consul, make sure they are removed as well. Hopefully this makes some sense! Thank you :slight_smile:

1 Like