Adding toleration to FluxCD bootstrap

192 Views Asked by At

I am trying to add some tolerations for the FluxCD pod, but could not understand the syntax for tolerations

here is how i was trying

flux bootstrap github \
  --toleration-keys='name=dedicated,value=Group' \
  --components-extra=image-reflector-controller,image-automation-controller \
  --owner=mak \
  --repository=mu \
  --path=yo \
  --branch=main \
  --version=v2.0.1 \
  --token-auth

here is my other helm chart toleration that work for reference

tolerations:
  - key: dedicated
    operator: "Equal"
    effect: "NoSchedule"
    value: Group

what tried added above error

✗ Deployment/flux-system/helm-controller dry-run failed, reason: Invalid: Deployment.apps "helm-controller" is invalid: [spec.template.spec.tolerations[0].key: Invalid value: "name=dedicated": name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName',  or 'my.name',  or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]'), spec.template.spec.tolerations[1].key: Invalid value: "value=Group": name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName',  or 'my.name',  or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]')]
1

There are 1 best solutions below

1
Guilherme Pellizzetti On

You didn't show how you tried to add the toleration to the Flux controllers, but your reference seems correct to me.

Flux controllers can be customized during bootstrap using Kustomize strategic merge patches and JSON patches.

First, create the file structure required by bootstrap, based on your command, it would look like this

BOOTSTRAP_PATH=mu/yo/flux-system
mkdir -p "$BOOTSTRAP_PATH"
touch "$BOOTSTRAP_PATH/gotk-components.yaml" \
  "BOOTSTRAP_PATH/gotk-sync.yaml" \
  "$BOOTSTRAP_PATH/kustomization.yaml" \
  "$BOOTSTRAP_PATH/toleration-patch.yaml"

Now, modify the patch file to add the toleration that will be added to Flux controllers.

// toleration-patch.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/part-of: flux
spec:
  template:
    spec:
      tolerations:
        - key: dedicated
          operator: Equal
          effect: NoSchedule
          value: Group

After creating the patch file, let's add it to the Kustomization file.

// kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - gotk-sync.yaml
  - gotk-components.yaml
patches:
  - patch: toleration-patch.yaml
    target:
      kind: Deployment
      labelSelector: "app.kubernetes.io/part-of=flux"

This will apply the patch to all controllers, because we're targeting all Deployment objects that have the "app.kubernetes.io/part-of=flux" label.

Push the changes

git add -A && git commit -m "init flux" && git push

Run the bootstrap command.

flux bootstrap github \
  --toleration-keys='name=dedicated,value=Group' \
  --components-extra=image-reflector-controller,image-automation-controller \
  --owner=mak \
  --repository=mu \
  --path=yo \
  --branch=main \
  --version=v2.0.1 \
  --token-auth

That's it, before applying the components, the toleration will be add to the controllers.