-
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.
[SHIPA-2322] adds wait-retry to helm update & delete (#233)
* adds wait-retry to helm update & delete clean up tests * avoids wait loop; returns error on non-actionable statuses; clean up const labels * adds default timeout/update to helm chart checks * rm duplicated code
- Loading branch information
1 parent
4b313a6
commit a6830cd
Showing
3 changed files
with
189 additions
and
28 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,93 @@ | ||
package chart | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"helm.sh/helm/v3/pkg/action" | ||
"helm.sh/helm/v3/pkg/release" | ||
helmTime "helm.sh/helm/v3/pkg/time" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
func TestIsHelmChartStatusActionable(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
status release.Status | ||
statusMap map[release.Status]int // helmStatusActionMapUpdate or helmStatusActionMapDelete | ||
expected bool | ||
expectedError string | ||
}{ | ||
{ | ||
description: "update - deployed", | ||
status: release.StatusDeployed, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: true, | ||
}, | ||
{ | ||
description: "update - not found", | ||
status: notFound, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: true, | ||
}, | ||
{ | ||
description: "update - unknown", | ||
status: release.StatusUnknown, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: false, | ||
expectedError: "helm chart for app testapp in non-actionable status unknown", | ||
}, | ||
{ | ||
description: "update - superseded", | ||
status: release.StatusSuperseded, | ||
statusMap: helmStatusActionMapUpdate, | ||
expected: false, | ||
}, | ||
{ | ||
description: "delete - deployed", | ||
status: release.StatusDeployed, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: true, | ||
}, | ||
{ | ||
description: "delete - not found", | ||
status: notFound, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: false, | ||
}, | ||
{ | ||
description: "delete - unknown", | ||
status: release.StatusUnknown, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: false, | ||
expectedError: "helm chart for app testapp in non-actionable status unknown", | ||
}, | ||
{ | ||
description: "delete - superseded", | ||
status: release.StatusSuperseded, | ||
statusMap: helmStatusActionMapDelete, | ||
expected: false, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.description, func(t *testing.T) { | ||
c := &HelmClient{ | ||
log: log.NullLogger{}, | ||
} | ||
mockStatusFunc := func(cfg *action.Configuration, appName string) (*release.Release, release.Status, error) { | ||
status := tc.status | ||
currentRelease := &release.Release{Info: &release.Info{FirstDeployed: helmTime.Time{Time: time.Now()}}} | ||
return currentRelease, status, nil | ||
} | ||
|
||
ok, err := c.isHelmChartStatusActionable(mockStatusFunc, "testapp", tc.statusMap) | ||
if tc.expectedError != "" { | ||
require.EqualError(t, err, tc.expectedError) | ||
} else { | ||
require.Nil(t, err) | ||
} | ||
require.Equal(t, tc.expected, ok) | ||
}) | ||
} | ||
} |