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

Autoupdate Local #10063

Merged
merged 3 commits into from
Apr 29, 2021
Merged

Conversation

ParkerVR
Copy link
Collaborator

#9088

Introduces a new auto-update policy: "local"

Although it should probably be using NewFromLocal() and comparing image digests, the current method is to compare creation dates for autoupdate - Though I'd like to discuss before changing this system

I tested this using a modified version of the docs autoupdate instructions & it worked 'successfully'
(it required the ctr to be stopped before updating it- is this proper?)

Todo List:
Digest-Based Diff Check ?
Refactor/Merge similar functions
Write Tests
Alias "image" policy as "registry"

Will build off of #9740 to write tests

Signed-off-by: Parker Van Roy [email protected]

@ParkerVR ParkerVR requested a review from vrothberg April 16, 2021 19:39
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 16, 2021
//return ctr_digest == img_digest, nil

img_created := img.Created()
ctr_created := ctr.CreatedTime()
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 we should continue comparing digests rather than using time stamps. The latter is prone to errors.

@@ -174,6 +183,36 @@ func AutoUpdate(runtime *libpod.Runtime, options Options) ([]string, []error) {
}
}

// Autoupdate Local Iteration
for imageID, containers := range localMap {
Copy link
Member

Choose a reason for hiding this comment

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

That adds quite some duplicate code. I think we should have only loop and make the needsUpdate check conditional on the policy. We could achieve that by merging the maps into one.

map[imageUpdate][]*libpod.Container with

type imageUpdate struct {
    image string
    policy string
}

That allows for bundling an image with a policy:

for imageUpdate, containers := range myMap {
    switch imageUpdate.policy {
    case ...:
    case ...:
    }
}

@ParkerVR ParkerVR linked an issue Apr 20, 2021 that may be closed by this pull request
@ParkerVR ParkerVR force-pushed the autoupdate-local branch 4 times, most recently from a1261c9 to 7966d6c Compare April 23, 2021 00:51
@ParkerVR ParkerVR requested review from vrothberg, jwhonce and mheon April 23, 2021 01:15
@ParkerVR
Copy link
Collaborator Author

I have a working edition of the code and made some changes to refactor - new struct including the policy and changing the naming convention of the original autoupdate to 'registry'

Here is my manual test/results:
auto-update-local-test.txt

// PolicyNewImage is the policy to update as soon as there's a new image found.
PolicyNewImage = "image"
// PolicyRegistryImage is the policy to update as soon as there's a new image found.
PolicyRegistryImage = "image"
Copy link
Member

Choose a reason for hiding this comment

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

Could you change it to "registry"?

I would love us to use this term in the future as it's less ambiguous than "image". But (as you already did 👍) we still need to support "image" for backwards compat.

}

// Struct for tying a container to it's autoupdate policy
type PolicyContainer struct {
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 should be a private type.

@@ -198,14 +233,14 @@ func AutoUpdate(runtime *libpod.Runtime, options Options) ([]string, []error) {

// imageContainersMap generates a map[image ID] -> [containers using the image]
// of all containers with a valid auto-update policy.
func imageContainersMap(runtime *libpod.Runtime) (map[string][]*libpod.Container, []error) {
func imageContainersMap(runtime *libpod.Runtime) (map[string][]PolicyContainer, []error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you extend the comment of this function? I think it'll be helpful for future readers to understand the reasoning behind this structure:

  • policyContainer to bundle a policy with a container
  • Mapping from image to a slice of policy containers since it's possible that multiple containers refer to the same image but with different policies.

Thinking about the upper points. If the slice has [policy A, policy B, policy A] ... I think it would make sense to further bundle the items together such that we have to run a given policy only once instead of for each item individually.

A PolicyContainer could look as follows:

type policyMapper struct {
   map[Policy][]*libpod.Container
}

Now, when executing the policies we have direct mapping image -> policy -> containers using this policy.

@ParkerVR ParkerVR requested a review from vrothberg April 23, 2021 20:04
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.

Looking good!

Along with tests, we also need to extend the man pages a bit.

I think that some may argue that having different policies for one image may be wrong (configuration error). But I haven't made my mind up on that. @ParkerVR, what do you think? Do you think we should (in theory) yield an error if image foo as containers configured with registry and local?


// policyMapper is used for tying a container to it's autoupdate policy
type policyMapper struct {
pMap map[Policy][]*libpod.Container
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we could rewrite it to type policyMappyer map[Policy][]*libpod.Container

policyMap.pMap[policy] = append(policyMap.pMap[policy], ctr)
containerMap[id] = policyMap
// Now we know that `ctr` is configured for auto updates.
} else {
Copy link
Member

Choose a reason for hiding this comment

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

If we invert the branch logic, we can get rid of one branch:

if policy == PolicyDefault {
    continue
}
id, _ := ...

@ParkerVR
Copy link
Collaborator Author

@vrothberg to address your concern with multiple configurations, I think while this could be implemented I don't see a realistic use and as we just use a difference in digests it doesn't seem particularly rational to implement - so, I'm adding an error case.
On that note, is it even possible to use multiple labels like this- 'io.containers.autoupdate=local', 'io.containers.autoupdate=registry' would not overwrite each other?

Digests were used to compare local image and container image

Registry alias added for Image Policy

Refactored to integrate new feature + change some naming conventions

Tested this using a modified version of the docs autoupdate instructions & it worked successfully

Signed-off-by: Parker Van Roy <[email protected]>
Signed-off-by: Parker Van Roy <[email protected]>
@ParkerVR ParkerVR force-pushed the autoupdate-local branch 4 times, most recently from 996d03b to d10d8e8 Compare April 28, 2021 06:41
@ParkerVR ParkerVR requested a review from vrothberg April 28, 2021 07:23
An image is considered updated if the digest in the local storage is different than the one of the remote image.
If an image must be updated, Podman pulls it down and restarts the systemd unit executing the container.

The registry policy requires a requires a fully-qualified image reference (e.g., quay.io/podman/stable:latest) to be used to create the container.
This enforcement is necessary to know which image to actually check and pull.
If an image ID was used, Podman would not know which image to check/pull anymore.
Copy link
Member

Choose a reason for hiding this comment

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

Note that "registry" and "image" refer to the same policy for backwards compatibility.

@@ -42,7 +42,7 @@ function teardown() {

cname=$(random_string)
# See #7407 for --pull=always.
run_podman create --pull=always --name $cname --label "io.containers.autoupdate=image" $IMAGE top
run_podman create --pull=always --name $cname --label "io.containers.autoupdate=local" $IMAGE top
Copy link
Member

Choose a reason for hiding this comment

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

Please create a new test for the local policy. --pull=always and local conflict a bit and the TODO not below is a rather important reminder of open work items.

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.

Besides the nits in the system tests, LGTM

@ParkerVR ParkerVR changed the title [WIP] Autoupdate Local Autoupdate Local Apr 28, 2021
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 28, 2021
changed struct to policyMapper
change "image" to "registry" in multiple locations

Updated documentation with registry alias & autoupdate local

Added relevant test

Signed-off-by: Parker Van Roy <[email protected]>
@ParkerVR ParkerVR requested a review from vrothberg April 29, 2021 15:04
@jwhonce
Copy link
Member

jwhonce commented Apr 29, 2021

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 29, 2021
@mheon
Copy link
Member

mheon commented Apr 29, 2021

LGTM

@mheon
Copy link
Member

mheon commented Apr 29, 2021

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mheon, ParkerVR

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-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 29, 2021
@openshift-merge-robot openshift-merge-robot merged commit 4d2ba32 into containers:master Apr 29, 2021
@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 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 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.

6 participants