tilt icon indicating copy to clipboard operation
tilt copied to clipboard

why does k8s_resource(objects) need to match a unique resource?

Open nicks opened this issue 5 years ago • 3 comments

When I've used k8s_resource(objects) for our own deployments, I've found it annoying to configure.

Often, I want ALL the resources named X, and it feels weird to list them out by type.

k8s_resource(
  new_name='prometheus',
  objects = [
    'tilt-prometheus:Prometheus',
    'tilt-prometheus:Service',
  ])

is there some reason why we can't support:

k8s_resource(
  new_name='prometheus',
  objects = [
    'tilt-prometheus'
  ])

such that it grabs both resources? It seems like that's how other users have expected it to work, as someone pointed out here: https://github.com/tilt-dev/tilt/issues/3714

right now, if I do this, I just get an error:

"tilt-prometheus" is not a unique fragment. Objects that match "tilt-prometheus" are "tilt-prometheus:Prometheus:tilt-telemetry", "tilt-prometheus:Service:tilt-telemetry"

nicks avatar Aug 25 '20 18:08 nicks

From Slack, jappievw writes that it'd also be nice for these to support some form of wildcarding (e.g. starts with):

I'm deploying apps to a dedicated namespace. It would be great if the object matcher for k8s_resource would allow for pattern matching of objects to allow for:

  1. All objects in a namespace.
  2. All objects which start with (and variants). An example resource I have is: traefik-dotenv-66tm2k6b4c:Secret:kube-system

milas avatar Feb 01 '21 16:02 milas

Today I learned that all uncategorized resources are created before any of the named resources. Below I included a simplified version of a Tiltfile and the built version of the kustomize definition.

As the secret can not be included in the whoami k8s resource, Tilt tries to apply the secret first. However, the first time the namespace is not created. When I remove the TLS certificate and the ingress in the first run, all works fine.

load('ext://namespace', 'namespace_create')
namespace_create('whoami')
k8s_yaml(kustomize('./k8s/whoami/local'))
k8s_resource(
    workload='whoami-deployment',
    new_name='whoami',
    links='https://whoami.yosokugames.dev',
    objects=[
        'whoami-ingress:ingress:whoami',
    ],
)
apiVersion: v1
data:
  tls.crt: |
    snip
  tls.key: |
    snip
kind: Secret
metadata:
  labels:
    k8s-app: whoami
  name: whoami-star-yosokugames-dev-9t56kbf552
  namespace: whoami
type: kubernetes.io/tls
---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: whoami
  name: whoami-service
  namespace: whoami
spec:
  ports:
  - port: 80
    protocol: TCP
  selector:
    k8s-app: whoami
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s-app: whoami
  name: whoami-deployment
  namespace: whoami
spec:
  selector:
    matchLabels:
      k8s-app: whoami
  template:
    metadata:
      labels:
        k8s-app: whoami
    spec:
      containers:
      - image: traefik/whoami
        name: whoami
        ports:
        - containerPort: 80
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.tls: "true"
  labels:
    k8s-app: whoami
  name: whoami-ingress
  namespace: whoami
spec:
  rules:
  - host: whoami.yosokugames.dev
    http:
      paths:
      - backend:
          serviceName: whoami-service
          servicePort: 80
        path: /
  tls:
  - secretName: whoami-star-yosokugames-dev-9t56kbf552

jappievw avatar Feb 02 '21 20:02 jappievw

also want to have the feature of wildcard selectors maybe if there exists conflicts, just respect the order of declaration? 🤔

in my case, would like to group istio related resources (e.g. virtualservice, authorizationpolicy, telemetry) to frontend, backend, etc. and also configmap generated from kustomize

yckbilly1929 avatar Jan 21 '23 12:01 yckbilly1929