Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect model for IPAM config settings #201

Closed
Mossop opened this issue Feb 24, 2022 · 7 comments
Closed

Incorrect model for IPAM config settings #201

Mossop opened this issue Feb 24, 2022 · 7 comments

Comments

@Mossop
Copy link

Mossop commented Feb 24, 2022

The current model for IPAM configuration is incorrect. It currently (https://cs.github.com/fussybeaver/bollard/blob/5effe1a16363d929e290919bca6542bbfaccd45a/codegen/target/generated-sources/src/models.rs#L1991) assumes a map of string keys to string values but the values can be more complex than this. One such example is the AuxiliaryAddresses setting which rather than having a string value is actually a map of strings to addresses.

One of my servers is using this, the list networks API call returns the following for the network in question:

{
    "Name": "services",
    "Id": "18e9cdac5d71b5b050b804b6d9d07aaa4104a986bf478e89057a088724c6328e",
    "Created": "2022-02-19T16:14:03.323536217Z",
    "Scope": "local",
    "Driver": "macvlan",
    "EnableIPv6": false,
    "IPAM": {
      "Driver": "default",
      "Options": null,
      "Config": [
        {
          "Subnet": "10.10.0.0/20",
          "IPRange": "10.10.12.0/24",
          "Gateway": "10.10.15.254",
          "AuxiliaryAddresses": { "bad": "10.10.12.0", "host": "10.10.12.1" }
        }
      ]
    },
    "Internal": false,
    "Attachable": true,
    "Ingress": false,
    "ConfigFrom": { "Network": "" },
    "ConfigOnly": false,
    "Containers": {},
    "Options": {
      "com.docker.network.bridge.name": "services",
      "parent": "enp1s0"
    },
    "Labels": {
      "com.docker.compose.network": "services",
      "com.docker.compose.project": "srv",
      "com.docker.compose.version": "1.24.1"
    }
  }

Bollard returns an error on encountering this due to the incorrect model: Failed to deserialize JSON: invalid type: map, expected a string at line 1 column 1057.

@Mossop
Copy link
Author

Mossop commented Feb 24, 2022

Looks like the swagger definition is incorrect here so that's unhelpful!

  IPAM:
    type: "object"
    properties:
      Driver:
        description: "Name of the IPAM driver to use."
        type: "string"
        default: "default"
      Config:
        description: |
          List of IPAM configuration options, specified as a map:

          ```
          {"Subnet": <CIDR>, "IPRange": <CIDR>, "Gateway": <IP address>, "AuxAddress": <device_name:IP address>}
          ```
        type: "array"
        items:
          type: "object"
          additionalProperties:
            type: "string"
      Options:
        description: "Driver-specific options, specified as a map."
        type: "object"
        additionalProperties:
          type: "string"

@fussybeaver
Copy link
Owner

Thanks for raising an issue upstream.

@fussybeaver
Copy link
Owner

I'm wondering if this can be supported in the swagger version 2 specification, as it does not support anyOf or oneOf like in later versions. We might need to handle this as an exception and build our own Enum type around this.

@fussybeaver
Copy link
Owner

I created an upstream patch and generated the bollard stubs from it. Could you test my branch to verify that the patch is correct?

https://github.com/fussybeaver/bollard/blob/ND-test-ipamconfig/codegen/target/generated-sources/src/models.rs#L2021-L2038

@Mossop
Copy link
Author

Mossop commented Mar 13, 2022

Can you give me some tips on how to test this branch? I tried the following in Cargo.toml:

bollard = { git = "https://github.com/fussybeaver/bollard", branch = "ND-test-ipamconfig", features = ["ssl"] }

But I think it didn't bring in the updated bollard-stubs so it was still failing to decode.

@fussybeaver
Copy link
Owner

Hmm... OK, I pulled in the new models into the Cargo.toml of the main repository, could you try with this:

bollard = { git = "https://github.com/fussybeaver/bollard", rev = "cf2b5de" }

@Mossop
Copy link
Author

Mossop commented Mar 14, 2022

Yes that resolves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants