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

kind load remove duplicate images names #2536

Merged
merged 2 commits into from Nov 18, 2021

Conversation

aojea
Copy link
Contributor

@aojea aojea commented Nov 14, 2021

Fixes: #2535

@aojea
Copy link
Contributor Author

aojea commented Nov 14, 2021

/assign @BenTheElder

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 14, 2021
Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

this is surprising, docker should handle this?
let me do some testing

@@ -24,6 +24,8 @@ import (

"github.com/spf13/cobra"

"k8s.io/apimachinery/pkg/util/sets"
Copy link
Member

Choose a reason for hiding this comment

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

ughhh we need to get rid of this dependency

Copy link
Contributor Author

@aojea aojea Nov 16, 2021

Choose a reason for hiding this comment

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

grep -r machinery pkg/ | grep sets
pkg/build/nodeimage/buildcontext.go:    "k8s.io/apimachinery/pkg/util/sets"
pkg/cluster/internal/kubeconfig/internal/kubeconfig/paths.go:   "k8s.io/apimachinery/pkg/util/sets"
pkg/cluster/internal/providers/docker/provider.go:      "k8s.io/apimachinery/pkg/util/sets"
pkg/cluster/internal/providers/podman/provider.go:      "k8s.io/apimachinery/pkg/util/sets"
pkg/cluster/internal/providers/common/images_test.go:   "k8s.io/apimachinery/pkg/util/sets"
pkg/cluster/internal/providers/common/images.go:        "k8s.io/apimachinery/pkg/util/sets"
pkg/cmd/kind/load/docker-image/docker-image.go: "k8s.io/apimachinery/pkg/util/sets"

Copy link
Member

Choose a reason for hiding this comment

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

pkg/internal/sets after #2539

Copy link
Member

Choose a reason for hiding this comment

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

(please group internal imports on their own, at the bottom, I had hoped to avoid internal imports in cmd/ but I think we can make an exception here, people re-implementing the cmd/ logic using the kind public APIs can just import k8s.io/apimachinery sets themselves if they need to implement this bit of logic)

@BenTheElder
Copy link
Member

I'm not sure this optimization is necessary, the check for presense is cheap (also the user can just dedupe themselves?) and docker etc. dedupe layers when save/load.

@aojea
Copy link
Contributor Author

aojea commented Nov 16, 2021

I'm not sure this optimization is necessary, the check for presense is cheap (also the user can just dedupe themselves?) and docker etc. dedupe layers when save/load.

the bug is legit and reproducible 🤷

@BenTheElder
Copy link
Member

the bug is legit and reproducible 🤷

it does not reproduce for me? what are you seeing?

we print two messages about loading the image (that just means we detected it wasn't loaded before loading it), we still only load the image once because we make one docker save call and docker dedupes (as does containerd), this seems to be WAI to me. if the user asks to load it twice we check both names.

besides, the user can have two slightly different names for the same image and the same behavior happens. it could be postgres:13 and postgres:13.4.

@aojea
Copy link
Contributor Author

aojea commented Nov 17, 2021

$ kind load docker-image busybox busybox -v7
Image: "busybox" with ID "sha256:018c9d7b792b4be80095d957533667279843acf9a46c973067c8d1dff31ea8b4" not yet present on node "kind-control-plane", loading...
Image: "busybox" with ID "sha256:018c9d7b792b4be80095d957533667279843acf9a46c973067c8d1dff31ea8b4" not yet present on node "kind-control-plane", loading...
ERROR: failed to load image: command "docker exec --privileged -i kind-control-plane ctr --namespace=k8s.io images import -" failed with error: exit status 1
Command Output: ctr: image "docker.io/library/busybox:1.29": already exists
Stack Trace: 
sigs.k8s.io/kind/pkg/errors.WithStack
        /home/aojea/go/pkg/mod/sigs.k8s.io/kind@v0.11.2-0.20210826184821-f8e6aa668edd/pkg/errors/errors.go:59
sigs.k8s.io/kind/pkg/exec.(*LocalCmd).Run
        /home/aojea/go/pkg/mod/sigs.k8s.io/kind@v0.11.2-0.20210826184821-f8e6aa668edd/pkg/exec/local.go:124
sigs.k8s.io/kind/pkg/cluster/internal/providers/docker.(*nodeCmd).Run
        /home/aojea/go/pkg/mod/sigs.k8s.io/kind@v0.11.2-0.20210826184821-f8e6aa668edd/pkg/cluster/internal/providers/docker/node.go:146
sigs.k8s.io/kind/pkg/cluster/nodeutils.LoadImageArchive
        /home/aojea/go/pkg/mod/sigs.k8s.io/kind@v0.11.2-0.20210826184821-f8e6aa668edd/pkg/cluster/nodeutils/util.go:80
sigs.k8s.io/kind/pkg/cmd/kind/load/docker-image.loadImage
        /home/aojea/go/pkg/mod/sigs.k8s.io/kind@v0.11.2-0.20210826184821-f8e6aa668edd/pkg/cmd/kind/load/docker-image/docker-image.go:181
sigs.k8s.io/kind/pkg/cmd/kind/load/docker-image.runE.func1
        /home/aojea/go/pkg/mod/sigs.k8s.io/kind@v0.11.2-0.20210826184821-f8e6aa668edd/pkg/cmd/kind/load/docker-image/docker-image.go:166
sigs.k8s.io/kind/pkg/errors.UntilErrorConcurrent.func1
        /home/aojea/go/pkg/mod/sigs.k8s.io/kind@v0.11.2-0.20210826184821-f8e6aa668edd/pkg/errors/concurrent.go:30
runtime.goexit
        /usr/local/go/src/runtime/asm_amd64.s:1581

@BenTheElder
Copy link
Member

f8e6aa668edd is a bit old, perhaps I can't reproduce because this was fixed in containerd at some point?

Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

needs a litte update after my mega PR, otherwise lgtm

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 17, 2021
@aojea
Copy link
Contributor Author

aojea commented Nov 17, 2021

/hold
there is a bug

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 17, 2021
@aojea
Copy link
Contributor Author

aojea commented Nov 17, 2021

/hold there is a bug

/hold cancel
false alarm

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 17, 2021
Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 17, 2021
return result
}
seen := make(map[string]struct{})
for _, s := range slice {
Copy link
Member

Choose a reason for hiding this comment

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

  1. the loop below is not go formatted properly (should be k := ...), I would guess your editor isn't configured to gofmt in simple mode? this is failing lints
  2. since we're rolling our own:
func removeDuplicates(slice []string) []string {
	result := []string{}
	seenKeys := make(map[string]struct{})
	for _, k := range slice {
		if _, seen := seenKeys[k]; !seen {
			result = append(result, k)
			seenKeys[k] = struct{}{}
		}
	}
	return result
}

(faster with one loop, simpler, no need to optimize for empty input, we require an argument)

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 18, 2021
@BenTheElder
Copy link
Member

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, BenTheElder

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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 18, 2021
@BenTheElder
Copy link
Member

/retest

@k8s-ci-robot k8s-ci-robot merged commit c8b759f into kubernetes-sigs:main Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could not load docker image in ubuntu in latest kind version
3 participants