Skip to content

As a user I'd like to be able to navigate from selector labels/expressions to matching labels #642

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

Closed
adietish opened this issue Jul 24, 2023 · 5 comments · Fixed by #858

Comments

@adietish
Copy link
Collaborator

adietish commented Jul 24, 2023

When editing k8 resources, it is cumbersome to make sure that your selector label/expression is really matching existing labels on templates/pods. Furthermore as a user I'd like to have an easy way to jump from the referee to the referencing component and vice-versa.
The jetbrains plugin displays clickable markers to labels (on the left ruler) but it doesnt work for me/I'm unsure how this works).
I'd like to implement those as clickable InlayHint.

ex. in the following multi-resource file that was generated by quarkus, there's a service that's referencing a pod (Service->Deployment, Ingress->Service)

---
apiVersion: v1
kind: Service
metadata:
  annotations:
    app.quarkus.io/build-timestamp: 2023-07-14 - 15:53:39 +0000
  labels:
    app.kubernetes.io/name: openshift-quickstart
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
    app.kubernetes.io/managed-by: quarkus
  name: openshift-quickstart
spec:
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 8080
    - name: https
      port: 443
      protocol: TCP
      targetPort: 8443
  selector:
    app.kubernetes.io/name: openshift-quickstart
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
  type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    app.quarkus.io/build-timestamp: 2023-07-14 - 15:53:39 +0000
  labels:
    app.kubernetes.io/managed-by: quarkus
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
    app.kubernetes.io/name: openshift-quickstart
  name: openshift-quickstart
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/version: 1.0.0-SNAPSHOT
      app.kubernetes.io/name: openshift-quickstart
  template:
    metadata:
      annotations:
        app.quarkus.io/build-timestamp: 2023-07-14 - 15:53:39 +0000
      labels:
        app.kubernetes.io/managed-by: quarkus
        app.kubernetes.io/version: 1.0.0-SNAPSHOT
        app.kubernetes.io/name: openshift-quickstart
    spec:
      containers:
        - env:
            - name: KUBERNETES_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          image: adietish/openshift-quickstart:1.0.0-SNAPSHOT
          imagePullPolicy: Always
          name: openshift-quickstart
          ports:
            - containerPort: 8080
              name: http
              protocol: TCP
            - containerPort: 8443
              name: https
              protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    app.quarkus.io/build-timestamp: 2023-07-14 - 15:53:39 +0000
  labels:
    app.kubernetes.io/name: openshift-quickstart
    app.kubernetes.io/version: 1.0.0-SNAPSHOT
    app.kubernetes.io/managed-by: quarkus
  name: openshift-quickstart
spec:
  rules:
    - http:
        paths:
          - backend:
              service:
                name: openshift-quickstart
                port:
                  name: http
            path: /
            pathType: Prefix
@adietish adietish self-assigned this Dec 11, 2024
@adietish adietish moved this to 📋 Backlog in IDE Cloudaptors Dec 11, 2024
@adietish
Copy link
Collaborator Author

adietish commented Dec 11, 2024

An idea would be to have Ctrl + click scroll to the portion in the editor that is matching. Lookup on the cluster could also be provided.
We could also highlight matching resources like we know it from properties in java class.

Jetbrains kubernetes plugin has no such support afaik.

@adietish adietish added the editor label Feb 7, 2025
@adietish adietish changed the title As a user I'd like to see the references within a multi-doc file As a user I'd like help with references in a multi-doc file Feb 26, 2025
@adietish
Copy link
Collaborator Author

adietish commented Mar 5, 2025

In a 2nd step, we could look up matching resources on the cluster

@adietish
Copy link
Collaborator Author

adietish commented Mar 11, 2025

matchLabel and matchExpression in a Deployment target Pods which are most likely defined as a template in the very same resource. You can of course define a pod in a file and create it. Nevertheless the more useful usecase is a lookup of references that exist on the cluster. This is true for most resources that can target pods like Service, DaemonSet, StatefulSet, Service, ReplicaSet, Job, CronJob, NetworkPolicies , PodDisruptionBudgets, ReplicationController, HorizontalPodAutoscaler. Similar but not identical are PersistentVolumeClaims which target PersistentVolumes.

Image

Here's an example of PVC and PV:

# --------------------------
# PersistentVolume 1 (targeted by PVC with matchLabels)
# --------------------------
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-labels
  labels:
    pvc-target: labels          # Label for direct matching
    storage-tier: ssd           # Additional label (not required for binding)
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  storageClassName: manual       # Disables dynamic provisioning
  hostPath:
    path: /mnt/data-labels

---
# --------------------------
# PersistentVolume 2 (targeted by PVC with matchExpressions)
# --------------------------
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-expressions
  labels:
    environment: production      # Label for matchExpressions
    region: us-west              # Label for matchExpressions (key existence)
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  storageClassName: manual       # Disables dynamic provisioning
  hostPath:
    path: /mnt/data-expressions

---
# --------------------------
# PVC 1: Uses matchLabels
# --------------------------
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-labels
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  selector:
    matchLabels:
      pvc-target: labels         # Direct label match

---
# --------------------------
# PVC 2: Uses matchExpressions
# --------------------------
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-expressions
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  selector:
    matchExpressions:
      - key: environment
        operator: In             # Value must be in the list
        values: [production, staging]
      - key: region
        operator: Exists         # Key must exist (value ignored)

@adietish
Copy link
Collaborator Author

We can offer a 2nd label that reports references to pods running on the cluster X references on cluster.

@adietish
Copy link
Collaborator Author

adietish commented Mar 13, 2025

Jetbrains kubernetes plugin provides similar functionality using icons in the gutter.

Image

If you click the gutter icon you'll get scrolled to the occurrence

Image

I discussed this with @angelozerr and we both agreed that a hint is better because it is matching the usual behaviour for references better. And then, gutter icons can come handy if you have multiple actions (ex. a run gutter icon where you can have mutliple entries for running, debugging, coverage run, etc.). For the references there's only 1 action: list the matching resources or click right to it if there's only 1.

adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 17, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 18, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 19, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 22, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 22, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 24, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 24, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 24, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 24, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 24, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 24, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 24, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 24, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 25, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 25, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Mar 25, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 9, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 9, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 9, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 9, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 9, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 10, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 10, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 11, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 11, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 11, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 11, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 11, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 11, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 12, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 14, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 14, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 14, 2025
@adietish adietish moved this from 📝 In Progress to 👀 In review in IDE Cloudaptors Apr 16, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 25, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 27, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 27, 2025
adietish added a commit to adietish/intellij-kubernetes that referenced this issue Apr 28, 2025
adietish added a commit that referenced this issue May 13, 2025
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in IDE Cloudaptors May 13, 2025
@adietish adietish changed the title As a user I'd like help with references in a multi-doc file As a user I'd like to be able to navigate from selector labels/expressions to matching labels May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
1 participant