-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds wait-retry to helm update & delete
- Loading branch information
1 parent
4b313a6
commit 30f592f
Showing
3 changed files
with
270 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package chart | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
"github.com/stretchr/testify/require" | ||
"helm.sh/helm/v3/pkg/action" | ||
"helm.sh/helm/v3/pkg/chart" | ||
"helm.sh/helm/v3/pkg/release" | ||
) | ||
|
||
func TestWaitForActionableStatus(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
statusFuncMap map[int]release.Status // sequence of responses returned by mockStatusFunc | ||
statusMap map[release.Status]int // test update or delete | ||
expected bool | ||
expectedStatusFuncCalls int | ||
expectedError error | ||
}{ | ||
{ | ||
description: "delete success - deployed", | ||
statusFuncMap: map[int]release.Status{0: release.StatusDeployed}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: true, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "delete eventual success", | ||
statusFuncMap: map[int]release.Status{0: release.StatusUnknown, 1: release.StatusDeployed}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: true, | ||
expectedStatusFuncCalls: 2, | ||
}, | ||
{ | ||
description: "delete success - not found", | ||
statusFuncMap: map[int]release.Status{0: "not-found"}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: false, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "delete success - superseded", | ||
statusFuncMap: map[int]release.Status{0: release.StatusSuperseded}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: false, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "delete timeout", | ||
statusFuncMap: map[int]release.Status{0: release.StatusPendingInstall, 1: release.StatusPendingInstall, 2: release.StatusPendingInstall, 3: release.StatusPendingInstall, 4: release.StatusPendingInstall}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: true, | ||
expectedStatusFuncCalls: 5, | ||
}, | ||
{ | ||
description: "update success - deployed", | ||
statusFuncMap: map[int]release.Status{0: release.StatusDeployed}, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: true, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "update eventual success", | ||
statusFuncMap: map[int]release.Status{0: release.StatusUnknown, 1: release.StatusDeployed}, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: true, | ||
expectedStatusFuncCalls: 2, | ||
}, { | ||
description: "delete success - deployed", | ||
statusFuncMap: map[int]release.Status{0: release.StatusDeployed}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: true, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "delete eventual success", | ||
statusFuncMap: map[int]release.Status{0: release.StatusUnknown, 1: release.StatusDeployed}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: true, | ||
expectedStatusFuncCalls: 2, | ||
}, | ||
{ | ||
description: "delete success - not found", | ||
statusFuncMap: map[int]release.Status{0: "not-found"}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: false, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "delete success - superseded", | ||
statusFuncMap: map[int]release.Status{0: release.StatusSuperseded}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: false, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "delete timeout", | ||
statusFuncMap: map[int]release.Status{0: release.StatusPendingInstall, 1: release.StatusPendingInstall, 2: release.StatusPendingInstall, 3: release.StatusPendingInstall, 4: release.StatusPendingInstall}, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: true, | ||
expectedStatusFuncCalls: 5, | ||
}, | ||
{ | ||
description: "update success - deployed", | ||
statusFuncMap: map[int]release.Status{0: release.StatusDeployed}, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: true, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "update eventual success", | ||
statusFuncMap: map[int]release.Status{0: release.StatusUnknown, 1: release.StatusDeployed}, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: true, | ||
expectedStatusFuncCalls: 2, | ||
}, | ||
{ | ||
description: "update success - not found", | ||
statusFuncMap: map[int]release.Status{0: "not-found"}, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: false, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "update success - uninstalled", | ||
statusFuncMap: map[int]release.Status{0: release.StatusUninstalled}, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: false, | ||
expectedStatusFuncCalls: 1, | ||
}, | ||
{ | ||
description: "update timeout", | ||
statusFuncMap: map[int]release.Status{0: release.StatusPendingInstall, 1: release.StatusPendingInstall, 2: release.StatusPendingInstall, 3: release.StatusPendingInstall, 4: release.StatusPendingInstall}, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: true, | ||
expectedStatusFuncCalls: 5, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.description, func(t *testing.T) { | ||
c := &HelmClient{ | ||
log: log.NullLogger{}, | ||
} | ||
// speed up retry, timeout | ||
statusRetryInterval = time.Millisecond * 100 | ||
statusRetryTimeout = time.Millisecond * 500 | ||
// mockStatusFunc and counter to track times called | ||
counter := 0 | ||
mockStatusFunc := func(cfg *action.Configuration, appName string) (*release.Release, release.Status, error) { | ||
status := tc.statusFuncMap[counter] | ||
counter += 1 | ||
mockRelease := &release.Release{Chart: &chart.Chart{}, Info: &release.Info{}} | ||
return mockRelease, status, nil | ||
} | ||
|
||
ok, err := c.waitForActionableStatus(mockStatusFunc, "testapp", helmStatusActionMapDelete) | ||
if tc.expectedError != nil { | ||
require.EqualError(t, err, tc.expectedError.Error()) | ||
} else { | ||
require.Nil(t, err) | ||
} | ||
require.Equal(t, tc.expected, ok) | ||
require.Equal(t, tc.expectedStatusFuncCalls, counter) | ||
}) | ||
} | ||
} |