rules_k8s icon indicating copy to clipboard operation
rules_k8s copied to clipboard

less targets generated

Open Toxicable opened this issue 5 years ago • 4 comments

I might be missed where this is configured, but is there a way to configure k8s_object to not have all the other targets that hang off it? We only use .create and .update and all the other targets produce cause us to build hundreds of extra targets, when we build the repository via npx bazel test ...

Toxicable avatar Dec 28 '19 05:12 Toxicable

They are always created, https://github.com/bazelbuild/rules_k8s/blob/a84d15926a882129b724105039ef804b8cbc6eb5/k8s/object.bzl#L524

fejta avatar Jan 11 '20 01:01 fejta

Yes that's the issue we have. We'd like to only build the targets that we actually use, .create and .update

Toxicable avatar Jan 11 '20 02:01 Toxicable

The code you're looking for is here:

https://github.com/bazelbuild/rules_k8s/blob/0a04716c226d0173bf7035965d9010871d39142b/k8s/object.bzl#L496-L587

k8s_object is a macro (aka function) which calls stuff like:

https://github.com/bazelbuild/rules_k8s/blob/0a04716c226d0173bf7035965d9010871d39142b/k8s/object.bzl#L527

https://github.com/bazelbuild/rules_k8s/blob/0a04716c226d0173bf7035965d9010871d39142b/k8s/object.bzl#L539

that actually declare these targets. This would probably involve putting something into **kwargs and extracting it. For example something like:

# default to all of them
verbs = kwargs.get("verbs", ["describe", "apply", "replace", "delete", "create")
if "create" in verbs: 
  _k8s_object_create(...)
if "apply" in verbs:
  _k8s_object_apply(...)
...

and you would change your usage to something like:

load("@rules_k8s//k8s:object.bzl", "k8s_object")
k8s_object(
  name = "foo",
  ...
  verbs = ["create", "delete"], # only create targets for these two verbs
)

Is this something you could contribute?

fejta avatar Jun 20 '20 08:06 fejta

This sounds interesting if someone wants to take it on, otherwise I'm going to close this out as it is the current intended behavior.

fejta avatar Jul 17 '20 18:07 fejta