Skip to content

SaltStack modules.dockerng _compare does not handle docker implicit Domainname properly (issue when using network_mode: host) #32033

Closed

Description

@timcharper

Description of Issue/Question

When managing containers, and using network_mode: host, docker will implicitly set the domainname property, and dockerng will continually assume that the config was changed.

Setup

input formula:

registrator:
  dockerng.running:
    - image: gliderlabs/registrator:latest
    - network_mode: host
    - command: consul://127.0.0.1:8500
    - restart_policy: None
    - binds:
        - /var/run/docker.sock:/tmp/docker.sock

I did a json-dump of the _compare function call args after the original container was already created, and dockerng was deciding whether the current running container config matches the saltstack-specified desired config:

defaults_from_image:

{
  "Comment": "",
  "Container": "a10857e6f5727fa44d215804137d8339c7035a138e40459ea5467f37cdbcac74",
  "DockerVersion": "1.6.2",
  "Parent": "",
  "Created": "2015-08-14T13:55:52.692476857Z",
  "Config": {
    "Tty": false,
    "Cmd": null,
    "Volumes": null,
    "Domainname": "",
    "WorkingDir": "",
    "Image": "3c46b3f46415a9f8dcb7cd7aae1d1f676024f8f35e55f03adfb65db31513b371",
    "Hostname": "dcc8924290fe",
    "StdinOnce": false,
    "Labels": {},
    "AttachStdin": false,
    "User": "",
    "Env": [
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    ],
    "Entrypoint": [
      "/bin/registrator"
    ],
    "OnBuild": [],
    "AttachStderr": false,
    "AttachStdout": false,
    "OpenStdin": false
  },
  "Author": "",
  "VirtualSize_Human": "20.0 MiB",
  "GraphDriver": {
    "Data": {
      "DeviceName": "docker-253:0-449439-ee47e2b8eac963e2cb525aeafb290564d9a5064d84432efea75a446225a21271",
      "DeviceSize": "42949672960",
      "DeviceId": "138"
    },
    "Name": "devicemapper"
  },
  "VirtualSize": 20932921,
  "Size_Human": "20.0 MiB",
  "Os": "linux",
  "Architecture": "amd64",
  "ContainerConfig": {
    "Tty": false,
    "Cmd": ["/bin/sh", "-c", "apk-install -t build-deps go git mercurial \t&& cd /go/src/github.com/gliderlabs/registrator \t&& export GOPATH=/go \t&& go get \t&& go build -ldflags \"-X main.Version $(cat VERSION)\" -o /bin/registrator \t&& rm -rf /go \t&& apk del --purge build-deps"],
    "Volumes": null,
    "Domainname": "",
    "WorkingDir": "",
    "Image": "3c46b3f46415a9f8dcb7cd7aae1d1f676024f8f35e55f03adfb65db31513b371",
    "Hostname": "dcc8924290fe",
    "StdinOnce": false,
    "Labels": {},
    "AttachStdin": false,
    "User": "",
    "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],
    "Entrypoint": ["/bin/registrator"],
    "OnBuild": [],
    "AttachStderr": false,
    "AttachStdout": false,
    "OpenStdin": false
  },
  "Size": 20932921,
  "RepoDigests": [],
  "Id": "sha256:57cbfaed16bf3d2377936a5274b84c5f05dc3fb300f39925e4df0dbf5207260f",
  "RepoTags": [
    "gliderlabs/registrator:latest"
  ]
}

actual:

{
  "ExecIDs": null,
  "State": {
    "Status": "running",
    "Pid": 32012,
    "OOMKilled": false,
    "Dead": false,
    "Paused": false,
    "Running": true,
    "FinishedAt": "0001-01-01T00:00:00Z",
    "Restarting": false,
    "Error": "",
    "StartedAt": "2016-03-21T22:43:14.408782832Z",
    "ExitCode": 0
  },
  "Config": {
    "Tty": false,
    "Cmd": ["consul://127.0.0.1:8500"],
    "Volumes": {"/tmp/docker.sock": {}},
    "Domainname": "local-domain.com",
    "WorkingDir": "",
    "Image": "gliderlabs/registrator:latest",
    "Hostname": "sw-analytics43",
    "StdinOnce": false,
    "Labels": {},
    "AttachStdin": false,
    "User": "",
    "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],
    "Entrypoint": ["/bin/registrator"],
    "OnBuild": null,
    "AttachStderr": true,
    "AttachStdout": true,
    "OpenStdin": false
  },
  "ResolvConfPath": "/var/lib/docker/containers/8cb88415fc74752b381fd8469aa76241d849776205cea658dca06bf38b03891a/resolv.conf",
  "HostsPath": "/var/lib/docker/containers/8cb88415fc74752b381fd8469aa76241d849776205cea658dca06bf38b03891a/hosts",
  "Args": ["consul://127.0.0.1:8500"],
  "Driver": "devicemapper",
  "Path": "/bin/registrator",
  "HostnamePath": "/var/lib/docker/containers/8cb88415fc74752b381fd8469aa76241d849776205cea658dca06bf38b03891a/hostname",
  "RestartCount": 0,
  "Name": "/registrator",
  "Created": "2016-03-21T22:43:09.773123742Z",
  "GraphDriver": {
    "Data": {
      "DeviceName": "docker-253:0-449439-791c7d4069747a8f3180276d401a7e8005a44251084dad9f19f4d617bafbaa1a",
      "DeviceSize": "42949672960",
      "DeviceId": "170"
    },
    "Name": "devicemapper"
  },
  "Mounts": [
    {
      "RW": true,
      "Source": "/var/run/docker.sock",
      "Destination": "/tmp/docker.sock",
      "Mode": "rw",
      "Propagation": "rprivate"
    }
  ],
  "ProcessLabel": "",
  "NetworkSettings": {
    "Bridge": "",
    "Networks": {
      "host": {
        "NetworkID": "<redacted>",
        "MacAddress": "",
        "GlobalIPv6PrefixLen": 0,
        "Links": null,
        "GlobalIPv6Address": "",
        "IPv6Gateway": "",
        "IPAMConfig": null,
        "EndpointID": "<redacted>",
        "IPPrefixLen": 0,
        "IPAddress": "",
        "Gateway": "",
        "Aliases": null
      }
    },
    "SecondaryIPv6Addresses": null,
    "LinkLocalIPv6Address": "",
    "HairpinMode": false,
    "IPv6Gateway": "",
    "SecondaryIPAddresses": null,
    "SandboxID": "<redacted>",
    "MacAddress": "",
    "GlobalIPv6Address": "",
    "Gateway": "",
    "LinkLocalIPv6PrefixLen": 0,
    "EndpointID": "",
    "SandboxKey": "/var/run/docker/netns/default",
    "GlobalIPv6PrefixLen": 0,
    "IPPrefixLen": 0,
    "IPAddress": "",
    "Ports": {}
  },
  "AppArmorProfile": "",
  "Image": "sha256:<redacted>",
  "LogPath": "/var/lib/docker/containers/8cb88415fc74752b381fd8469aa76241d849776205cea658dca06bf38b03891a/8cb88415fc74752b381fd8469aa76241d849776205cea658dca06bf38b03891a-json.log",
  "HostConfig": {
    "CpuPeriod": 0,
    "MemorySwappiness": -1,
    "ContainerIDFile": "",
    "MemorySwap": 0,
    "BlkioDeviceReadIOps": null,
    "CpuQuota": 0,
    "Dns": null,
    "ExtraHosts": null,
    "PidsLimit": 0,
    "DnsSearch": null,
    "Privileged": false,
    "Ulimits": null,
    "CpusetCpus": "",
    "CgroupParent": "",
    "BlkioWeight": 0,
    "RestartPolicy": {"MaximumRetryCount": 0, "Name": "None"},
    "OomScoreAdj": 0,
    "BlkioDeviceReadBps": null,
    "VolumeDriver": "",
    "ReadonlyRootfs": false,
    "CpuShares": 0,
    "PublishAllPorts": false,
    "MemoryReservation": 0,
    "BlkioWeightDevice": null,
    "ConsoleSize": [0, 0],
    "NetworkMode": "host",
    "BlkioDeviceWriteBps": null,
    "Isolation": "",
    "GroupAdd": null,
    "Devices": null,
    "BlkioDeviceWriteIOps": null,
    "Binds": ["/var/run/docker.sock:/tmp/docker.sock:rw"],
    "CpusetMems": "",
    "KernelMemory": 0,
    "UTSMode": "",
    "PidMode": "",
    "VolumesFrom": null,
    "CapDrop": null,
    "DnsOptions": null,
    "ShmSize": 67108864,
    "Links": null,
    "IpcMode": "",
    "PortBindings": null,
    "SecurityOpt": null,
    "CapAdd": null,
    "Memory": 0,
    "OomKillDisable": false,
    "LogConfig": {"Config": {}, "Type": "json-file"}
  },
  "Id": "8cb88415fc74752b381fd8469aa76241d849776205cea658dca06bf38b03891a",
  "MountLabel": ""
}

create_kwargs:

{
  "network_mode": "host",
  "binds": {
    "/var/run/docker.sock": {"bind": "/tmp/docker.sock", "ro": false}
  },
  "restart_policy": {"MaximumRetryCount": 0, "Name": "None"},
  "command": ["consul://127.0.0.1:8500"],
  "volumes": ["/tmp/docker.sock"]
}

Versions Report

Salt Version:
           Salt: 2015.8.7

Dependency Versions:
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
           Mako: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.7.0
         Python: 2.7.5 (default, Nov 20 2015, 02:00:19)
           RAET: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
        libgit2: Not Installed
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.7
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
   python-gnupg: Not Installed
          smmap: Not Installed
        timelib: Not Installed

System Versions:
           dist: centos 7.2.1511 Core
        machine: x86_64
        release: 3.10.0-327.4.4.el7.x86_64
         system: CentOS Linux 7.2.1511 Core
  • dockerng state and module patched with from 553ecac.
  • docker-py 1.6.0

Activity

  1. changed the title [-]SaltStack `modules.dockerng` `_compare` does not handle domain properly[/-] [+]SaltStack `modules.dockerng` `_compare` does not handle docker implicit Domainname properly (issue when using network_mode: host)[/+] on Mar 21, 2016
  2. timcharper commented on Mar 21, 2016

    @timcharper
    ContributorAuthor

    Here's the diff that fixes it for me.

    If it looks good, I'll submit as a pull request:

    diff --git a/salt/patch/docker/states/dockerng.py b/salt/patch/docker/states/dockerng.py
    index 3516eda..843caba 100644
    --- a/salt/patch/docker/states/dockerng.py
    +++ b/salt/patch/docker/states/dockerng.py
    @@ -206,6 +206,14 @@ def _compare(actual, create_kwargs, defaults_from_image):
                     ret.update(env_diff)
                 continue
    
    +        elif item == 'domainname':
    +            if data is not None and data != '' and data != actual_data:
    +                ret.update({item: {'old': actual_data,
    +                                   'new': data}})
    +            continue
    +
             elif item == 'ports':
                 # Munge the desired configuration instead of the actual
                 # configuration here, because the desired configuration is a
  3. ticosax commented on Mar 22, 2016

    @ticosax
    Contributor

    Can you copy paste the log that reports the discrepancies ?

    You'd need to run with level -l debug.

    Actually the value is supposed to be fetched from the container. Which would solve your issue, theoretically.

  4. ticosax commented on Mar 22, 2016

    @ticosax
    Contributor

    I tried to reproduce locally, with network_mode: host and I couldn't reproduce.
    Do you have local patches applied ?

  5. added
    pending-discussion
    on Mar 22, 2016
  6. added this to the Blocked milestone on Mar 22, 2016
  7. timcharper commented on Mar 22, 2016

    @timcharper
    ContributorAuthor

    @ticosax I do have local patches applied. Running 2015.8.7, with states/dockerng.py and modules/dockerng.py from 553ecac.

    You can see the discrepancies from my original report, I've logged the three parameters to _compare. It expects '', but has 'local-domain.com'.

    I'll work more on a repro case.

  8. ticosax commented on Mar 23, 2016

    @ticosax
    Contributor

    Still not clear for me what's wrong, please give me the log output.

  9. timcharper commented on Mar 23, 2016

    @timcharper
    ContributorAuthor

    I'll send the full log via a message and private gist, to reduce the need to redact so much.

  10. timcharper commented on Mar 23, 2016

    @timcharper
    ContributorAuthor

    I'm running into a very similar error with memory_swap

  11. ticosax commented on Mar 24, 2016

    @ticosax
    Contributor

    @timcharper
    memory_swap is different from hostname becasue memory_swap has hadcoded default to 0.
    Next time open a new issue so we can focus on hostname.
    BTW I'm still waiting for the logs that report the discrepancies for hostname.

    What I need is just an excerpt, something like this.

    dockerng.running: Analysis of container 'foo' reveals the following changes need to be made: {'hostname': {'new': 'bla', 'old': 'foo'}}
    
  12. timcharper commented on Mar 24, 2016

    @timcharper
    ContributorAuthor

    The issue seemed similar since in both cases defaults being set by Docker were causing saltstack to think the config was modified / not set properly.

    [DEBUG   ] dockerng.running: Analysis of container 'registrator' reveals the following changes need to be made: {'domainname': {'new': '', 'old': u'<redacted.com>'}}
    
  13. ticosax commented on Mar 24, 2016

    @ticosax
    Contributor

    I tried to reproduce your use case and still fails to fail.

    consul:
      dockerng.running:
        - image: gliderlabs/consul-server
        - network_mode: host
        - command: -bootstrap -advertise=127.0.0.1
    
    registrator:
      dockerng.running:
        - image: gliderlabs/registrator:latest
        - network_mode: host
        - command: -internal consul://127.0.0.1:8500
        - restart_policy: None
        - binds:
            - /var/run/docker.sock:/tmp/docker.sock
        - require:
          - dockerng: consul

    I think to reproduce it, I need somehow to have a domain name defined on the host server.
    I'm using ubuntu14.04 within Vagrant. Can you check your hostname conf and tell me how I could setup hostname the same way ?
    Sorry, it is not very clear, but I think you have <redacted.com> defined somewhere on the host.
    If you can point me to that file it will help.

  14. rallytime commented on Mar 24, 2016

    @rallytime
    Contributor

    I saw that @ticosax submitted a fix related to this issue, but it looks like the original reported bug is still being chased down. Is that right @timcharper?

  15. added
    bug
    severity-medium
    P3
    Platform
    and removed
    pending-discussion
    on Mar 24, 2016
  16. modified the milestones: Approved, Blocked on Mar 24, 2016
  17. dverbeek84 commented on Mar 31, 2016

    @dverbeek84

    The patch from @timcharper works for me.

  18. ticosax commented on Mar 31, 2016

    @ticosax
    Contributor

    @dverbeek84 maybe it is working for you, but this is not the correct fix, because if user explicitly ask for domainname to be an empty string

    domainname: 

    The state will ignore this value and dockerng will become inconsistent.

    For you and @timcharper the domainnane is set on the container implicitly by whatever mechanism.
    I'd like to track down from were it is coming from so I can reproduce it locally.

    FYI the fix is probably

    diff --git a/salt/modules/dockerng.py b/salt/modules/dockerng.py
    index 7f43360..dffd4db 100644
    --- a/salt/modules/dockerng.py
    +++ b/salt/modules/dockerng.py
    @@ -370,7 +370,7 @@ VALID_CREATE_OPTS = {
         'domainname': {
             'validator': 'string',
             'path': 'Config:Domainname',
    -        'default': '',
    +        'get_default_from_container': True,
         },
         'interactive': {
             'api_name': 'stdin_open',

    But I'd like to test it locally first. And it is difficult because I can't reproduce it in my environment.

  19. jgmchan commented on Apr 6, 2016

    @jgmchan

    @ticosax I was having this exact problem. Couldn't reproduce it in my vagrant machine but it blew up in our real environments. Here is what I had to do to reproduce it in vagrant.

    1. Modify /etc/hostname with an FQDN. eg. vagrant.example.com
    2. Restart the hostname service: sudo service hostname restart
    3. Kill and remove your test container (Super important)
    4. Run the salt state against the minion, you'll see no errors and the test container has been created. A docker inspect --format '{{ .Config.Domainname }}' <test_container> will show the Domainname is now example.com
    5. Run the salt state again, the reported error appears.

    Reference: http://askubuntu.com/questions/158957/how-to-set-the-fully-qualified-domain-name-in-12-04

    I've had to temporarily work around this issue by setting - domainname: "{{ salt['grains.get']('domain') }}" in the state file.

    Hope this helps.

  20. ticosax commented on Apr 8, 2016

    @ticosax
    Contributor

    @jgmchan thank you for those clear steps. It helps me a lot.
    I could reproduce and a PR is on its way.

  21. added
    fixed-pls-verify
    on Apr 8, 2016
  22. rallytime commented on Jun 10, 2016

    @rallytime
    Contributor

    Fixed via #32432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3PlatformState-Modulebugfixed-pls-verifyseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions