Comments (2)
thanks for the report!
from tilt.
Currently working with a non-ideal workaround below:
# Intercept Tilt resource naming and also apply labels to resources
def apply_resource_labels(id):
# Set the TILT_RESOURCE environment variable
# This allows us to share information globally between Tiltfile functions scope and within apply_resource_labels function
resource_identifier = "%s/%s/%s" % (id.namespace, id.kind, id.name)
if os.getenv("TILT_RESOURCE", None) == None:
os.environ["TILT_RESOURCE"] = resource_identifier
else:
if os.environ["TILT_RESOURCE"].find(resource_identifier) <= -1:
if os.environ["TILT_RESOURCE"] != "":
os.environ["TILT_RESOURCE"] += ","
os.environ["TILT_RESOURCE"] += resource_identifier
return id.name
# Reference: https://docs.tilt.dev/api#api.workload_to_resource_function
workload_to_resource_function(apply_resource_labels)
if os.getenv("TILT_RESOURCE", None) != None:
# Will not execute on first run
# But will execute on subsequent runs (i.e. when Tilt control loop triggers again on file/folder/resource changes)
for r in os.environ["TILT_RESOURCE"].split(","):
# Split the resource identifier into namespace, kind and name
ns = r.split("/")[0]
kd = r.split("/")[1].lower()
nm = r.split("/")[2]
resource_value = str(
local(
command="""
kubectl --namespace %s get %s %s --output jsonpath='{.metadata.labels.tilt\\.dev\\/resource}' --ignore-not-found=true
""" % (
ns, kd, nm,
),
echo_off=True, # skips printing command to log.
quiet=True, # skips printing output to log.
)
)
label_value = str(
local(
command="""
kubectl --namespace %s get %s %s --output jsonpath='{.metadata.labels.tilt\\.dev\\/label}' --ignore-not-found=true
""" % (
ns, kd, nm,
),
echo_off=True, # skips printing command to log.
quiet=True, # skips printing output to log.
)
)
# # Set sensible default label values
# if label_value == None or len(label_value) <= 0:
# if "prometheus" in resource_value:
# label_value = "monitoring"
# elif "ingress-nginx" in resource_value:
# label_value = "ingress"
# # elif ...
if label_value and len(label_value) > 0:
if resource_value and len(resource_value) > 0:
# Reference: https://docs.tilt.dev/api.html#api.k8s_resource
k8s_resource(
workload=nm,
new_name=resource_value,
labels=[label_value],
)
else:
# Reference: https://docs.tilt.dev/api.html#api.k8s_resource
k8s_resource(
workload=nm,
labels=[label_value],
)
Note: This is not ideal because it will not set resource names / labels on first pass of Tiltfile parsing. On second pass, the
TILT_RESOURCE
environment variable value will be accessible by rest of Tiltfile functions and so can be used to programmatically access them and detect and set Tilt resource names and labels
from tilt.
Related Issues (20)
- Tilt syncback does not work on WSL2 (Linux subsystem for Windows) HOT 3
- tilt down does not kill Tilt process HOT 1
- Support Tiltfile args with `tilt enable` HOT 1
- Docker compose profiles set to * doesn't work HOT 5
- Tilt tries to push to docker registry when used with rootless docker + minikube HOT 4
- livenessProbeProbe returns Connection Refused HOT 1
- Override auto_init for `tilt ci` HOT 2
- Feature Request: Support Gitlab subgroups within an extension repo's URL HOT 2
- When specifying a deployment namespace with `tilt up --namespace <NAMESPACE>`, if `<NAMESPACE>` does not currently exist, create the namespace. HOT 4
- Make it Scoopable HOT 1
- How to Starlark here to config it? HOT 1
- missing argument for echo_off HOT 1
- split service from workload resource
- Graceful shutdown is ignored by Tilt HOT 3
- tty in local_resource kills tilt HOT 2
- Log pane scrolls to top when truncating
- live update doesn't work with jobset HOT 2
- ability to wait on crd deletion before deleting operator
- tty in node in local_resource kills tilt
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tilt.