open-nomad/client
Mahmood Ali 7a32d3f3aa client: handle 0.8 server network resources
Fixes https://github.com/hashicorp/nomad/issues/5587

When a nomad 0.9 client is handling an alloc generated by a nomad 0.8
server, we should check the alloc.TaskResources for networking details
rather than task.Resources.

We check alloc.TaskResources for networking for other tasks in the task
group [1], so it's a bit odd that we used the task.Resources struct
here.  TaskRunner also uses `alloc.TaskResources`[2].

The task.Resources struct in 0.8 was sparsly populated, resulting to
storing of 0 in port mapping env vars:

```
vagrant@nomad-server-01:~$ nomad version
Nomad v0.8.7 (21a2d93eecf018ad2209a5eab6aae6c359267933+CHANGES)
vagrant@nomad-server-01:~$ nomad server members
Name                    Address      Port  Status  Leader  Protocol  Build  Datacenter  Region
nomad-server-01.global  10.199.0.11  4648  alive   true    2         0.8.7  dc1         global
vagrant@nomad-server-01:~$ nomad alloc status -json 5b34649b | jq '.Job.TaskGroups[0].Tasks[0].Resources.Networks'
[
  {
    "CIDR": "",
    "Device": "",
    "DynamicPorts": [
      {
        "Label": "db",
        "Value": 0
      }
    ],
    "IP": "",
    "MBits": 10,
    "ReservedPorts": null
  }
]
vagrant@nomad-server-01:~$ nomad alloc status -json 5b34649b | jq '.TaskResources'
{
  "redis": {
    "CPU": 500,
    "DiskMB": 0,
    "IOPS": 0,
    "MemoryMB": 256,
    "Networks": [
      {
        "CIDR": "",
        "Device": "eth1",
        "DynamicPorts": [
          {
            "Label": "db",
            "Value": 21722
          }
        ],
        "IP": "10.199.0.21",
        "MBits": 10,
        "ReservedPorts": null
      }
    ]
  }
}
```

Also, updated the test values to mimic how Nomad 0.8 structs are
represented, and made its result match the non compact values in
`TestEnvironment_AsList`.

[1] 24e9040b18/client/taskenv/env.go (L624-L639)
[2] https://github.com/hashicorp/nomad/blob/master/client/allocrunner/taskrunner/task_runner.go#L287-L303
2019-05-02 12:08:38 -04:00
..
allocdir goimports 2019-01-22 15:44:31 -08:00
allochealth client: fix setting alloc unhealthy at deadline 2019-02-19 07:44:14 -08:00
allocrunner Merge pull request #5515 from hashicorp/dani/f-alloc-signal 2019-04-26 14:21:05 +02:00
allocwatcher goimports 2019-01-22 15:44:31 -08:00
config goimports until make check is happy 2019-01-23 06:27:14 -08:00
consul test: add some extra logging 2019-01-14 09:56:53 -08:00
devicemanager test: fix NewMemDB API change 2019-03-04 13:37:20 -08:00
fingerprint Merge pull request #5553 from hashicorp/b-fingerprinter-manual-config 2019-04-26 12:55:34 -04:00
interfaces Populate alloc stats API with device stats 2018-11-16 10:26:32 -05:00
lib rename fifo methods for clarity 2019-04-01 16:52:58 -04:00
logmon logmon client to handle grpc closing errors 2019-04-25 14:32:24 -04:00
pluginmanager client: log detected driver health state 2019-04-19 09:15:25 -04:00
servers fix test compiling 2018-10-16 16:56:55 -07:00
state test: fix NewMemDB API change 2019-03-04 13:37:20 -08:00
stats Add Client Device Stats structs in `api` package 2018-11-14 14:41:19 -05:00
structs Bump to 0.9.1-dev 2019-04-09 09:01:48 -07:00
taskenv client: handle 0.8 server network resources 2019-05-02 12:08:38 -04:00
testutil tests: expect Docker on AppVeyor 2019-02-20 07:41:47 -05:00
vaultclient vault: fix data races 2019-04-16 11:22:44 -07:00
acl.go client: hclog-ify most of the client 2018-10-16 16:53:30 -07:00
acl_test.go tests: explicitly cleanup after clients 2018-10-17 10:06:59 -07:00
alloc_endpoint.go alloc_signal: Add autcompletion and cmd tests 2019-04-26 12:47:53 +02:00
alloc_endpoint_test.go alloc_signal: Add autcompletion and cmd tests 2019-04-26 12:47:53 +02:00
alloc_watcher_e2e_test.go tests: enable and fix tests requiring mock driver 2019-01-10 10:10:11 -05:00
client.go Merge pull request #5553 from hashicorp/b-fingerprinter-manual-config 2019-04-26 12:55:34 -04:00
client_stats_endpoint.go Server side impl + touch ups 2018-02-15 13:59:02 -08:00
client_stats_endpoint_test.go tests: explicitly cleanup after clients 2018-10-17 10:06:59 -07:00
client_test.go client fingerprinter doesn't overwrite manual configuration 2019-04-19 15:23:48 -04:00
driver_manager_test.go tests: port some fingerprint tests from 0.8 (#5359) 2019-02-26 10:54:16 -05:00
fingerprint_manager.go goimports until make check is happy 2019-01-23 06:27:14 -08:00
fingerprint_manager_test.go client/drivermananger: add driver manager 2018-12-18 22:55:18 -05:00
fs_endpoint.go client: expose task state to client 2018-10-16 16:56:55 -07:00
fs_endpoint_test.go tests: deflake client TestFS_Logs_TaskPending test 2019-01-18 21:26:48 -05:00
gc.go Plugins use parent loggers 2019-01-11 11:36:37 -08:00
gc_test.go test: copy AR's Alloc before mutating 2018-12-19 15:48:02 -08:00
node_updater.go client: wait for batched driver updated 2019-04-19 09:00:24 -04:00
rpc.go fix more cases of logging arity errors 2019-01-09 09:22:47 -05:00
rpc_test.go tests: explicitly cleanup after clients 2018-10-17 10:06:59 -07:00
testing.go goimports until make check is happy 2019-01-23 06:27:14 -08:00
util.go client: avoid registering node twice right away 2019-04-19 09:12:50 -04:00
util_test.go Update state with server 2018-10-16 16:53:29 -07:00