Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

Automatic upgrade of helm chart files to version 3

I have a ton of helm files, with the structure aligned to comply with Helm2, i.e. a separate requirements.yaml file and no type:application in Chart.yaml

Is there an option in helm-2to3 plugin that automagically places the requirements.yaml under Chart.yaml or do I have to write myself a script to do this?

My charts are checked-in to GH btw (not using a helm repo but operating them via GitOps)

edit: After confirmation in answers below that helm-2to3 does not provide that functionality, I ended up using the draft script below (warning: do not use it in production :) ); you can then proceed by a simple find/xargs oneliner to remove all requirements.yaml (or give them an extension of .bak to keep around for some time).

the chart should of course be run from the root directory of the project where your helm files are kept.

import os
import time


for root, dirs, files in os.walk(os.path.abspath(".")):
    for file in files:
        if file == "requirements.yaml":
            path = os.path.dirname(os.path.join(root, file))
            print(path)
            os.chdir(path)
            files = [f for f in os.listdir('.') if os.path.isfile(f)]
            # print(files)
            if "requirements.yaml" in files and "Chart.yaml" in files:
                requirements_path = os.path.join(root, file)
                print("Doing job in..: ", requirements_path)
                chart_path = path + "/Chart.yaml"
                print(chart_path)
                with open(requirements_path) as req:
                    r = req.read()
                with open(chart_path, 'a') as chr:
                    chr.write(r)
                time.sleep(2)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have a ton of helm template files, with the structure aligned to comply with Helm2, i.e. a separate requirements.yaml file and no type:application in Chart.yaml

The template files, within the helm chart, should work the same way under Helm 3. It's the Chart.yaml file, in each chart that will need to be edited. Unfortunately the helm-2to3 plugin won't do that for you. It's primarily designed to fix the Kubernetes cluster where you might have previously installed helm charts.

Helm3 is capable of installing older helm charts, so I suggest updating each helm chart one at a time.

To conclude, we're using GitOps too. Happily ArgoCD supports both Helm 2 + Helm 3 charts and only uses Helm to generate YAML. This means there is no Helm configuration on the cluster that requires updating. (Miles has a link in his answer, if you're alternatively using FluxCD)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...