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

Adds a kubeadm config images pull command #63833

Merged
merged 1 commit into from May 16, 2018

Conversation

@chuckha
Copy link
Member

chuckha commented May 15, 2018

This command will use crictl or docker to pull images locally.

The dockerfall back is needed because in some cases the kubelet is not
yet running so there is no CRI dockershim socket available.

Fixes kubernetes/kubeadm#812

Signed-off-by: Chuck Ha ha.chuck@gmail.com

What this PR does / why we need it:
This PR adds a command to the kubeadm config images subcommand to pull images using either crictl or docker.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes kubernetes/kubeadm#812

Special notes for your reviewer:

Release note:

Adds a `kubeadm config images pull` command to pull container images used by kubeadm.

/cc @kubernetes/sig-cluster-lifecycle-pr-reviews

return ip.exec.Command("sh", "-c", fmt.Sprintf("docker pull %v", image)).Run()
}

return ip.exec.Command(ip.crictlPath, "-r", ip.criSocket, "pull", image).Run()

This comment has been minimized.

@timothysc

timothysc May 15, 2018

Member

Don't we need todo version magic checking to ensure that the crictl can pull for the runtimes we are endorsing? We'll need to ship a version with kubeadm that we we vet.

This comment has been minimized.

@chuckha

chuckha May 15, 2018

Author Member

You are 💯% correct. We'll be addressing that in this issue kubernetes/kubeadm#811

Use: "images",
Short: "Interact with container images used by kubeadm.",
RunE: cmdutil.SubCmdRunE("images"),
}

This comment has been minimized.

@neolit123

neolit123 May 15, 2018

Member

did these two PRs overlap?
#63811

oddly, for the other one the bots are saying PR is unable to be automatically merged. Needs rebase. but github thinks there is no need for rebase.

the refactor and pull addition could have been separate commits.

This comment has been minimized.

@chuckha

chuckha May 15, 2018

Author Member

Yeah, that was me basing this branch off that one. I forgot to mention that, my mistake. The refactor and the addition are in two separate commits. I just fixed the merge conflict, it should look a lot better now.

@@ -258,8 +324,8 @@ func (i *ListImages) Run(out io.Writer) error {
return nil
}

// AddListImagesConfigFlag adds the flags that configure kubeadm
func AddListImagesConfigFlag(flagSet *flag.FlagSet, cfg *kubeadmapiv1alpha1.MasterConfiguration, featureGatesString *string) {
// AddImagesCommonConfigFlags adds the flags that configure kubeadm (and affect the images kubeadm will use)

This comment has been minimized.

@neolit123

neolit123 May 15, 2018

Member

it's OK to remove the ( ) here, but keep the text in there.

}

// Puller is an interface for pulling images
type Puller interface {

This comment has been minimized.

@fabriziopandini

fabriziopandini May 15, 2018

Contributor

What about to move it in app/images? This more part of a re-usabe tools than a UX concern...
(Same for types that follows)

This comment has been minimized.

@chuckha

chuckha May 15, 2018

Author Member

I was thinking about this as if it were an internal interface (which I should have then named it puller instead) -- not really something for reuse, but I don't see any reason why it can't live in the images package.

The ImagesPull was not designed for use elsewhere, but looking at it a bit closer, the only thing I can see that is specific to this command is the glog call.

Would you be ok if I moved the Puller interface out to the images package but kept ImagesPull internal to this package for now?

This comment has been minimized.

@fabriziopandini

fabriziopandini May 16, 2018

Contributor

Ever if there is no real use case for reuse now, I would like to have the capability to pull a set of images implemented in the app/images package instead of in the UX

..., the only thing I can see that is specific to this command is the glog call.
I don't see this as a constraint, e.g. there are already several glog calls in phases

)

// ImagePuller is a struct that can pull images and hides the implementation (crictl vs docker)
type ImagePuller struct {

This comment has been minimized.

@fabriziopandini

fabriziopandini May 15, 2018

Contributor

criImagePuller?

This comment has been minimized.

@chuckha

chuckha May 15, 2018

Author Member

Why make it private? I'd also argue that the name should not reveal the implementation as this uses either docker or crictl to pull images

This comment has been minimized.

@fabriziopandini

fabriziopandini May 16, 2018

Contributor

The initial lower case was a typo, sorry

However I'm still not fully comfortable about naming of ImagePull and ImagePuller because those confused me while reading the code. If we are keeping 'ImagePuller' because it's implementation, what about ImagePull -> ImageSetPuller or something that makes more clear it's responsibility to coordinate the pull process for a set of images

@fabriziopandini
Copy link
Contributor

fabriziopandini left a comment

@chuckha
I suggested some refactoring for a better separation between UX and the image pull machinery.
However the PR overall is fine for me. Thanks!

@chuckha chuckha force-pushed the chuckha:image-puller branch from b8383c0 to 6005981 May 15, 2018


// Pull pulls the actual image using either crictl or docker
func (ip *ImagePuller) Pull(image string) error {
if ip.crictlPath == "" {

This comment has been minimized.

@chuckha

chuckha May 15, 2018

Author Member

This logic is wrong. We want to use docker if the cri socket is the default docker socket. Otherwise, use crictl

@chuckha chuckha force-pushed the chuckha:image-puller branch from 6005981 to f61559d May 15, 2018

@timothysc
Copy link
Member

timothysc left a comment

/approve

@fabriziopandini please lgtm when you are happy with the change.

@luxas
Copy link
Member

luxas left a comment

A couple of comments that need fixing, but overall this LGTM 👍. Thanks for this patch!

return cmd
}

// NewCmdConfigImagesPull returns the `config images pull` command
func NewCmdConfigImagesPull() *cobra.Command {
cfg := kubeadmapiv1alpha1.MasterConfiguration{}

This comment has been minimized.

@luxas

luxas May 16, 2018

Member

must use & pointer here

This comment has been minimized.

@chuckha

chuckha May 16, 2018

Author Member

Is 'must' the right word here? I don't think it is unless I'm missing something.

I'm passing around the pointer everywhere else so I understand to reduce the number of &s it would make more sense to initialize it as a pointer. That being said I do agree, it's better as a pointer.

This comment has been minimized.

@luxas

luxas May 16, 2018

Member

It's technically not a must, but practically. If you init it as a pointer, you don't have to remember to pass & all the time. I'm pretty sure most things break if someone somehow forgets to pass the pointer at some time. Would be super hard to debug and notice.

This comment has been minimized.

@chuckha

chuckha May 16, 2018

Author Member

fair point 👍 thanks for explaining what you meant

// NewCmdConfigImagesPull returns the `config images pull` command
func NewCmdConfigImagesPull() *cobra.Command {
cfg := kubeadmapiv1alpha1.MasterConfiguration{}
kubeadmapiv1alpha1.SetDefaults_MasterConfiguration(&cfg)

This comment has been minimized.

@luxas

luxas May 16, 2018

Member

kubeadmscheme.Scheme.Default(cfg)
where kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"

This comment has been minimized.

@chuckha

chuckha May 16, 2018

Author Member

sure, seems reasonable. I need to understand this stuff better

func (ip *ImagesPull) PullAll() error {
for _, image := range ip.images {
if err := ip.puller.Pull(image); err != nil {
return fmt.Errorf("failed to pull image [%v]: %v", image, err)

This comment has been minimized.

@luxas

luxas May 16, 2018

Member

nit: maybe use %q instead of [%v]?

This comment has been minimized.

@chuckha

chuckha May 16, 2018

Author Member

thanks for this nit, I always default to %v but will endeavor to improve my formatting strings :)

if err := ip.puller.Pull(image); err != nil {
return fmt.Errorf("failed to pull image [%v]: %v", image, err)
}
glog.Infof("[config/images/pull] Pulled %v", image)

This comment has been minimized.

@luxas

luxas May 16, 2018

Member

just [images] is fine for me here. As image is a string, use %s\n (don't forget the newline)

@@ -254,12 +304,12 @@ func NewImagesList(cfgPath string, cfg *kubeadmapiv1alpha1.MasterConfiguration)
}, nil
}

// ImagesList defines the struct used for "kubeadm config images list"
// ImagesList defines the struct used for "kubeadm images"

This comment has been minimized.

@luxas

luxas May 16, 2018

Member

Why change this?

This comment has been minimized.

@chuckha

chuckha May 16, 2018

Author Member

This was probably a merge conflict failing, good 👀

import (
"fmt"

kubeadmdefaults "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha1"

This comment has been minimized.

@luxas

luxas May 16, 2018

Member

kubeadmapiv1alpha1

// NewImagePuller returns a ready to go ImagePuller
func NewImagePuller(execer utilsexec.Interface, criSocket string) (*ImagePuller, error) {
crictlPath, err := execer.LookPath("crictl")
if crictlPath == "" && err != nil {

This comment has been minimized.

@luxas

luxas May 16, 2018

Member

What happens if crictlPath is "" but there isn't an error?

This comment has been minimized.

@neolit123

neolit123 May 16, 2018

Member

&& -> ||

This comment has been minimized.

@chuckha

chuckha May 16, 2018

Author Member

Also wrong logic from before -- If we need crictl (our crisocket is not the default) then we fail. Otherwise it's fine that we don't have crictl available (since we use docker instead).

@luxas luxas self-assigned this May 16, 2018

@chuckha chuckha force-pushed the chuckha:image-puller branch 2 times, most recently from 79aeac4 to c2d0f8b May 16, 2018

@chuckha chuckha force-pushed the chuckha:image-puller branch from c2d0f8b to 0edf208 May 16, 2018

Adds a kubeadm config images pull command
This command will use crictl or docker to pull images locally.

The dockerfall back is needed because in some cases the kubelet is not
yet running so there is no CRI dockershim socket available.

Fixes kubernetes/kubeadm#812

Signed-off-by: Chuck Ha <ha.chuck@gmail.com>

@chuckha chuckha force-pushed the chuckha:image-puller branch from 0edf208 to 7ecab96 May 16, 2018

@luxas

luxas approved these changes May 16, 2018

Copy link
Member

luxas left a comment

/lgtm

Thanks a lot Chuck 🎉!

@k8s-ci-robot k8s-ci-robot added the lgtm label May 16, 2018

@luxas luxas added the approved label May 16, 2018

@k8s-ci-robot

This comment has been minimized.

Copy link
Contributor

k8s-ci-robot commented May 16, 2018

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: chuckha, luxas, timothysc

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-github-robot

This comment has been minimized.

Copy link
Contributor

k8s-github-robot commented May 16, 2018

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 82b355e into kubernetes:master May 16, 2018

15 of 18 checks passed

Submit Queue Required Github CI test is not green: pull-kubernetes-kubemark-e2e-gce
Details
pull-kubernetes-e2e-gce-100-performance Job triggered.
Details
pull-kubernetes-kubemark-e2e-gce-big Job triggered.
Details
cla/linuxfoundation chuckha authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-cross Skipped
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gke Skipped
pull-kubernetes-e2e-kops-aws Job succeeded.
Details
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce Job succeeded.
Details
pull-kubernetes-local-e2e Skipped
pull-kubernetes-local-e2e-containerized Skipped
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.