Only store Flux resource path without entire CRD reference in the Environments model
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
In the current Environments model we store a flux_resource_path which looks something like this helm.toolkit.fluxcd.io/v2beta1/namespaces/flux-system/helmreleases/gitlab-agent. This has the format of: <api>/<version>/namespace/<namespace>/<resource-type>/<resource-name>.
This is limiting because we don't want to force the user to update the Environment when they update their Flux in the cluster which may come with a new API (version). In the UI this is also coupled with the kubernetes_namespace field. However, this does not always make sense because the user may want to show a specific namespace which is simply the "target namespace" of a Flux resource located in a different namespace.
For example:
- HelmRelease at flux-system/gitlab-agent
- HelmRelease flux-system/gitlab-agenthas a target namespace ofgitlab-agent
Proposal
The CRD (API) discovery should happen in the Dashboard specific code in the frontend which determines the API (version) and the Environments model on the backend (DB) only stores a flux resource path, for example HelmRelease/<name>.<namespace>. That specific format is used in couple of places by Flux itself, like in the flux CLI tool.
This change would require a database migration. To transform the flux_resource_path from <api>/<version>/namespace/<namespace>/<resource-type>/<resource-name> to <HelmRelease if <api> is "helm.toolkit.fluxcd.io" else Kustomization>/<resource-name>.<namespace>.
We also don't strictly need the API discovery just yet to decouple the two fields, but just hardcode the API and version on the frontend.