mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 06:19:41 +02:00
feat(helm): rollback helm chart [r8s-287] (#660)
This commit is contained in:
parent
61d6ac035d
commit
c91c8a6467
13 changed files with 701 additions and 32 deletions
123
pkg/libhelm/sdk/rollback_test.go
Normal file
123
pkg/libhelm/sdk/rollback_test.go
Normal file
|
@ -0,0 +1,123 @@
|
|||
package sdk
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/portainer/portainer/pkg/libhelm/options"
|
||||
"github.com/portainer/portainer/pkg/libhelm/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRollback(t *testing.T) {
|
||||
test.EnsureIntegrationTest(t)
|
||||
is := assert.New(t)
|
||||
|
||||
// Create a new SDK package manager
|
||||
hspm := NewHelmSDKPackageManager()
|
||||
|
||||
t.Run("should return error when name is not provided", func(t *testing.T) {
|
||||
rollbackOpts := options.RollbackOptions{
|
||||
Namespace: "default",
|
||||
}
|
||||
|
||||
_, err := hspm.Rollback(rollbackOpts)
|
||||
|
||||
is.Error(err, "should return an error when name is not provided")
|
||||
is.Equal("name is required for helm release rollback", err.Error(), "should return correct error message")
|
||||
})
|
||||
|
||||
t.Run("should return error when release doesn't exist", func(t *testing.T) {
|
||||
rollbackOpts := options.RollbackOptions{
|
||||
Name: "non-existent-release",
|
||||
Namespace: "default",
|
||||
}
|
||||
|
||||
_, err := hspm.Rollback(rollbackOpts)
|
||||
|
||||
is.Error(err, "should return an error when release doesn't exist")
|
||||
})
|
||||
|
||||
t.Run("should successfully rollback to previous revision", func(t *testing.T) {
|
||||
// First install a release
|
||||
installOpts := options.InstallOptions{
|
||||
Name: "hello-world",
|
||||
Chart: "hello-world",
|
||||
Namespace: "default",
|
||||
Repo: "https://helm.github.io/examples",
|
||||
}
|
||||
|
||||
// Ensure the release doesn't exist before test
|
||||
hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
// Install first version
|
||||
release, err := hspm.Upgrade(installOpts)
|
||||
is.NoError(err, "should successfully install release")
|
||||
is.Equal(1, release.Version, "first version should be 1")
|
||||
|
||||
// Upgrade to second version
|
||||
_, err = hspm.Upgrade(installOpts)
|
||||
is.NoError(err, "should successfully upgrade release")
|
||||
|
||||
// Rollback to first version
|
||||
rollbackOpts := options.RollbackOptions{
|
||||
Name: installOpts.Name,
|
||||
Namespace: "default",
|
||||
Version: 0, // Previous revision
|
||||
}
|
||||
|
||||
rolledBackRelease, err := hspm.Rollback(rollbackOpts)
|
||||
defer hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
is.NoError(err, "should successfully rollback release")
|
||||
is.NotNil(rolledBackRelease, "should return non-nil release")
|
||||
is.Equal(3, rolledBackRelease.Version, "version should be incremented to 3")
|
||||
})
|
||||
|
||||
t.Run("should successfully rollback to specific revision", func(t *testing.T) {
|
||||
// First install a release
|
||||
installOpts := options.InstallOptions{
|
||||
Name: "hello-world",
|
||||
Chart: "hello-world",
|
||||
Namespace: "default",
|
||||
Repo: "https://helm.github.io/examples",
|
||||
}
|
||||
|
||||
// Ensure the release doesn't exist before test
|
||||
hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
// Install first version
|
||||
release, err := hspm.Upgrade(installOpts)
|
||||
is.NoError(err, "should successfully install release")
|
||||
is.Equal(1, release.Version, "first version should be 1")
|
||||
|
||||
// Upgrade to second version
|
||||
_, err = hspm.Upgrade(installOpts)
|
||||
is.NoError(err, "should successfully upgrade release")
|
||||
|
||||
// Upgrade to third version
|
||||
_, err = hspm.Upgrade(installOpts)
|
||||
is.NoError(err, "should successfully upgrade release again")
|
||||
|
||||
// Rollback to first version
|
||||
rollbackOpts := options.RollbackOptions{
|
||||
Name: installOpts.Name,
|
||||
Namespace: "default",
|
||||
Version: 1, // Specific revision
|
||||
}
|
||||
|
||||
rolledBackRelease, err := hspm.Rollback(rollbackOpts)
|
||||
defer hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
is.NoError(err, "should successfully rollback to specific revision")
|
||||
is.NotNil(rolledBackRelease, "should return non-nil release")
|
||||
is.Equal(4, rolledBackRelease.Version, "version should be incremented to 4")
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue