Helm "appVersion:"

Hello;
I couldn’t have found a proper solution yet and needed to consult your advises.

I deploy Helm charts to Kubernetes.

Here how it works:
TeamCity packs the chart (tar.gz) and pushes to Octopus built-in repo. During the deployment Release Manager guy selects the chart release and referenced Docker image. Octopus deploys helm chart (tar.gz file).
Things work.

As you know Helm has a “chart.yaml” file which includes “appVersion” parameter which is used to define Docker image release version. helm command doesn’t has a parameter to set “appVersion” during the installation. I am not able to assign a hard-coded release there because during Octopus deployment it is assigned dynamically depending on what we select from “Docker image reference” in Octopus.

I leave appVersion empty in Chart.yaml but after the installation we are not able know which app version was set during the installation:

Here is the question:
How can I assign a value to appVersion: in Chart.yaml during the Octopus deployment?

Thanks & Regards

Hi @tirelibirefe

Thanks for getting in touch with Octopus and your question!

Firstly, I’ll be transparent and say that Helm and Kubernetes is not my strong point.

However, from what I understand of Helm, trying to modify the appVersion is somewhat controversial.
One of the main benefits of a chart having a version is that it deploys a particular version of the app. This allows the .tgz to be immutable.

When the chart is deployed to a Kubernetes cluster, a range of things rely on knowing what the chart version did, which is only possible if Helm knows exactly what is in it, and a specific version and appVersion contribute to that aim.

As such, I don’t believe there is a way to update the chart’s appVersion using any of the built-in features, as it goes against the original design of the Upgrade a Helm chart built-in step.

I hope that helps, but please let me know if you have any further questions!

Best,

Hello @mark.harrison
Thanks for explanation.
I know mutable/immutable config mgmt approach. My recommendation looks like “a basic DevOps law violation”.

Although appVersion: value is empty, Helm lets the chart works. It looks like Helm streched out the rule bit. :slightly_smiling_face:

Hi @tirelibirefe

Sometimes you need to be pragmatic about these things. Not all processes fit nicely into the boxes provided by software!

With that in mind, something that might work is the use of the custom deployment script option in the Upgrade a Helm chart step:

Enable the option:

Then in the pre-deployment step:

You could try and perform a string replace on the Chart.yaml with a script, something like this:

$appVersion = "2021.4"
$CurrentDir = Get-Location
$Items = @(Get-ChildItem -Path $CurrentDir -Include "Chart.yaml" -Recurse)
if ($Items.Length -gt 0) {
    foreach ($item in $Items) {
        $FileLines = Get-Content -Path $Item
        for (($i = 0); $i -lt $FileLines.Length; $i++) {
            $Line = $FileLines[$i]
            if ($Line -ieq "appVersion: ") {
                $FileLines[$i] = "appVersion: $($appVersion)"
            }
        }
        Set-Content -Path $item -Value $FileLines
    }
}

You’d want to set the $appVersion variable value to the docker image version - this should be available as a system variable if you’re using the standard Octopus release/deployment and selecting it as a “package”.

Also, consider the script does a recursive search for files matching Chart.yaml, so if you have multiple Chart files, it will also potentially run against them too.

I wasn’t able to test the script as my Kubernetes cluster isn’t working right now.

Even so, I hope this helps.

Best,

Hello @mark.harrison
Thanks for your advise and script but Helm Chart is a tar.gz package.
Unpacking the package, assigning there the value then re-packing the chart…

Wish it possible to assign there the value after the tar.gz is unpacked by Octopus and before it’s deployed by Octopus…

Ah yes, of course! In the words of Homer Simpson, doh!