Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
bugfix: allow installs to proceed if no v2 and v3 release exists duri…
Browse files Browse the repository at this point in the history
…ng migration

bugfix: allow installs to proceed if no v2 and v3 release exists during migration
  • Loading branch information
Mahmoud Saada committed Jun 25, 2020
1 parent 71c1ba5 commit 5a58d84
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pkg/helm/v3/converter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v3

import (
"strings"

"github.com/helm/helm-2to3/pkg/common"
helm2 "github.com/helm/helm-2to3/pkg/v2"
helm3 "github.com/helm/helm-2to3/pkg/v3"
Expand All @@ -22,7 +24,10 @@ func (c Converter) V2ReleaseExists(releaseName string) (bool, error) {
File: c.KubeConfig,
}
v2Releases, err := helm2.GetReleaseVersions(retrieveOpts, kubeConfig)
if err != nil {

// We check for the error message content because
// Helm 2to3 returns an error if it doesn't find release versions
if err != nil && !strings.Contains(err.Error(), "has no deployed releases") {
return false, err
}
return len(v2Releases) > 0, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (r *Release) determineSyncAction(client helm.Client, hr *apiV1.HelmRelease,
case string(apiV1.HelmV3):
v2ReleaseExists, err := r.converter.V2ReleaseExists(hr.GetReleaseName())
if err != nil {
return SkipAction, nil, fmt.Errorf("failed to retrieve Helm v2 release whil attempting migration: %w", err)
return SkipAction, nil, fmt.Errorf("failed to retrieve Helm v2 release while attempting migration: %w", err)
}
if v2ReleaseExists {
return MigrateAction, nil, nil
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/45_convert_2to3.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function setup() {
kubectl create namespace "$DEMO_NAMESPACE"
}

@test "When migrate annotations exist, migration succeeds" {
@test "Migration succeeds from v2 to v3" {
# Apply the HelmRelease
kubectl apply -f "$FIXTURES_DIR/releases/convert-2to3-v2.yaml" >&3

Expand All @@ -28,6 +28,15 @@ function setup() {
poll_until_equals 'helm2 no longer shows helm release' '0' "HELM_VERSION=v2 helm ls | grep podinfo-helm-repository | wc -l | awk '{\$1=\$1};1'"
poll_until_equals 'helm3 shows helm release' 'podinfo-helm-repository' "HELM_VERSION=v3 helm ls -n $DEMO_NAMESPACE | grep podinfo-helm-repository | awk '{print \$1}'"
poll_until_equals 'release migrated' 'True' "kubectl -n $DEMO_NAMESPACE get helmrelease/podinfo-helm-repository -o jsonpath='{.status.conditions[?(@.type==\"Released\")].status}'"

kubectl apply -f "$FIXTURES_DIR/releases/convert-2to3-v3-upgrade.yaml" >&3
poll_until_equals 'upgrades work after migration' '1' "kubectl get deploy/podinfo-helm-repository -n "$DEMO_NAMESPACE" -o jsonpath='{.spec.replicas}'"
}

@test "Migration is skipped and install works when no v2 release exists" {
kubectl apply -f "$FIXTURES_DIR/releases/convert-2to3-v3.yaml" >&3
poll_until_equals 'helm3 shows helm release' 'podinfo-helm-repository' "HELM_VERSION=v3 helm ls -n $DEMO_NAMESPACE | grep podinfo-helm-repository | awk '{print \$1}'"
poll_until_equals 'install successful' 'True' "kubectl -n $DEMO_NAMESPACE get helmrelease/podinfo-helm-repository -o jsonpath='{.status.conditions[?(@.type==\"Released\")].status}'"
}

function teardown() {
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/fixtures/releases/convert-2to3-v3-upgrade.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
apiVersion: helm.fluxcd.io/v1
kind: HelmRelease
metadata:
name: podinfo-helm-repository
namespace: demo
annotations:
helm.fluxcd.io/migrate: "true"
spec:
helmVersion: v3
releaseName: podinfo-helm-repository
timeout: 30
test:
enable: true
timeout: 30
rollback:
enable: true
wait: true
chart:
repository: https://stefanprodan.github.io/podinfo
name: podinfo
version: 4.0.1
values:
replicaCount: 1

0 comments on commit 5a58d84

Please sign in to comment.