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

api: ContainerCreate: clean up BC conditions #46720

Merged
merged 5 commits into from
Oct 25, 2023

Conversation

akerouanton
Copy link
Member

@akerouanton akerouanton commented Oct 25, 2023

- What I did

In postContainersCreate:

  1. Init hostConfig and networkingConfig when they're nil ;
  2. Return an error when config is nil ;
  3. Remove repetitive nil checks on config, hostConfig and networkingConfig ;
  4. Re-organize BC-related conditions ;

- How to verify it

CI is green.

- A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
@akerouanton akerouanton added area/api status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Oct 25, 2023
@akerouanton akerouanton changed the title api: ContainerCreate: clean up api: ContainerCreate: clean up BC conditions Oct 25, 2023
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -31,6 +31,8 @@ const (
ErrUnsupportedNetworkAndAlias validationError = "network-scoped alias is supported only for containers in user defined networks"
// ErrConflictUTSHostname conflict between the hostname and the UTS mode
ErrConflictUTSHostname validationError = "conflicting options: hostname and the UTS mode"
// ErrEmptyConfig when container config is nil
ErrEmptyConfig validationError = "Config cannot be empty in order to create a container"
Copy link
Member

Choose a reason for hiding this comment

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

Do we know if anything checks for this error message? (Was considering to fix the capitalisation (lowercase Config))

Copy link
Member Author

Choose a reason for hiding this comment

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

At least not the CLI. Is that enough to consider fixing the capitalization?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, probably; if CI still passes on 17.06 (and docker-py), we're probably good to go.

I'm ok with doing it separately though; perhaps better for this case to have a clear commit where we changed it (in case we missed it being used somewhere, and need to find a regression point)

@akerouanton akerouanton force-pushed the container-create-init-structs branch from 639eb62 to 6f1beb4 Compare October 25, 2023 15:35
Comment on lines +631 to +638
if hostConfig.PidsLimit != nil && *hostConfig.PidsLimit <= 0 {
// Don't set a limit if either no limit was specified, or "unlimited" was
// explicitly set.
// Both `0` and `-1` are accepted as "unlimited", and historically any
// negative value was accepted, so treat those as "unlimited" as well.
hostConfig.PidsLimit = nil
}

Copy link
Member

Choose a reason for hiding this comment

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

Funny how this is different in postContainerUpdate

if updateConfig.PidsLimit != nil && *updateConfig.PidsLimit <= 0 {
// Both `0` and `-1` are accepted to set "unlimited" when updating.
// Historically, any negative value was accepted, so treat them as
// "unlimited" as well.
var unlimited int64
updateConfig.PidsLimit = &unlimited
}

The same error is already returned by `(*Daemon).containerCreate()` but
since this function is also called by the cluster executor, the error
has to be duplicated.

Doing that allows to remove a nil check on container config in
`postContainersCreate`.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
- Merge BC conds for API < v1.42 together
- Merge BC conds for API < v1.44 together
- Re-order BC conds by API version
- Move pids-limit normalization after BC conds

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
@akerouanton akerouanton force-pushed the container-create-init-structs branch from 6f1beb4 to 4f0cab3 Compare October 25, 2023 19:25
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

still LGTM

For posterity; last push fixed a minor issue in a test that was overlooked in review (as the test was checking for the error message not the error;
Screenshot 2023-10-25 at 22 47 02

@thaJeztah thaJeztah merged commit 460e1b3 into moby:master Oct 25, 2023
104 checks passed
@akerouanton akerouanton deleted the container-create-init-structs branch October 25, 2023 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api kind/refactor PR's that refactor, or clean-up code status/4-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants