postBuild.substitute doesn't work in Flux CD
#5454
-
|
Hi, I have following files on my public repo https://github.com/Cloufish/k8s-home-ops/tree/main/apps/base/code-server: /app/release.yml ---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: &name ${appName}
spec:
interval: 5m
chart:
spec:
chart: *name
sourceRef:
kind: HelmRepository
name: bjw-s-charts
namespace: flux-system
valuesFiles:
- values.yml
interval: 1m
---
apiVersion: v1
kind: Namespace
metadata:
name: &name ${appName}
labels:
name: *nameks.yml ---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: &appname code-server # Change this
namespace: flux-system
spec:
targetNamespace: *appname
commonMetadata:
labels:
app.kubernetes.io/name: *appname
interval: 30m
timeout: 5m
prune: true
path: "./kubernetes/apps/programming/code-server/app" # Change this
sourceRef:
kind: GitRepository
name: flux-system
namespace: flux-system
wait: true
postBuild:
substitute:
app_k8s_domain_name: k8s.cloufish.xyz
default_k8s_cert_name: wildcard-k8s-cert-prod
appName: *appnameEven though it is a very simple setup, the Flux doesn't resolve the variables $ flux get kustomizations --watch
NAME REVISION SUSPENDED READY MESSAGE
flux-system main@sha1:5967c7a5 False Unknown Reconciliation in progress
flux-system main@sha1:5967c7a5 False Unknown Reconciliation in progress
flux-system main@sha1:5967c7a5 False False Namespace/${appName} dry-run failed (Invalid): Namespace "${appName}" is invalid: [metadata.name: Invalid value: "${appName}": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?'), metadata.labels: Invalid value: "${appName}": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')]
✗ timed out waiting for the conditionIt doesn't make any sense to me why it's not substituting. spec:
targetNamespace: *appname
commonMetadata:
labels:
app.kubernetes.io/name: *appname
kustomize.toolkit.fluxcd.io/substitute: enabledThe plan is simple
When I execute |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
|
Get rid of anchors from all these manifests and it should work. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your response @stefanprodan !!! Unfortunately previously I already tried this. I tried this now and didn't work ks.yml ---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: ${appName}
spec:
interval: 5m
chart:
spec:
chart: ${appName}
sourceRef:
kind: HelmRepository
name: bjw-s-charts
namespace: flux-system
valuesFiles:
- values.yml
interval: 1m
---
apiVersion: v1
kind: Namespace
metadata:
name: ${appName}
labels:
name: ${appName} |
Beta Was this translation helpful? Give feedback.
-
|
Okay I will use the template in https://github.com/fluxcd/flux2-kustomize-helm-example https://github.com/fluxcd/flux2-kustomize-helm-example When I'm done and It will I will let you know :) |
Beta Was this translation helpful? Give feedback.
-
Could you give a hint @stefanprodan where to place Flux Kustomization with I've deployed it using your template and it didn't fix the problem In your https://github.com/fluxcd/flux2-kustomize-helm-example template I see you are declaring Kustomizations in In ---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: apps
namespace: flux-system
spec:
interval: 10m0s
dependsOn:
- name: infra-configs
sourceRef:
kind: GitRepository
name: flux-system
path: ./apps/production # <---
prune: true
wait: true
timeout: 5m0s
Does that mean that in ---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./APP1/ks.yaml
- ./APP2/ks.yaml
- ./APP3/ks.yaml
- [...] |
Beta Was this translation helpful? Give feedback.
There are many way to do it, this example is a for a simple setup where all apps are applied by a single Flux Kustomization. If you follow this example, then the substitutions must go into
clusters/production/apps.yamlfor all apps.Check out the D2 example repos for a complex setup where substitutions are used https://github.com/controlplaneio-fluxcd/d2-fleet