-
Notifications
You must be signed in to change notification settings - Fork 303
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
Add custom label
parameter to k8s_yaml
function for Tiltfile
#6106
Comments
Below are suggestions from ChatGPT on how such a requirement could work with tilt_label = 'my_label'
for resource in tilt.get_resources():
if resource.name.startswith('your-helm-release-name'):
k8s_resource(resource.name, labels=[tilt_label]) |
label
to k8s_yaml
functionlabel
parameter to k8s_yaml
function for Tiltfile
Closing this as a suitable workaround was found. We are using for w in [..., "my-chart-prometheus", "my-chart-grafana", ...]:
k8s_resource(workload=w, labels=["infra"]) # <<< Just to define Tilt resource labels
for w in [..., "my-chart-vitess", "my-chart-neo4j", ...]:
k8s_resource(workload=w, labels=["databases"]) # <<< Just to define Tilt resource labels
for w in [..., "my-chart-api-service1", "my-chart-api-service2", ...]:
k8s_resource(workload=w, labels=["apis"]) # <<< Just to define Tilt resource labels
... Ideally, all the calls to |
Found yet another (cleaner) workaround and thought to share it: # Intercept Tilt resource naming and also apply labels to resources
def apply_resource_labels(id):
if "prometheus" in id.name:
# Reference: https://docs.tilt.dev/api.html#api.k8s_resource
k8s_resource(
workload=id.name,
labels=["monitoring"],
)
elif "ingress-nginx" in id.name:
# Reference: https://docs.tilt.dev/api.html#api.k8s_resource
k8s_resource(
workload=id.name,
labels=["ingress"],
)
# elif ...
return id.name
# Reference: https://docs.tilt.dev/api#api.workload_to_resource_function
workload_to_resource_function(apply_resource_labels) |
Found yet another (cleaner) workaround and thought to share it: # Reference: https://docs.tilt.dev/api#api.decode_json
tilt_KubernetesApply_list = decode_json(
# Reference: https://docs.tilt.dev/api#api.local
json=local(
command="""
tilt get KubernetesApplys --output=json
""",
echo_off=True,
quiet=True,
)
)
for tilt_KubernetesApply in tilt_KubernetesApply_list.get('items', []):
tilt_KubernetesApply_yaml = tilt_KubernetesApply.get('spec', {}).get('yaml', "")
for tilt_labels in [l for l in tilt_KubernetesApply_yaml.splitlines() if 'tilt.dev/label' in l]:
tilt_resource_name = tilt_KubernetesApply.get('metadata', {}).get('name', "")
tilt_labels = tilt_labels.split(':')[1].strip()
if tilt_resource_name != None and len(tilt_resource_name) > 0 and tilt_labels != None and len(tilt_labels) > 0:
# Reference: https://docs.tilt.dev/api#api.k8s_resource
k8s_resource(
workload=tilt_resource_name,
labels=[tilt_labels],
) Though, this suffers from the same issue as described in #6349 (comment) (where the issue is the above code will update Tilt resource label in the UI on second run, not first) |
Describe the Feature You Want
Add
labels
parameter tok8s_yaml
function.Current Behavior
Currently, any resource sent to
k8s_yaml
gets no label. So the resources show up as "unlabeled"Why Do You Want This?
Similar to tilt-dev/tilt-extensions#299, it would be great to add
labels
parameter so that objects sent to the function can be customized.The grouping behavior is very nice. But it would be good to group arbitrary YAMLs together.
This is our user experience:
At this point we pretty much have everything else labeled. And in our minds, just keep a note that anything unlabeled is coming from our Helm chart and its dependencies.
Additional context
Our use case is code like this:
The text was updated successfully, but these errors were encountered: