Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for bumpVersion when updating helm-values #8231

Closed
chgl opened this issue Jan 9, 2021 · 36 comments · Fixed by #8240 or #26441
Closed

Support for bumpVersion when updating helm-values #8231

chgl opened this issue Jan 9, 2021 · 36 comments · Fixed by #8240 or #26441
Labels
manager:helm-values Helm v2 values.yml files priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others type:feature Feature (new functionality)

Comments

@chgl
Copy link
Contributor

chgl commented Jan 9, 2021

What would you like Renovate to be able to do?

When the container image tags in Helm value files are updated using the helm-values manager, it should also support bumping the chart version.

Did you already have any implementation ideas?

I've been attempting this in https://github.com/chgl/renovate/tree/add-bumpversion-support-to-helm-values (Let me know if you'd like a WIP PR). But the main challenge I face is that the helm-values manager works on values.yaml files, but the packageFile containing the version that should be bumped is Chart.yaml. I can work around this by opening and reading the Chart.yaml file and get as far as updating the file contents with a bumped version (https://github.com/chgl/renovate/blob/add-bumpversion-support-to-helm-values/lib/manager/helm-values/update.spec.ts#L38), but now I am not sure how to correctly write back the updated contents without majorly updating getUpdatedPackageFiles (it currently incorrectly overwrites values.yaml with the updated contents of Chart.yaml).

I'm definitely interested in working on this.

@HonkingGoose HonkingGoose added type:feature Feature (new functionality) manager:helm-values Helm v2 values.yml files priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others labels Jan 9, 2021
@rarkins
Copy link
Collaborator

rarkins commented Jan 10, 2021

I refactored the return signature for bumpPackageVersion so that it's an object. I think it's possible that you could now add bumpedFileName to that object for your purposes - what do you think?

@chgl
Copy link
Contributor Author

chgl commented Jan 10, 2021

@rarkins Perfect, thank you for your help! I've implemented something in #8240.

@rarkins rarkins added status:requirements Full requirements are not yet known, so implementation should not be started status:in-progress Someone is working on implementation and removed status:requirements Full requirements are not yet known, so implementation should not be started labels Jan 12, 2021
@renovate-release
Copy link
Collaborator

🎉 This issue has been resolved in version 24.67.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@viceice
Copy link
Member

viceice commented Mar 7, 2021

We need a new pr for this, as the previous caused a bug and had been reverted, see #8926 and #8919

@jmmaloney4
Copy link

Any idea when this will be done? This would be a really useful feature for anyone hosting their own helm chart repository (like myself). Thanks!

@chgl
Copy link
Contributor Author

chgl commented Jul 24, 2021

I hope to get to it eventually, since I do need it myself as well ;). But of course I'd gladly yield the implementation to anyone interested - while there is clearly a bug left to squash, https://github.com/renovatebot/renovate/pull/8240/files may at least be a starting point.

@andywow
Copy link

andywow commented Jul 25, 2021

I made workaround with this (bump patch version):

  "postUpgradeTasks": {
    "commands": [
      "sed -i \"s/^version:.*/version: $(grep '^version:' Chart.yaml | awk '{print $2}' | awk -F '[.\"]' '{$NF = $NF + 1;} 1' | sed 's/ /./g')/\" Chart.yaml",
    ],
    "fileFilters": ["Chart.yaml"],
    "executionMode": "branch"
  },

@ap-vishal
Copy link

Hello, it would be awesome if we get this working, we use flux together with renovate bot and this is the only missing piece for us.

@asergeant01
Copy link

I'm struggling to understand the status of this feature.... if i follow the tickets my understanding is it was committed, merged and released, but there was a bug so it was rolled back? What needs done to implement this - perhaps i can contribute?

@viceice viceice added status:ready and removed status:in-progress Someone is working on implementation labels Sep 7, 2022
@viceice
Copy link
Member

viceice commented Sep 7, 2022

Needs a new PR with a fix for #8919

christianhuth added a commit to christianhuth/helm-charts that referenced this issue Nov 28, 2022
add workaround from renovatebot/renovate#8231 to bump version in Chart.yaml, when image tag gets updated
@alekc
Copy link

alekc commented Mar 18, 2023

"packageRules": [
  {
    "matchManagers": [
      "helm-requirements",
      "helm-values",
    ],
    "postUpgradeTasks": {
      "commands": [
        `version=$(grep '^version:' {{{parentDir}}}/Chart.yaml | awk '{print $2}')
        major=$(echo $version | cut -d. -f1)
        minor=$(echo $version | cut -d. -f2)
        patch=$(echo $version | cut -d. -f3)
        minor=$(expr $minor + 1)
        echo "Replacing $version with $major.$minor.$patch"
        sed -i "s/^version:.*/version: $\{major\}.$\{minor\}.$\{patch\}/g" {{{parentDir}}}/Chart.yaml
        cat {{{parentDir}}}/Chart.yaml
        `
      ],
      "fileFilters": [
        "**/Chart.yaml",
      ],
      "executionMode": "branch",
    },
  },
]

@justinas-b is it still working with latest versions? For some reason parentDir is not being resolved for me (thus command fails with grep: /Chart.yaml: No such file or directory

module.exports = {
    extends: ['config:base'],
    allowPostUpgradeCommandTemplating: true,
    allowedPostUpgradeCommands: ['^.*'],
    regexManagers: [
        {
            fileMatch: ['(^|/)Chart\\.yaml$'],
            matchStrings: [
                '#\\s?renovate: image=(?<depName>.*?)\\s?appVersion:\\s?\\"?(?<currentValue>[\\w+\\.\\-]*)',
            ],
            datasourceTemplate: 'docker',
        },
    ],
    packageRules: [
        {
            matchManagers: ['helm-requirements', 'helm-values', 'regex'],
            postUpgradeTasks: {
                commands: [
                  `version=$(grep '^version:' {{{parentDir}}}/Chart.yaml | awk '{print $2}')
                  major=$(echo $version | cut -d. -f1)
                  minor=$(echo $version | cut -d. -f2)
                  patch=$(echo $version | cut -d. -f3)
                  minor=$(expr $minor + 1)
                  echo "Replacing $version with $major.$minor.$patch"
                  sed -i "s/^version:.*/version: $\{major\}.$\{minor\}.$\{patch\}/g" {{{parentDir}}}/Chart.yaml
                  cat {{{parentDir}}}/Chart.yaml
                  `,
                ],
            },
            fileFilters: ['**/Chart.yaml'],
            executionMode: 'branch',
        },
    ],
};

@justinas-b
Copy link
Contributor

I am currently on "renovateVersion": "35.14.3", and it still works. We are using mono-repo for all helm charts, meaning that every helm chart is in dedicated folder. Do you have same structure?

@alekc
Copy link

alekc commented Mar 21, 2023

Hmm, turns out I was not on the latest one (35.10.x). After upgrade it looks like it works as expected, thx

@legonigel
Copy link

I'm going to try to revive the reverted PR, but no promises. JS isn't something I usually work with, so will take me some time.

@marthydavid

This comment was marked as spam.

@renovate-release
Copy link
Collaborator

🎉 This issue has been resolved in version 37.138.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Crapworks
Copy link

Hey! So I pulled the new release in and set "bumpVersion": "minor" in my renvate.json, hoping that it would just work and bump the version in Chart.yaml whenever it updates the values.yaml. But the behavior is the same as before, it only updates the values.yaml. From the discussion here and the PR it is not clear to me how this is supposed to work. Do I need to setup / configure something else to make this work?

@rarkins
Copy link
Collaborator

rarkins commented Jan 18, 2024

@Crapworks please start a non-closed issue or discussion. I'm not sure if this was intended to update both or only values

@renovatebot renovatebot locked as resolved and limited conversation to collaborators Jan 18, 2024
@rarkins rarkins reopened this Jan 20, 2024
@renovatebot renovatebot unlocked this conversation Jan 20, 2024
@morremeyer
Copy link
Contributor

morremeyer commented Feb 28, 2024

Quick note for everyone wondering why this is not working since #26441 has been merged: #26441 was reverted with #26758 since it did not work as intended.

Edit: Found the revert PR and updated comment with it.

@jkroepke
Copy link
Contributor

jkroepke commented Feb 28, 2024

I have some hope for #27602 - maybe we could use regex magic to trigger version bump. this also would include versionBump, if there is a change inside the Chart.yaml (e.g. appVersion has been changed)

Note sure, but a vote can help on the discussion.

@morremeyer
Copy link
Contributor

We have taken the workaround shown by @justinas-b and built on top of it. Main changes are:

  • it's now in a separate file to allow for linting and keep the renovate.json a valid json file
  • it bumps the chart version depending on the version bump of the dependency

ℹ️ This only bumps for major, minor and patch upgrades. digests, pins, rollbacks, replacements and pinDigest updates are deliberately ignored since in our use case, these need a manual decision about the version bump for the chart

Setup

  • put the script below in scripts/bump-chart-version.sh
  • your chart directories need to be in the charts/ directory

Script

Script
#!/usr/bin/env bash

set -euo pipefail

parent_dir="$1"
is_major="$2"
is_minor="$3"
is_patch="$4"

version=$(grep "^version:" "charts/${parent_dir}/Chart.yaml" | awk '{print $2}')
if [[ ! $version ]]; then
  echo "No valid version was found"
  exit 1
fi

major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
patch=$(echo "$version" | cut -d. -f3)

# Bump major version
if [[ "$is_major" = 'true' ]]; then
  major=$(( major + 1 ))
  minor=0
  patch=0
fi

# Bump minor version
if [[ "$is_minor" = 'true' ]]; then
  minor=$(( minor + 1 ))
  patch=0
fi

# Bump patch version
if [[ "$is_patch" = 'true' ]]; then
  patch=$(( patch + 1 ))
fi

echo "Bumping version for $parent_dir from $version to $major.$minor.$patch"
sed -i "s/^version:.*/version: ${major}.${minor}.${patch}/g" "charts/${parent_dir}/Chart.yaml"

renovate config

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "packageRules": [
    {
      "description": "Bump helm chart versions by a patch when updating values files. Digests, pins, rollbacks, replacements and pinDigest updates are deliberately ignored since in our use case, these need a manual decision about the version bump for the chart. This can be removed when https://github.com/renovatebot/renovate/issues/8231 is implemented and enabled.",
      "matchManagers": ["helm-values"],
      "postUpgradeTasks": {
        "commands": [
          "bash scripts/bump-chart-version.sh '{{{parentDir}}}' '{{{isMajor}}}' '{{{isMinor}}}' '{{{isPatch}}}'"
        ],
        "fileFilters": ["**/Chart.yaml"],
        "executionMode": "branch"
      }
    }
  ]
}

@Rajesh-Gurjar
Copy link

Hi @morremeyer will this fucntionality be added to renovate or we'll have to via the script version?

@morremeyer
Copy link
Contributor

@Rajesh-Gurjar There is still the goal of supporting this directly in renovate, but it has to be implemented.

For now, using the script in my comment works, but only on self-hosted instances

@maxiangelo

This comment has been minimized.

@maxiangelo

This comment has been minimized.

@babuga365
Copy link

We have taken the workaround shown by @justinas-b and built on top of it. Main changes are:

  • it's now in a separate file to allow for linting and keep the renovate.json a valid json file
  • it bumps the chart version depending on the version bump of the dependency

ℹ️ This only bumps for major, minor and patch upgrades. digests, pins, rollbacks, replacements and pinDigest updates are deliberately ignored since in our use case, these need a manual decision about the version bump for the chart

Setup

  • put the script below in scripts/bump-chart-version.sh
  • your chart directories need to be in the charts/ directory

Script

Script

renovate config

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "packageRules": [
    {
      "description": "Bump helm chart versions by a patch when updating values files. Digests, pins, rollbacks, replacements and pinDigest updates are deliberately ignored since in our use case, these need a manual decision about the version bump for the chart. This can be removed when https://github.com/renovatebot/renovate/issues/8231 is implemented and enabled.",
      "matchManagers": ["helm-values"],
      "postUpgradeTasks": {
        "commands": [
          "bash scripts/bump-chart-version.sh '{{{parentDir}}}' '{{{isMajor}}}' '{{{isMinor}}}' '{{{isPatch}}}'"
        ],
        "fileFilters": ["**/Chart.yaml"],
        "executionMode": "branch"
      }
    }
  ]
}

If I have multiple charts in single repository under charts folder, this script is working only on first chart and remaining charts were not updated with new version value in Chart.yaml file..

Do you know how to make it work for other charts as well?

@renovatebot renovatebot locked and limited conversation to collaborators May 6, 2024
@rarkins rarkins converted this issue into discussion #28861 May 6, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
manager:helm-values Helm v2 values.yml files priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others type:feature Feature (new functionality)
Projects
None yet