Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

refactor: image api to create one img that includes list of tags/references #958 #882 #959

Merged
merged 7 commits into from
Dec 17, 2022

Conversation

jsilverio22
Copy link
Contributor

@jsilverio22 jsilverio22 commented Dec 2, 2022

#958 #882

Signed-off-by: Joshua Silverio joshua@acorn.io

@jsilverio22 jsilverio22 self-assigned this Dec 2, 2022
@jsilverio22 jsilverio22 force-pushed the refactor-img branch 2 times, most recently from b5cf37c to 2a6467e Compare December 2, 2022 23:00
@jsilverio22 jsilverio22 marked this pull request as ready for review December 2, 2022 23:08
@jsilverio22 jsilverio22 changed the title refactor: image api to create one img that includes list of tags/references #958 refactor: image api to create one img that includes list of tags/references #958 #882 Dec 2, 2022
@tylerslaton
Copy link
Contributor

tylerslaton commented Dec 5, 2022

@jsilverio22 Reviewing this now, can you take a look at resolving the merge conflicts?

@jsilverio22 jsilverio22 force-pushed the refactor-img branch 2 times, most recently from 8b14f68 to fe3f063 Compare December 5, 2022 15:42
@jsilverio22
Copy link
Contributor Author

@jsilverio22 Reviewing this now, can you take a look at resolving the merge conflicts?

should be all up to date now

Copy link
Contributor

@tylerslaton tylerslaton left a comment

Choose a reason for hiding this comment

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

Some initial comments that I wanted to get out. Will do some more reviewing later.

pkg/server/registry/images/storage.go Outdated Show resolved Hide resolved
integration/client/images/images_test.go Outdated Show resolved Hide resolved
pkg/cli/images.go Outdated Show resolved Hide resolved
pkg/client/image.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tylerslaton tylerslaton left a comment

Choose a reason for hiding this comment

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

Nice work!

pkg/client/image.go Outdated Show resolved Hide resolved
pkg/client/client.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
pkg/client/image.go Outdated Show resolved Hide resolved
pkg/client/image.go Outdated Show resolved Hide resolved
@cjellick
Copy link
Member

cjellick commented Dec 6, 2022

@jsilverio22 I want to define some behavior/usecases around deleting and untagging images here. Generally, it should follow the behavior of docker rmi, but I want to call out some edge cases explcitly:

When more than one tag exists

Given this list of images:

$ acorn images
REPOSITORY   TAG       IMAGE-ID
image-a      1         ddac371c3e35
image-a      2         ddac371c3e35
image-b      1         ddac371c3e35
image-b      latest    ddac371c3e35

note: image-b:latest can be the result of either acorn build -t image-b . or acorn build -t image-b:latest .

command expected behavior
acorn images rm image-a:1 untag image-a:1
acorn images rm --force image-a:1 untag image-a:1
acorn images rm image-b untag image-b:latest
acorn images rm image-b:latest untag image-b:latest
acorn images rm --force ddac371c3e35 delete the entire image

When exactly one tag exists

Given this list of images:

$ acorn images
REPOSITORY   TAG       IMAGE-ID
image-a      1         ddac371c3e35
command expected behavior
acorn images rm image-a:1 delete the entire image
acorn images rm ddac371c3e35 delete the entire image

When the image is "in use" by an app

As described in slack, we may also want to start considering whether there are any apps consuming an image. If we were mimicking docker rmi, we would:

  1. refuse to rm the image unless the user passed --force.
  2. only actually untag the image, but not delete it. it would still be there via digest
  3. update the output of acorn ps to have the digest, rather than the actual image name (though I imagine we'd want to keep app.spec unchanged)

Waiting to hear back from darren on what he'd want to do in those cases. I don't think you should focus on this part yet. I see this "when the image is 'in use' stuff as not critical to the refactor and could be done in a follow up

Copy link
Contributor

@tylerslaton tylerslaton left a comment

Choose a reason for hiding this comment

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

Another round of review. Nothing blocking from my end still, just some food for thought.

pkg/cli/images_rm.go Outdated Show resolved Hide resolved
pkg/client/image.go Outdated Show resolved Hide resolved
pkg/client/image.go Outdated Show resolved Hide resolved
pkg/cli/images.go Outdated Show resolved Hide resolved
pkg/tables/tables.go Show resolved Hide resolved
pkg/client/image.go Outdated Show resolved Hide resolved
pkg/client/image.go Outdated Show resolved Hide resolved
pkg/client/image.go Outdated Show resolved Hide resolved
pkg/client/image.go Outdated Show resolved Hide resolved
pkg/client/image.go Show resolved Hide resolved
pkg/cli/images.go Show resolved Hide resolved
pkg/server/registry/images/strategy.go Outdated Show resolved Hide resolved
pkg/server/registry/registry.go Show resolved Hide resolved
pkg/server/registry/images/strategy.go Outdated Show resolved Hide resolved
@jsilverio22
Copy link
Contributor Author

Next Steps:

  • Design discussion with @ibuildthecloud on CRDs vs resource version handling vs ignoring conflicts
  • If Ignore conflicts move tags.Write to handle []strings and remove old tags and write new ones
  • @cjellick to look into new framework to see if that can remove "do-nothing" methods in API
  • Move assumption of ":latest" to api side as there are multiple clients who can/will use it
  • Clarify image print templates (when/where they are used)

pkg/tables/tables.go Outdated Show resolved Hide resolved
pkg/cli/images.go Outdated Show resolved Hide resolved
@cjellick
Copy link
Member

acorn images -c output

If i specify an image (either via tag or digets) as part of the acorn images -c command, but that image has been tagged more than once, I am getting duplicate output.

Given:

# Given this normal image list:
$ acorn images
REPOSITORY   TAG       IMAGE-ID
image-a      1         6123877caafe
image-a      2         6123877caafe

Actual:

 $ acorn images -c image-a:1
REPOSITORY   TAG       IMAGE-ID       CONTAINER   DIGEST
image-a      1         6123877caafe   mycon1      sha256:9fbe5d4f861af0189c42c8eff224f95fe20a2ae91e6ff75f95857cf3bd0c38fa
image-a      2         6123877caafe   mycon1      sha256:9fbe5d4f861af0189c42c8eff224f95fe20a2ae91e6ff75f95857cf3bd0c38fa
image-a      1         6123877caafe   mycon2      sha256:41b16fa94dd2f42e33632e4bfc8fbb11e2dd98f45c3a37e933aba0783e84f8c1
image-a      2         6123877caafe   mycon2      sha256:41b16fa94dd2f42e33632e4bfc8fbb11e2dd98f45c3a37e933aba0783e84f8c1

Expected:

 $ acorn images -c image-a:1
REPOSITORY   TAG       IMAGE-ID       CONTAINER   DIGEST
image-a      1         6123877caafe   mycon1      sha256:9fbe5d4f861af0189c42c8eff224f95fe20a2ae91e6ff75f95857cf3bd0c38fa
image-a      1         6123877caafe   mycon2      sha256:41b16fa94dd2f42e33632e4bfc8fbb11e2dd98f45c3a37e933aba0783e84f8c1

Additionally, If i specify a digest like $ acorn images -c 6123877caafe, it should also similarily limit output to just once....but the old behavior in v0.4.2 is even a little weird...it just picks one of the tags to display. You can probably do the same - just use the first tag if there is one.

@cjellick
Copy link
Member

Tag stopped working since last iteration

acorn tag a:1 b:1
Error: resource name may not be empty

@cjellick
Copy link
Member

funkiness on kubectl output:

$ acorn images -a
REPOSITORY   TAG       IMAGE-ID
<none>       <none>    a086e2cd2261
a            1         a086e2cd2261
b            1         a086e2cd2261
<none>       <none>    71ad97238b13
simple-demo $ acorn images
REPOSITORY   TAG       IMAGE-ID
a            1         a086e2cd2261
b            1         a086e2cd2261
simple-demo $
simple-demo $
simple-demo $
simple-demo $ kubectl get images -n acorn
IMAGE-ID       TAGS
a086e2cd2261   <none>,a:1,b:1
71ad97238b13   <none>

shouldn't have if theres tags.

@@ -30,5 +31,9 @@ func NewImage(t *testing.T, namespace string) string {
if err != nil {
t.Fatal(err)
}
_, err = helper.BuilderClient(t, namespace).ImageCreate(context.Background(), image.ID, "")
Copy link
Member

Choose a reason for hiding this comment

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

when we sync with darren's changes, i dont know if this will stay her permanently or not.

@@ -59,6 +59,11 @@ func TestDev(t *testing.T) {

eg := errgroup.Group{}
eg.Go(func() error {
_, err = helper.BuilderClient(t, ns.Name).ImageCreate(ctx, "test-app", "")
Copy link
Member

Choose a reason for hiding this comment

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

again, not sure if we will do this permanently. you should keep all these ImageCreate adds in their own single commit that we can nuke later if we need to

@cjellick
Copy link
Member

Looking good @jsilverio22. You can squash this down now. I think this is as done as it's going to get until we can sync up with Darren's changes.

…rences acorn-io#958

Signed-off-by: Joshua Silverio <joshua@acorn.io>
Signed-off-by: Joshua Silverio <joshua@acorn.io>
Signed-off-by: Joshua Silverio <joshua@acorn.io>
return image, err
}
}
err = t.client.List(ctx, imageList)
Copy link
Member

Choose a reason for hiding this comment

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

This should be limited to the request namespace so that we are only checking for duplicates in the context of one namespace. You can have tag foo in two different namespaces, that is allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be limited now

image := obj.(*apiv1.Image)
duplicateTag := make(map[string]bool)

for _, tag := range image.Tags {
Copy link
Member

Choose a reason for hiding this comment

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

On update we should still validate that the new tag list is unique. Is that check still enforced?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it back & changed the order in which the image/tags runs. It will now update all duplicate tags and then either create the new image or update the existing one w/ the tags

@@ -171,7 +168,7 @@ type ImageTag struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

TagName string `json:"tagName,omitempty"`
Image *Image `json:"image,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Image *Image `json:"image,omitempty"`
Tags []string `json:"tags,omitempty"`

The other fields of image, namely Digest don't seem to have any use, lets just have the one field Tags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed to Image *Image with image/tags now having to call the create so now the requestImage can be created if it does not exist

func (t *TagStrategy) ImageTag(ctx context.Context, namespace, imageName string, requestImage *apiv1.Image) (*apiv1.Image, error) {
	image := &apiv1.Image{}
	imageList := &apiv1.ImageList{}
	err := t.client.Get(ctx, router.Key(namespace, imageName), image)
	if apierror.IsNotFound(err) {
		err = t.client.Create(ctx, requestImage)
		if err != nil {
			return image, err
		}

Copy link
Member

Choose a reason for hiding this comment

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

This is a side effect of the fact i've rewritten things. We don't want the user to be able to create new Image objects, but right now you have to create images from the client. So I guess just leave it as is and I'll refactor it in my PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay 👍

Name string `json:"name,omitempty"`
Digest string `json:"digest,omitempty"`
Repository string `json:"repository,omitempty"`
Tag string `json:"tags,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Tag string `json:"tags,omitempty"`
Tag string `json:"tag,omitempty"`

Signed-off-by: Joshua Silverio <joshua@acorn.io>
Signed-off-by: Joshua Silverio <joshua@acorn.io>
Signed-off-by: Joshua Silverio <joshua@acorn.io>
Signed-off-by: Joshua Silverio <joshua@acorn.io>
@ibuildthecloud ibuildthecloud merged commit e6f9d4e into acorn-io:main Dec 17, 2022
@jsilverio22 jsilverio22 deleted the refactor-img branch December 21, 2022 13:41
tylerslaton pushed a commit to tylerslaton/runtime that referenced this pull request Jan 5, 2023
…rences acorn-io#958 acorn-io#882 (acorn-io#959)

refactor: image api to create one img that includes list of tags/references acorn-io#958

Signed-off-by: Joshua Silverio <joshua@acorn.io>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants