rancher / dashboard

The Rancher UI
https://rancher.com
Apache License 2.0
440 stars 242 forks source link

[BUG] UI - additionalPrinterColumns values empty when fields have periods or slashes in them #10777

Open ekristen opened 3 months ago

ekristen commented 3 months ago

Rancher Server Setup

Information about the Cluster

Describe the bug The UI will not render the values of labels and annotations from the metadata block when periods or slashes are involved leaving to missing fields in the rancher UI especially when it comes to CRDs.

To Reproduce Install any CRD that has additionalPrinterColumns that reference .metadata.labels or annotations with an annotation for example that has a period or slash in it.

  - additionalPrinterColumns:
    - jsonPath: .metadata.labels.node\.kubernetes\.io/instance-type
      name: Type
      type: string
    - jsonPath: .metadata.labels.topology\.kubernetes\.io/zone
      name: Zone
      type: string
    - jsonPath: .status.nodeName
      name: Node
      type: string
    - jsonPath: .status.conditions[?(@.type=="Ready")].status
      name: Ready
      type: string
    - jsonPath: .metadata.creationTimestamp
      name: Age
      type: date
    - jsonPath: .metadata.labels.karpenter\.sh/capacity-type
      name: Capacity
      priority: 1
      type: string
    - jsonPath: .metadata.labels.karpenter\.sh/provisioner-name
      name: Provisioner
      priority: 1
      type: string
    - jsonPath: .spec.machineTemplateRef.name
      name: Template
      priority: 1
      type: string

Result

Empty fields in the UI.

Expected Result

The fields to be populated with the correct values.

Screenshots Screenshot 2024-04-05 at 8 52 27 AM

Additional context

My guess it has to do with the escaping of the special characters that's breaking the UI from rendering them properly.

rak-phillip commented 3 months ago

@ekristen thanks for raising this issue and helping to make Rancher better! I'm transferring this issue to the Rancher Dashboard repository for additional triage. Our team may reach out to you to gather more information as we work to reproduce.

richard-cox commented 3 months ago

CRD additionalPrinterColumns are converted into Rancher schema attributes.columns. In the UI for tables without a custom list component we show those as columns.

Given the examples in description, and some examples that exercise other json path syntax, we need to confirm what happens to those attributes.columns values (are they correct / valid) and then how we fetch the cell value given the string (i think we already do some magic to convert $.metadata.field kind of thing).

I've brought this in to 2.9.0 as we'll be making a lot more use of these in the near future

richard-cox commented 3 months ago

See shell/store/type-map.utils.ts rowValueGetter, that's the first breadcrumb. I was wrong through and the actual part that gets the value is ...

get is very vanilla

  if ( !path.includes('.') ) {
    return obj?.[path];
  }

  const parts = splitObjectPath(path);

  for (let i = 0; i < parts.length; i++) {
    if (!obj) {
      return;
    }

    obj = obj[parts[i]];
  }

  return obj;

We need to confirm what kind of string the schema is providing and work out how to use it to get the required value from the object

nwmac commented 2 months ago

@richard-cox Is this a must for 2.9.0?