openconfig / kne

Apache License 2.0
214 stars 64 forks source link

Specifying a command for HOST nodes in a topology file does not override a default value #81

Closed bortok closed 2 years ago

bortok commented 2 years ago

There is a default value for command parameter for HOST nodes: /bin/sh -c sleep 2000000000000. This value should be replaced if a command is present in a topology definition, but instead, both are being merged. For example:

nodes: {
    name: "host1"
    type: HOST
    config: {
        image: "ubuntu-host:latest"
        command: "/start.sh"
        args: "-s"
    }
}

results in the following POD spec

    Command:
      /start.sh
      /bin/sh
      -c
      sleep 2000000000000
      /start.sh
    Args:
      -s
      -s

Alternatively, if a command is defined via an array like this:

nodes: {
    name: "host2"
    type: HOST
    config: {
        image: "ubuntu-host:latest"
        command: ["/start.sh", "-s"]
    }
}

we get

    Command:
      /start.sh
      -s
      /bin/sh
      -c
      sleep 2000000000000
      /start.sh
      -s

The issue seems to be originating at https://github.com/google/kne/blob/main/topo/node/host/host.go#L26. From Merge func documentation the expected behavior matches what is observed:

The elements of every list field in src is appended to the corresponded list fields in dst.

bortok commented 2 years ago

Tested with #83, looks good using both types of syntax:

host1 syntax now produces

    Command:
      /start.sh
    Args:
      -s

host2 syntax now produces

    Command:
      /start.sh
      -s

Both work as expected.