Skip to content

Conversation

@fgimenez
Copy link
Contributor

@fgimenez fgimenez commented Nov 4, 2021

What this PR does / why we need it:

Fixes discrepancy between the types used in inspect for docker and podman. This causes a panic when using the docker client against podman when the secondary IP fields in the NetworkSettings inspect field are populated.

How to verify it

  • podman system service --log-level debug -t 0 unix:///${HOME}/podman.sock > /var/log/podman.log 2>&1 &
  • Create a container with SecondaryIPV6Address populated in inspect's NetworkSettings
  • ln -s /root/podman.sock /var/run/docker.sock
  • Use docker cli to inspect the container:
inspected, err := cli.ContainerInspect(context.Background(), container.ID)
if err != nil {
  log.Panicf("could not inspect container %v\n", err)
} 

Which issue(s) this PR fixes:

Fixes #12165

Signed-off-by: Federico Gimenez [email protected]

@rhatdan
Copy link
Member

rhatdan commented Nov 4, 2021

@Luap99 @mheon @baude PTAL

@Luap99
Copy link
Member

Luap99 commented Nov 4, 2021

@fgimenez How do you create such a container?

@Luap99
Copy link
Member

Luap99 commented Nov 4, 2021

I think we might want to fix this only for the compat API and not regular inspect, @mheon WDYT?

@fgimenez
Copy link
Contributor Author

fgimenez commented Nov 4, 2021

@fgimenez How do you create such a container?

I'm finding this issue on CI doing something similar to:

$ sudo podman run --privileged -ti --entrypoint /bin/bash quay.io/kubevirtci/bootstrap:podman-test16
# inside the container
$ podman system service --log-level debug -t 0 unix:///${HOME}/podman.sock > /var/log/podman.log 2>&1 &
$ git clone https://github.com/kubevirt/kubevirtci && cd kubevirtci
$ make cluster-up # fails with default podman 3.4.1, succeeds with the changes in this PR
$ podman inspect k8s-1.20-node01
[
    {
................
        "NetworkSettings": {
            "EndpointID": "",
            "Gateway": "10.88.0.1",
            "IPAddress": "10.88.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "SecondaryIPv6Addresses": [
                "2001:db8:1::2/64"
            ],
..............

Will try to find a simpler example

@mheon
Copy link
Member

mheon commented Nov 4, 2021

Tend to agree with @Luap99 that this should be compat API only - this looks like a breaking change to me, and while we are in a breaking-change mode for 4.0, I don't see a good reason we should change inspect now, instead of just fixing the Docker-compat endpoint.

@fgimenez
Copy link
Contributor Author

fgimenez commented Nov 4, 2021

@Luap99 @mheon sgtm, where should I add the changes to make them compat API only?

@Luap99
Copy link
Member

Luap99 commented Nov 4, 2021

n, err := json.Marshal(inspect.NetworkSettings)
if err != nil {
return nil, err
}
networkSettings := types.SummaryNetworkSettings{}
if err := json.Unmarshal(n, &networkSettings); err != nil {
return nil, err
}

This is where the error happens. We cannot use json.marshal/unmarshal because the types do not match apparently so you would need to manually assign the value to the new struct.

@fgimenez fgimenez force-pushed the fix-docker-networksettings-type-discrepancy branch from e3398fd to 4457a62 Compare November 7, 2021 11:16
@fgimenez
Copy link
Contributor Author

fgimenez commented Nov 7, 2021

I think we might want to fix this only for the compat API and not regular inspect

Ok done, checked in our use case and works fine, also added a few unit tests. @Luap99 @mheon PTAL

@rhatdan
Copy link
Member

rhatdan commented Nov 8, 2021

@fgimenez Tests are failing.

@fgimenez fgimenez force-pushed the fix-docker-networksettings-type-discrepancy branch from 4457a62 to 41b8892 Compare November 9, 2021 08:00
@fgimenez
Copy link
Contributor Author

fgimenez commented Nov 9, 2021

@fgimenez Tests are failing.

@rhatdan thanks for the heads up! ok that error should be fixed now, I see now this test failing https://github.com/containers/podman/pull/12174/checks?check_run_id=4149334267 not sure if it is related to the changes in the PR?

@rhatdan
Copy link
Member

rhatdan commented Nov 9, 2021

@Luap99 @jwhonce @mheon PTAL

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also have to set the PrefixLen field in this struct, although I am not sure how we could get this value here if we do not change the type in libpod inspect as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I assumed that the strings in the current SecondaryIPv6Addresses's []string in libpod inspect represent actual addresses, not CIDRs, so the default value of PrefixLen of 0 should be ok, is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the strings in libpod's inspect output can contain CIDRs then maybe we could try to parse them, split by / if present or something like that, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I assumed that the strings in the current SecondaryIPv6Addresses's []string in libpod inspect represent actual addresses, not CIDRs, so the default value of PrefixLen of 0 should be ok, is this correct?

Sorry, this was wrong, if SecondaryIPv6Addresses's []string in libpod inspect represent actual addresses then PrefixLen should be 64, not 0 (32 for IPv4). I've pushed changes to fix it, PTAL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not correct. You should have the actual ip/prefix for this container, hard coding it to 64 or 32 is wrong.
TBH looking at this I think your original patch works better. We are on 4.0 so breaking changes are possible. I do not think there many users of the secondary ip field anyway.
@mheon WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the secondary IP field in podman inspect itself?

You're probably right that there are almost no users. I'm not strongly opposed to making a breaking change here.

@fgimenez fgimenez force-pushed the fix-docker-networksettings-type-discrepancy branch from 41b8892 to bb147e5 Compare November 11, 2021 16:30
@TomSweeneyRedHat
Copy link
Member

Changes LGTM
one last failure on the "fedora-34 rootless host" test, I've restarted.

@fgimenez fgimenez force-pushed the fix-docker-networksettings-type-discrepancy branch from bb147e5 to 32e89d3 Compare November 15, 2021 09:44
@flouthoc
Copy link
Collaborator

@fgimenez Needs a small test for inspect. :) or you could test CI via adding NO TESTS NEEDED to your commit message and add test later when everything is green.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 18, 2021
@fgimenez fgimenez force-pushed the fix-docker-networksettings-type-discrepancy branch from 78a3200 to ed7e46b Compare November 18, 2021 12:12
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 18, 2021
@fgimenez fgimenez force-pushed the fix-docker-networksettings-type-discrepancy branch from ed7e46b to a3e9dee Compare November 18, 2021 12:22
@fgimenez
Copy link
Contributor Author

@fgimenez Needs a small test for inspect. :) or you could test CI via adding NO TESTS NEEDED to your commit message and add test later when everything is green.

@flouthoc ok I've added a unit test for the changes, PTAL

@flouthoc
Copy link
Collaborator

@containers/podman-maintainers Could there be any issues with CI I think some unrelated tests are failing.

@mheon
Copy link
Member

mheon commented Nov 18, 2021

#12343 will fix CI once it merges, after that this will need to be rebased

@fgimenez fgimenez force-pushed the fix-docker-networksettings-type-discrepancy branch from a3e9dee to c910cbe Compare November 18, 2021 15:57
@fgimenez
Copy link
Contributor Author

#12343 will fix CI once it merges, after that this will need to be rebased

cool thx, I see it is already merged, rebased this one

@Luap99
Copy link
Member

Luap99 commented Nov 18, 2021

@fgimenez Could you squash your commits into one please, otherwise LGTM.

…data

structure.

Resolves a discrepancy between the types used in inspect for docker and podman.
This causes a panic when using the docker client against podman when the
secondary IP fields in the `NetworkSettings` inspect field are populated.

Fixes containers#12165

Signed-off-by: Federico Gimenez <[email protected]>
@fgimenez fgimenez force-pushed the fix-docker-networksettings-type-discrepancy branch from c910cbe to 2e5d3e8 Compare November 18, 2021 16:05
@fgimenez
Copy link
Contributor Author

@fgimenez Could you squash your commits into one please, otherwise LGTM.

sure, done

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 18, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fgimenez, Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 18, 2021
@Luap99
Copy link
Member

Luap99 commented Nov 18, 2021

/lgtm
/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 18, 2021
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 18, 2021
@Luap99
Copy link
Member

Luap99 commented Nov 19, 2021

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 19, 2021
@openshift-merge-robot openshift-merge-robot merged commit 5432bb9 into containers:main Nov 19, 2021
@fgimenez fgimenez deleted the fix-docker-networksettings-type-discrepancy branch November 24, 2021 12:30
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker api: NetworkSettings.SecondaryIPv6Addresses type mismatch

7 participants