kind icon indicating copy to clipboard operation
kind copied to clipboard

cmd/load: consider auto pull the image if does not exist in locally

Open Dentrax opened this issue 3 years ago • 7 comments

What would you like to be added:

It should have better UX if we automatically pull the non-existed image from the registry:

$ kind load docker-image $(IMAGE)

See the related image control check flow here.

We can create a new function that executes docker pull ... command as the following:

func pullImage(imageRef string) error {
	cmd := exec.Command("docker", "pull", "{{ .ref }}",
		imageRef, // ... against the container
	)
	lines, err := exec.OutputLines(cmd)
	if err != nil {
		return err
	}
	return nil
}

Implementing would be straightforward:

imageID, err := imageID(imageName)
if err != nil {
  logger.V(0).Infof("image: %q not present locally", imageName)
  err = pullImage(imageName)
  if err != nil {
   return fmt.Errorf("could not pull the image: %q", imageName)
  }
}

If this implementation may break the as-is legacy flow, we can easily pass a feature flag something like $AUTO_PULL_ENABLED in order to enable this feature.

Why is this needed:

To provide better developer experience. @developer-guy ⚡️

Dentrax avatar Aug 19 '21 14:08 Dentrax

we (w/@Dentrax) are the volunteers for doing this issue 🥳🙋🏻‍♂️🤝

developer-guy avatar Aug 20 '21 06:08 developer-guy

If this implementation may break the as-is legacy flow

Auto-pulling is actually not a safe default and will break developer flows. Consider for example I have built my own version of an image locally for development, pulling will replace it with the public hosted version.

I think maybe a --pull flag would be reasonable though. It may be somewhat familiar to users due to e.g. docker build ...,

BenTheElder avatar Aug 20 '21 16:08 BenTheElder

I would argue that actually the majority of load usage is for images that have not been pushed, to avoid using a registry for local development workflow. The other case is some attempt at optimization of image pulling, or importing images the cluster doesn't have credentials to pull. The first case is at least definitely significant and must be considered, this is why the command does not pull currently (and whatever tool is calling load can call docker pull in the case of e.g. private images).

BenTheElder avatar Aug 20 '21 16:08 BenTheElder

Rightnow kind always look for the local image and if it exists it blindly ignores to pull the image even if there is a change in node image. The classic example is with tags like :master pointing to the node image for the k8s master branch, I expect kind should have a mechanism to specific pull type like we have in the docker ("always"|"missing"|"never") (default "missing") instead of just having missing(the existing behaviour)

I understand this is not a regular usecase but good to have better UX for the developers.

mkumatag avatar Sep 12 '22 05:09 mkumatag

You can pull the image yourself if you're using images that are not pinned. We strongly encourage pinning by digest.

BenTheElder avatar Sep 12 '22 06:09 BenTheElder

@mkumatag i think you're confusing the node images and loading images. Loading images never pulls and the user must pull. Node images specified for running a cluster are pulled if not present. You can make that always by pulling before starting the cluster. It's unclear what the use case would be for never for node images, and in any case this issue is NOT about node images nor is the linked PR you commented on.

BenTheElder avatar Sep 12 '22 06:09 BenTheElder

@mkumatag i think you're confusing the node images and loading images. Loading images never pulls and the user must pull. Node images specified for running a cluster are pulled if not present. You can make that always by pulling before starting the cluster. It's unclear what the use case would be for never for node images, and in any case this issue is NOT about node images nor is the linked PR you commented on.

ya, I realise that now.. sorry for creating confusion..

mkumatag avatar Sep 12 '22 06:09 mkumatag

I don't think building this in is a significant improvement over "docker pull && kind load" and it is yet another logic branch to maintain

BenTheElder avatar Apr 18 '23 04:04 BenTheElder