Skip to content

Commit 907a8e5

Browse files
authored
Merge pull request #96 from daniel-hutao/dev-3
feat: make argocd uninstall operation idempotent
2 parents 60f0d83 + 2a42068 commit 907a8e5

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ build-core: fmt vet ## Build dtm core only, locally.
1212
go mod tidy
1313
go build -trimpath -gcflags="all=-N -l" -o dtm ./cmd/devstream/
1414

15-
fmt: ## Run go fmt against code.
15+
fmt: ## Run 'go fmt' & goimports against code.
1616
go get golang.org/x/tools/cmd/goimports
1717
goimports -local="github.com/merico-dev/stream" -d -w cmd
1818
goimports -local="github.com/merico-dev/stream" -d -w internal

internal/pkg/argocd/argocd.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package argocd
33
import (
44
"context"
55
"log"
6+
"strings"
67
"time"
78

89
"github.com/mitchellh/mapstructure"
@@ -75,6 +76,22 @@ func (a *ArgoCD) installOrUpgradeHelmChart() error {
7576
return nil
7677
}
7778

79+
// uninstallHelmChartIgnoreReleaseNotFound will return nil when:
80+
// 1. The argocd helm chart release uninstall successful
81+
// 2. The argocd helm chart release not found
82+
func (a *ArgoCD) uninstallHelmChartIgnoreReleaseNotFound() error {
83+
err := a.uninstallHelmChart()
84+
// Log: < Release not loaded: argocd: release: not found >
85+
if err == nil {
86+
return nil
87+
}
88+
if strings.Contains(err.Error(), "not found") {
89+
log.Println("argocd release is not found, maybe it has been deleted")
90+
return nil
91+
}
92+
return err
93+
}
94+
7895
func (a *ArgoCD) uninstallHelmChart() error {
7996
err := (*a.client).UninstallReleaseByName(a.param.Chart.ReleaseName)
8097
if err != nil {

internal/pkg/argocd/reinstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func Reinstall(options *map[string]interface{}) (bool, error) {
1111
}
1212

1313
log.Println("uninstalling argocd helm chart")
14-
if err := acd.uninstallHelmChart(); err != nil {
14+
if err := acd.uninstallHelmChartIgnoreReleaseNotFound(); err != nil {
1515
return false, err
1616
}
1717

internal/pkg/argocd/uninstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func Uninstall(options *map[string]interface{}) (bool, error) {
1111
}
1212

1313
log.Println("uninstalling argocd helm chart")
14-
if err := acd.uninstallHelmChart(); err != nil {
14+
if err := acd.uninstallHelmChartIgnoreReleaseNotFound(); err != nil {
1515
return false, err
1616
}
1717

0 commit comments

Comments
 (0)