hashicorp/nomad-pack

Unable to use Nomad service registration

Jamesits opened this issue · 2 comments

I have a simple nomad pack:

job "[[- .nomad_pack.pack.name -]]" {
  update {
    max_parallel = 1
    auto_revert       = true
    auto_promote      = true
    canary            = 1
  }

  group "hello" {
    network {
      port "http" {}
    }

    service {
      provider = "nomad"
      name = "hello"
      port = "http"
    }

    task "hello" {
      driver = "docker"

      config {
        image        = "k8s.gcr.io/pause:3.1"
        ports = ["http"]
      }
    }
  }
}

And it seems to render correctly when running nomad-pack render. However, when applied to a nomad server, the service provider automatically changes to consul which is not what I defined.

The full job definition, retrieved from Nomad:

{
  "Stop": false,
  "Region": "global",
  "Namespace": "default",
  "ID": "hello_world",
  "ParentID": "",
  "Name": "hello_world",
  "Type": "service",
  "Priority": 50,
  "AllAtOnce": false,
  "Datacenters": [
    "*"
  ],
  "Constraints": null,
  "Affinities": null,
  "Spreads": null,
  "TaskGroups": [
    {
      "Name": "hello",
      "Count": 1,
      "Update": {
        "Stagger": 30000000000,
        "MaxParallel": 1,
        "HealthCheck": "checks",
        "MinHealthyTime": 10000000000,
        "HealthyDeadline": 300000000000,
        "ProgressDeadline": 600000000000,
        "AutoRevert": true,
        "AutoPromote": true,
        "Canary": 1
      },
      "Migrate": {
        "MaxParallel": 1,
        "HealthCheck": "checks",
        "MinHealthyTime": 10000000000,
        "HealthyDeadline": 300000000000
      },
      "Constraints": [
        {
          "LTarget": "${attr.consul.version}",
          "RTarget": ">= 1.7.0",
          "Operand": "semver"
        }
      ],
      "Scaling": null,
      "RestartPolicy": {
        "Attempts": 2,
        "Interval": 1800000000000,
        "Delay": 15000000000,
        "Mode": "fail"
      },
      "Tasks": [
        {
          "Name": "hello",
          "Driver": "docker",
          "User": "",
          "Config": {
            "ports": [
              "http"
            ],
            "image": "k8s.gcr.io/pause:3.1"
          },
          "Env": null,
          "Services": null,
          "Vault": null,
          "Templates": null,
          "Constraints": null,
          "Affinities": null,
          "Resources": {
            "CPU": 100,
            "Cores": 0,
            "MemoryMB": 300,
            "MemoryMaxMB": 0,
            "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,
            "Disabled": false
          },
          "Artifacts": null,
          "Leader": false,
          "ShutdownDelay": 0,
          "VolumeMounts": null,
          "ScalingPolicies": null,
          "KillSignal": "",
          "Kind": "",
          "CSIPluginConfig": null,
          "Identity": 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": "",
          "Device": "",
          "CIDR": "",
          "IP": "",
          "Hostname": "",
          "MBits": 0,
          "DNS": null,
          "ReservedPorts": null,
          "DynamicPorts": [
            {
              "Label": "http",
              "Value": 0,
              "To": 0,
              "HostNetwork": "default"
            }
          ]
        }
      ],
      "Consul": {
        "Namespace": ""
      },
      "Services": [
        {
          "Name": "hello",
          "TaskName": "",
          "PortLabel": "http",
          "AddressMode": "auto",
          "Address": "",
          "EnableTagOverride": false,
          "Tags": null,
          "CanaryTags": null,
          "Checks": null,
          "Connect": null,
          "Meta": null,
          "CanaryMeta": null,
          "TaggedAddresses": null,
          "Namespace": "default",
          "OnUpdate": "require_healthy",
          "Provider": "consul"
        }
      ],
      "Volumes": null,
      "ShutdownDelay": null,
      "StopAfterClientDisconnect": null,
      "MaxClientDisconnect": 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,
  "DispatchIdempotencyToken": "",
  "Payload": null,
  "Meta": {
    "pack.version": "dev",
    "pack.deployment_name": "redacted\\nomad\\packs\\hello_world",
    "pack.job": "hello_world",
    "pack.name": "redacted\\nomad\\packs\\hello_world",
    "pack.path": "redacted\\nomad\\packs\\hello_world",
    "pack.registry": "dev"
  },
  "ConsulToken": "",
  "ConsulNamespace": "",
  "VaultToken": "",
  "VaultNamespace": "",
  "NomadTokenID": "redacted",
  "Status": "running",
  "StatusDescription": "",
  "Stable": false,
  "Version": 0,
  "SubmitTime": 1693235935822707200,
  "CreateIndex": 69453,
  "ModifyIndex": 69454,
  "JobModifyIndex": 69453
}

Hi @Jamesits, could you confirm which version of nomad-pack you're using please?

Tested with 0.1.0 and this issue does not exist anymore.