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

Libnetwork: Add IgnoreIfExists flag to network create method #1250

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

ygalblum
Copy link
Contributor

@ygalblum ygalblum commented Dec 1, 2022

Having this flag is very useful when using scripts or systemd unit files

Signed-off-by: Ygal Blum ygal.blum@gmail.com

@ygalblum
Copy link
Contributor Author

ygalblum commented Dec 1, 2022

This PR relates to the comment about Quadlet's support for .network files: containers/podman#16688 (comment)

It is the first step in adding this flag to Podman, the same way it was added for Volumes here: containers/podman#16243.

@ygalblum
Copy link
Contributor Author

ygalblum commented Dec 1, 2022

@mheon, @Luap99 can you please take a look?

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM

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.

This cannot not be added to the network struct. The network struct is used all over the place (including netavark) , this option only applies to network create.

Can we catch the ErrNetworkExists error in podman instead?

@ygalblum
Copy link
Contributor Author

ygalblum commented Dec 1, 2022

This cannot not be added to the network struct. The network struct is used all over the place (including netavark) , this option only applies to network create.

Can we catch the ErrNetworkExists error in podman instead?

@Luap99 I'll split my answer into two.
First, the reason I did this here and not in Podman was because I wanted to mimic the behavior of Volume create which also handles this flag at the same level. I don't mind limiting it to Podman.
Second, regarding netavark I can see that it does pretty much the same. So, if this the concern, I make the same change there.

@Luap99
Copy link
Member

Luap99 commented Dec 1, 2022

Yes in theory we can handle it in libnetwork, but this a requires the change to be implement for every network backend which is possible but I don't really consider this a task the network backend should do.
But more importantly this type contains information about a network. This option has nothing to do with a network, it should never be returned in network list/inspect or send to netavark so the only other option is to break the interface and add a new parameter to the NetworkCreate call.

The important part is that the error is checked on the podman server side and not remote client. It does not need to happen inside libnetwork. Podman already blocks certain names here: https://github.com/containers/podman/blob/3f76f29adb070b3481843d33f75d05b8c8aebdfa/pkg/domain/infra/abi/network.go#L142-L145
I think the error can be check there.

I now also start to remember that I tried to do this a long time ago and it was decided against it, containers/podman#8842

Instead we agreed on podman network exits || podman network create

@ygalblum
Copy link
Contributor Author

ygalblum commented Dec 1, 2022

Podman already blocks certain names here:

Yes, I saw it too. But, again went with the layer in which it is handled for Volumes. I don't mind closing this PR and make the check there.

it was decided against it

I see that the discussion started from both Network and Volume and for Volumes it was since added. So, why not add it for Network? I think that from the users' persprctive, having Podman support the noop is much simpler and cleaner than making them write complex commands

@Luap99
Copy link
Member

Luap99 commented Dec 1, 2022

I see that the discussion started from both Network and Volume and for Volumes it was since added. So, why not add it for Network? I think that from the users' persprctive, having Podman support the noop is much simpler and cleaner than making them write complex commands

Yes I am totally ok with adding --ignore, I just wanted to link old discussions here.

Yes, I saw it too. But, again went with the layer in which it is handled for Volumes. I don't mind closing this PR and make the check there.

The only way to add it here is to break the interface to add a new parameter (or a new function). We do not guarantee a stable interface here AFAIK so that could work if you prefer to do it here.

@mheon
Copy link
Member

mheon commented Dec 1, 2022

C/common isn't 1.0 yet, so we can, but @nalind usually gets annoyed when we break Buildah because things changed. One extra parameter shouldn't be that bad, though, and I don't know if Buildah actually creates networks - I think it just consumes them.

@Luap99
Copy link
Member

Luap99 commented Dec 1, 2022

and I don't know if Buildah actually creates networks - I think it just consumes them.

Correct, buildah would not be effected by this.

@ygalblum
Copy link
Contributor Author

ygalblum commented Dec 4, 2022

@Luap99 @mheon I've changed the implementation by adding a new parameter to the API and implemented it for both CNI and Netavark.
The reason I kept it here is that this is where the checks are done inside a lock

libnetwork/cni/config.go Outdated Show resolved Hide resolved
Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM

@rhatdan
Copy link
Member

rhatdan commented Dec 5, 2022

@Luap99 PTAL

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.

one small comment, otherwise LGTM

libnetwork/types/network.go Outdated Show resolved Hide resolved
@Luap99
Copy link
Member

Luap99 commented Dec 5, 2022

Also before merging we need a ready to go podman PR with this change vendored to make sure we do not block others people work since you break the interface.

@vrothberg
Copy link
Member

Also before merging we need a ready to go podman PR with this change vendored to make sure we do not block others people work since you break the interface.

Great call, Paul. I keep forgetting to ask for that unfortunately.

@ygalblum, you can open the PR at Podman and vendor this (unmerged) PR here. You can use go mod edit -replace github.com/containers/common=$yourFork@$yourBranch.

@ygalblum
Copy link
Contributor Author

ygalblum commented Dec 5, 2022

@vrothberg is this containers/podman#16740 what you mean?

@vrothberg
Copy link
Member

@vrothberg is this containers/podman#16740 what you mean?

yes, thank you! Looks like you need to run make vendor and repush in the Podman PR

For now, only add IgnoreIfExists flag.
Having this flag is very useful when using scripts or systemd unit files

Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
@rhatdan
Copy link
Member

rhatdan commented Dec 6, 2022

/lgtm
/hold
/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 6, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan, ygalblum

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

The pull request process is described here

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 label Dec 6, 2022
@ygalblum
Copy link
Contributor Author

ygalblum commented Dec 6, 2022

@vrothberg, @Luap99 I don't want to mess up Podman, so, please let me know what should the next steps be w.r.t this PR and the one in Podman

@vrothberg
Copy link
Member

@vrothberg, @Luap99 I don't want to mess up Podman, so, please let me know what should the next steps be w.r.t this PR and the one in Podman

Since containers/podman#16740 is green, you can drop a /hold cancel here and then vendor in github.com/containers/common@main into the Podman PR.

@ygalblum
Copy link
Contributor Author

ygalblum commented Dec 6, 2022

/hold cancel

@openshift-merge-robot openshift-merge-robot merged commit eb48ebb into containers:main Dec 6, 2022
@ygalblum ygalblum deleted the network_ignore branch December 6, 2022 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants