diff --git a/decision_maker.go b/decision_maker.go index 2705ca7e..5bdcd4c1 100644 --- a/decision_maker.go +++ b/decision_maker.go @@ -268,7 +268,7 @@ func logDecision(decision string) { } -// extractChartName extracts the Helm chart name from full chart name. +// extractChartName extracts the Helm chart name from full chart name in the desired state. // example: it extracts "chartY" from "repoX/chartY" func extractChartName(releaseChart string) string { @@ -328,6 +328,11 @@ func checkNamespaceDefined(ns string) bool { // returns true if a release is protected, false otherwise func isProtected(r release) bool { + // if the release does not exist in the cluster, it is not protected + if !helmReleaseExists("", r.Name, "all") { + return false + } + if getCurrentNamespaceProtection(r) { return true } diff --git a/helm_helpers.go b/helm_helpers.go index 8533856f..b293bf3b 100644 --- a/helm_helpers.go +++ b/helm_helpers.go @@ -97,15 +97,19 @@ func getReleaseRevision(releaseName string, state string) string { } // getReleaseChartName extracts and returns the Helm chart name from the chart info retrieved by getReleaseChart(). -// example: getReleaseChart() returns "stable/jenkins-0.9.0" and this functions will extract "stable/jenkins" from it. +// example: getReleaseChart() returns "jenkins-0.9.0" and this functions will extract "jenkins" from it. func getReleaseChartName(releaseName string) string { - return strings.TrimSpace(strings.Split(getReleaseChart(releaseName), "-")[0]) + chart := getReleaseChart(releaseName) + runes := []rune(chart) + return string(runes[0:strings.LastIndexByte(chart, '-')]) } // getReleaseChartVersion extracts and returns the Helm chart version from the chart info retrieved by getReleaseChart(). -// example: getReleaseChart() returns "stable/jenkins-0.9.0" and this functions will extract "0.9.0" from it. +// example: getReleaseChart() returns "jenkins-0.9.0" and this functions will extract "0.9.0" from it. func getReleaseChartVersion(releaseName string) string { - return strings.TrimSpace(strings.Split(getReleaseChart(releaseName), "-")[1]) + chart := getReleaseChart(releaseName) + runes := []rune(chart) + return string(runes[strings.LastIndexByte(chart, '-')+1 : len(chart)]) } // getReleaseStatus returns the output of Helm status command for a release.