gimlet-io / capacitor

A general purpose UI for FluxCD.
Apache License 2.0
476 stars 13 forks source link

BUG: Uncaught TypeError: Cannot read properties of undefined (reading 'metadata') #61

Closed koolay closed 3 months ago

koolay commented 4 months ago

version 0.2.0

image

Uncaught TypeError: Cannot read properties of undefined (reading 'metadata')

export function findSource(sources, reconciler) {
  let namespace = reconciler.metadata.namespace
  if (reconciler.spec.sourceRef.namespace) { // namespace is not mandatory
    namespace = reconciler.spec.sourceRef.namespace
  }

  return sources.find((source) => source.kind === reconciler.spec.sourceRef.kind &&
    source.metadata.name === reconciler.spec.sourceRef.name &&
    source.metadata.namespace === namespace)
}
laszlocph commented 3 months ago

Can you share what is in your cluster? The reported error is not very likely to occur. A repro case would be amazing.

arcker commented 3 months ago

Hi @laszlocph

i've the same problem, repo is managed by fluxcd and talos

You can find it here https://github.com/arcker/TalosHyperVTest2

kustomization is here https://github.com/arcker/TalosHyperVTest2/blob/main/kubernetes/apps/flux-system/capacitor/kustomization.yaml and source helm repo is here https://github.com/arcker/TalosHyperVTest2/blob/main/kubernetes/flux/repositories/oci/flux-capacitor.yaml

i've captured some notifications problems ( they are fast but manage to capture, don't know if it's related ( dns issues but flux seems to be fine so ... )

image

then blank page and same metadata error in browser logs

laszlocph commented 3 months ago

You can find it here https://github.com/arcker/TalosHyperVTest2

I could not fully install things from this repo. But when I tried to apply yamls from it to a cluster with Flux v2.2.2 it was telling me that it uses old api versions: "kubernetes/flux/repositories/git/kustomization.yaml": no matches for kind "Kustomization" in version "kustomize.config.k8s.io/v1beta1"

This could explain the situation that kustomizations are undefined in the data model. It is kind of the root of the data model we use so I could not see how they can be undefined.

Except I see now that we query for kusomitzations in in the v1 apiVersion: kustomize.toolkit.fluxcd.io/v1 here https://github.com/gimlet-io/capacitor/blob/main/pkg/flux/flux.go#L36

I am not exactly sure when was kustomize.config.k8s.io/v1beta1 deprecated, but it feels rather old. Can you try updating to the latest flux and try capacitor again?

trahim commented 3 months ago

Hi @laszlocph also the same problem, console logs show image The kustomize api version we are using is kustomize.toolkit.fluxcd.io/v1 so should be good with regards to that.

Flux version is v2.0.1

arcker commented 3 months ago

thx @laszlocph for looking I've tried few things ( took my morning ) but nothing It seems to be around services not getting kustomization attributes my cluster doesn't seem to have issues ( i've removed problematic helmreleases )

here are the output

TalosHyperVTest2 on  main via 🐍 v3.11.6 (.venv) ⬢ [Docker] ❯ kubent 1:13PM INF >>> Kube No Trouble kubent <<< 1:13PM INF version 0.7.1 (git sha 1ed4bfb4bd271f88731d245131edec931956cf74) 1:13PM INF Initializing collectors and retrieving data 1:13PM INF Target K8s version is 1.29.2 1:13PM INF Retrieved 0 resources from collector name=Cluster 1:13PM INF Retrieved 35 resources from collector name="Helm v3" 1:13PM INF Loaded ruleset name=custom.rego.tmpl 1:13PM INF Loaded ruleset name=deprecated-1-16.rego 1:13PM INF Loaded ruleset name=deprecated-1-22.rego 1:13PM INF Loaded ruleset name=deprecated-1-25.rego 1:13PM INF Loaded ruleset name=deprecated-1-26.rego 1:13PM INF Loaded ruleset name=deprecated-1-27.rego 1:13PM INF Loaded ruleset name=deprecated-1-29.rego 1:13PM INF Loaded ruleset name=deprecated-future.rego

TalosHyperVTest2 on  main via 🐍 v3.11.6 (.venv) took 6s ⬢ [Docker] ❯ kubectl version --client Client Version: v1.29.2 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3

TalosHyperVTest2 on  main via 🐍 v3.11.6 (.venv) ⬢ [Docker] ❯ flux version flux: v2.2.3 distribution: flux-v2.2.3 helm-controller: v0.37.4 image-automation-controller: v0.37.1 image-reflector-controller: v0.31.2 kustomize-controller: v1.2.2 notification-controller: v1.2.4 source-controller: v1.2.4

TalosHyperVTest2 on  main via 🐍 v3.11.6 (.venv)

and for the browser, seems to block when getting cilium helm ( 1.15.1 installed )

image

in capacitor pods, i've this W0307 13:23:15.522316 1 warnings.go:70] v2beta1 HelmRelease is deprecated, upgrade to v2beta2 W0307 13:23:16.523396 1 warnings.go:70] v2beta1 HelmRelease is deprecated, upgrade to v2beta2 W0307 13:24:33.504005 1 warnings.go:70] v2beta1 HelmRelease is deprecated, upgrade to v2beta2

but i don't have any helmrelease in v2beta1, don't know if it's related

laszlocph commented 3 months ago

Appreciate all the input.

I was able to reproduce the problem.

If a HelmRelease is not created by a Kustomization, but applied on the cluster with kubectl, this reconciler in question is undefined.

This is a valid usecase, so I am altering the code to handle this better.

laszlocph commented 3 months ago

https://github.com/gimlet-io/capacitor/releases/tag/capacitor-v0.3.2

arcker commented 3 months ago

it works !! image

thx for the fix, amazing tool, will follow it

you can close the issue 💯