rules_k8s icon indicating copy to clipboard operation
rules_k8s copied to clipboard

workspace status command variable substitution for images

Open codesuki opened this issue 6 years ago • 9 comments

rules_docker has variable substitution from workspace status. So we can do

container_bundle(
    name = "all_images",
    images = {
        "gcr.io/{PROJECT_ID}/server:{DOCKER_TAG}": "//cmd/server:server_image",
    },
)

When we tried to switch to rules_k8s this surprisingly stopped working.

k8s_deploy(
    name = "development",
    cluster = "gke-cluster-name",
    template = ":kustomize-development",
    images = {
        "gcr.io/our-project/server:dev": "//cmd/server:server_image",
       # this doesn't work
         #"gcr.io/{PROJECT_ID}/server:{DOCKER_TAG}": "//cmd/server:server_image",
    },
)

What is the correct way to do this? Is there a plan to make this compatible with rules_docker?

codesuki avatar Jul 11 '19 06:07 codesuki

can you please provide a more detailed example of what you mean with "switch to rules_k8s"? I.e., what type of target is working with rules_docker when you specify images with substitutions and what type of target are you using in rules_k8s.

nlopezgi avatar Jul 16 '19 15:07 nlopezgi

Thanks for responding, I added more context to the text above.

codesuki avatar Jul 17 '19 02:07 codesuki

Thanks for the additional context @codesuki , It took a bit to remember how that works, but the logic to resolve the workspace status variables in rules_docker is here: https://github.com/bazelbuild/rules_docker/blob/master/container/join_layers.py#L201. To get this feature to work with rules_k8s it would be necessary to modify the resolver (https://github.com/bazelbuild/rules_k8s/blob/master/k8s/resolver.py) to also take in as input the stamp info (and get object.bzl to pass the info when calling resolver) and get the functionality similar to the one in join_layers. It's not a trivial change, and we are currently not working on adding new features to rules_k8s. If you are interested in volunteering a PR to get this working I'd be happy to help guide you.

nlopezgi avatar Jul 17 '19 16:07 nlopezgi

Thank you for your guidance. Right now I don't have time on my schedule for it but might consider it in the near future. In that case, I'll write here again.

we are currently not working on adding new features to rules_k8s.

Is this because you are satisfied with how it works right now or what are the reasons? Would it be better not to rely on it?

codesuki avatar Jul 17 '19 22:07 codesuki

it's because we are satisfied with how it works right now and have other higher priorities. You can continue to rely on it as we are committed to keep the current features working.

nlopezgi avatar Jul 18 '19 02:07 nlopezgi

and we will also continue receiving community contributions for new features/improvements!

nlopezgi avatar Jul 18 '19 02:07 nlopezgi

Thanks for clearing that up!

codesuki avatar Jul 18 '19 02:07 codesuki

Is this still valid? We've replaced the python resolver with a golang one.

fejta avatar Jun 20 '20 08:06 fejta

https://github.com/bazelbuild/rules_k8s/pull/423 This one solved my use case. If the golang resolver has the same functionality then I think it's fine :)

codesuki avatar Jun 22 '20 06:06 codesuki