rules_k8s icon indicating copy to clipboard operation
rules_k8s copied to clipboard

add --noupload flag or similar to not try and upload the image

Open Globegitter opened this issue 6 years ago • 8 comments

https://github.com/bazelbuild/rules_k8s/pull/188 added a great fix of something that has bitten us a few times but it would also be nice to have a way to explicitly tell the resolver to not upload the image / not try to resolve any images. Sometimes all we want is verify the final k8s manifest but might be without internet connection or the image to be uploaded is large so would take a while to be uploaded. I first want to see how https://github.com/bazelbuild/rules_k8s/issues/209 pans out before adding any other cli flags but just wanted to have the issue tracked.

So the idea would be to be able to run the command like bazel run :target -- --noupload or similar.

Globegitter avatar Nov 09 '18 20:11 Globegitter

—dry-run=true should help. Now the container I think is uploaded with the docket tool chain, so you would need to address that there. But using the dry run args should help with this toolchain.

chrislovecnm avatar Nov 10 '18 23:11 chrislovecnm

Also I think I am correct but kubectl required communication with a cluster in order to render the yaml. It needs to know the cluster api version. You can test this by trying the dry run flag w/o a internet connection. I think it will timeout.

chrislovecnm avatar Nov 10 '18 23:11 chrislovecnm

For --dry-run it does indeed need a connection to the cluster but just to use bazel run :target that renders the template fine without connection to the cluster so for that use-case the flag would imo still be useful.

Globegitter avatar Nov 14 '18 09:11 Globegitter

I actually have a working implementation of this that I forgot about. It's a resolver that accepts a --no_upload flag. If specified, it calculates the image digest locally and uses that as the tag.

Does that sound reasonable? Should I open a PR?

rohansingh avatar Mar 22 '19 21:03 rohansingh

@rohansingh that sounds great, would love to see this as a PR.

Globegitter avatar Mar 26 '19 19:03 Globegitter

sgtm too; I'd be happy to review (lets try to add a test to the PR if possible). Thanks @rohansingh

nlopezgi avatar Mar 26 '19 19:03 nlopezgi

I've done a similar thing as @rohansingh (https://github.com/bnczk/rules_k8s/tree/daemon-resolver). If the appropriate flag is set, the digest is set as tag, the image loaded into the daemon and the template references the image by tag instead of digest. Using the tag is necessary as the daemon does not set the digest if it wasn't pulled from a registry. This greatly simplifies our local development.

If this is an acceptable feature, I'll start on the appropriate tests and open a PR.

afsluit avatar Aug 07 '20 08:08 afsluit

@georgwastaken thank you for posting. I think you should make a PR. FWIW, I just copied your resolver.go file and passed it to the resolver field like so:

k8s_deploy(
    name = "server",
    images = {
        "img": "//diypaxos:diypaxos_image",
    },
    resolver = "//diypaxos/k8/resolver:resolver",
    template = ":simple-kv-store.yaml",
)

In resovler.go, I also set allow_unused_images and load_daemon to default to true.

Thank you for posting your comment, it unblocked me :)

lolitsgab avatar Dec 07 '22 07:12 lolitsgab