Skip to content

Instantly share code, notes, and snippets.

@scottrigby
Last active January 14, 2021 06:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottrigby/c2f34d2557113a1681acfc1fac969305 to your computer and use it in GitHub Desktop.
Save scottrigby/c2f34d2557113a1681acfc1fac969305 to your computer and use it in GitHub Desktop.
Demo: Flux Helm Operator -> Controller Migration

Demo: Flux Helm Operator -> Controller Migration

  1. Create local cluster

    kind create cluster
  2. Barebones flux2 install for demo

    flux install --components source-controller,helm-controller --export | kubectl apply -f -
  3. Install Operator

    See https://docs.fluxcd.io/projects/helm-operator/en/stable/get-started/using-yamls/#install-the-helm-operator

    kubectl apply -f https://raw.githubusercontent.com/fluxcd/helm-operator/1.2.0/deploy/crds.yaml
    kubectl create namespace flux
    kubectl apply -f https://raw.githubusercontent.com/fluxcd/helm-operator/1.2.0/deploy/rbac.yaml
    kubectl apply -f https://raw.githubusercontent.com/fluxcd/helm-operator/1.2.0/deploy/deployment.yaml
    kubectl patch -f https://raw.githubusercontent.com/fluxcd/helm-operator/1.2.0/deploy/deployment.yaml \
      --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value":"--enabled-helm-versions=v3"}]'
  4. Install v1 Operator CR

    $ echo 'apiVersion: helm.fluxcd.io/v1
    kind: HelmRelease
    metadata:
      name: podinfo
      namespace: default
    spec:
      chart:
        repository: https://stefanprodan.github.io/podinfo
        name: podinfo
        version: 5.0.3
      rollback:
        enable: true
        retries: true
        maxRetries: 5
      values:
        replicaCount: 1' | k apply -f -
  5. See the v1 Operator CR

    $ k get helmreleases.helm.fluxcd.io
    NAME      RELEASE           PHASE       STATUS     MESSAGE                                                                   AGE
    podinfo   default-podinfo   Succeeded   deployed   Release was successful for Helm release 'default-podinfo' in 'default'.   2m1s
  6. See the release

    $ helm ls
    NAME           	NAMESPACE	REVISION	UPDATED                              	STATUS  	CHART        	APP VERSION
    default-podinfo	default  	1       	2020-11-13 13:35:27.5339046 +0000 UTC	deployed	podinfo-5.0.3	5.0.3
  7. Scale down helm operator, so it stops syncing from v1 CRD

    k -n flux scale deployment/helm-operator --replicas=0
  8. Apply v2 helm repository

    echo 'apiVersion: source.toolkit.fluxcd.io/v1beta1
    kind: HelmRepository
    metadata:
      name: podinfo
      namespace: default
    spec:
      interval: 10m
      url: https://stefanprodan.github.io/podinfo' | k apply -f -
  9. Describe helm repository to show it fetched the index:

    k describe helmrepositories.source.toolkit.fluxcd.io
  10. Apply v2 Controller CR

    Note we set "releaseName: default-podinfo" to match operator namespace prefixing.

    echo 'apiVersion: helm.toolkit.fluxcd.io/v2beta1
    kind: HelmRelease
    metadata:
      name: podinfo
      namespace: default
    spec:
      interval: 5m
      releaseName: default-podinfo
      chart:
        spec:
          chart: podinfo
          version: 5.0.3
          sourceRef:
            kind: HelmRepository
            name: podinfo
      install:
        remediation:
          retries: 3
      upgrade:
        remediation:
          retries: 5
      values:
        replicaCount: 1' | k apply -f -

    * In future we will have conversion hooks for new CRD versions

  11. See the v2 Controller CR

    $ k get helmreleases.helm.toolkit.fluxcd.io
    NAME      READY   STATUS                             AGE
    podinfo   True    release reconciliation succeeded   6s
  12. See there are now 2 helm release revisions

    $ helm ls
    NAME           	NAMESPACE	REVISION	UPDATED                              	STATUS  	CHART        	APP VERSION
    default-podinfo	default  	2       	2020-11-13 13:41:37.7153917 +0000 UTC	deployed	podinfo-5.0.3	5.0.3 
  13. Show reconciling

    $ helm uninstall default-podinfo
    release "default-podinfo" uninstalled
    
    $ helm ls
    NAME	NAMESPACE	REVISION	UPDATED	STATUS	CHART	APP VERSION
    
    $ flux reconcile helmrelease podinfo -n default
    ► annotating HelmRelease podinfo in default namespace
    ✔ HelmRelease annotated
    ◎ waiting for HelmRelease reconciliation
    ✔ HelmRelease reconciliation completed
    ✔ reconciled revision 5.0.3
    
    $ helm ls
    NAME           	NAMESPACE	REVISION	UPDATED                              	STATUS  	CHART        	APP VERSION
    default-podinfo	default  	1       	2020-11-13 13:44:29.4932623 +0000 UTC	deployed	podinfo-5.0.3	5.0.3

    Reconciled!

  14. Cleanup v1 Operator release CR

    Finally delete the old operator CRD

    k delete helmreleases.helm.fluxcd.io podinfo

    * Repeat for each v1 release, one by one.

  15. Uninstall v1 Operator, CRDs, and v1 namespace

    Once all v1 releases have been migrated to v2, you may uninstall the v1 Operator. Note deleting the v1 CRDs removes any v1 CRs, so this should not be done until all releases have been migrated to v2.

    kubectl delete -f https://raw.githubusercontent.com/fluxcd/helm-operator/1.2.0/deploy/deployment.yaml
    kubectl delete -f https://raw.githubusercontent.com/fluxcd/helm-operator/1.2.0/deploy/rbac.yaml
    kubectl delete -f https://raw.githubusercontent.com/fluxcd/helm-operator/1.2.0/deploy/crds.yaml
    kubectl delete namespace flux
  16. Cleanup demo cluster

    kind delete cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment