tilt-dev / tilt-dev/tilt

Cannot specify namespace to use for label selectors with `k8s_custom_deploy`

Open
#5,208 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
10.1k
Forks
413
Avg merge
1d 10h
Merged PRs (30d)
6

Description

Expected Behavior
  • Possible to rely on label selectors with k8s_custom_deploy that does not return any YAML from apply_cmd
Current Behavior
  • We only watch for events in namespaces that we've seen a deployed object in, which we determine from result YAML, so if we never get any YAML, we won't watch any namespaces and label selectors will silently fail
    • If you also apply resource(s) that DO use result YAML, assuming there's a namespace overlap, things will work implicitly
Steps to Reproduce
  1. Create a Tiltfile with a k8s_custom_deploy that doesn't return YAML and relies on label selectors:

     k8s_custom_deploy(
         'nginx',
         apply_cmd='kubectl apply -f app.yaml 1>&2',
         delete_cmd='kubectl delete -f app.yaml',
         deps=['app.yaml']
     )
    
     k8s_resource('nginx', extra_pod_selectors={'app': 'web'}, discovery_strategy='selectors-only')
    

    app.yaml:

     apiVersion: apps/v1
     kind: Deployment
     metadata:
       name: web
     spec:
       selector:
         matchLabels:
           app: web
       replicas: 1
       template:
         metadata:
           labels:
             app: web
         spec:
           containers:
             - name: web
               image: nginx
               resources:
                 limits:
                   cpu: 100m
                   memory: 128Mi
               ports:
                 - containerPort: 80
               readinessProbe:
                 httpGet:
                   port: 80
                 failureThreshold: 1
                 periodSeconds: 10
    
  2. Run tilt up

  3. Run kubectl get pod -l app=web to see that pod exists and is healthy

  4. Observe that Tilt UI shows it as perpetually pending / has no logs / is unaware of Pod's existence

Context

I think the most logical thing here is to add an optional namespace arg to k8s_resource to explicitly use in the KubernetesDiscoveryTemplateSpec + KubernetesDiscoverySpec in addition to(?) any implicitly discovered namespaces. It should probably be an error to set this without also populating extra_pod_selectors because otherwise it's meaningless.

Alternatively, we could have a "magic" key in extra_pod_selectors that's something like $namespace (not a valid K8s label identifier, so no risk of overlap) to use for this purpose without changing the API.

We also currently eagerly watch any namespaces based on the spec YAML; in the case of a spec apply cmd, we could eagerly watch the "default" namespace in that case, but that only works if that's the namespace the apply cmd actually uses, which isn't a given.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the k8s_resource implementation and the KubernetesDiscoveryTemplateSpec and KubernetesDiscoverySpec mentioned in the issue. Reproduce the selectors-only example, then determine how an explicit namespace should combine with implicitly discovered namespaces; done means a custom deploy with no result YAML watches the specified namespace and discovers matching pods.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
devops, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.