mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 06:49:40 +02:00
feat(helm): use helm upgrade for install [r8s-258] (#568)
This commit is contained in:
parent
e68bd53e30
commit
0ebfe047d1
19 changed files with 613 additions and 150 deletions
|
@ -9,26 +9,6 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func createValuesFile(values string) (string, error) {
|
||||
file, err := os.CreateTemp("", "helm-values")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
_, err = file.WriteString(values)
|
||||
if err != nil {
|
||||
file.Close()
|
||||
return "", err
|
||||
}
|
||||
|
||||
err = file.Close()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return file.Name(), nil
|
||||
}
|
||||
|
||||
func Test_Install(t *testing.T) {
|
||||
test.EnsureIntegrationTest(t)
|
||||
is := assert.New(t)
|
||||
|
@ -44,10 +24,14 @@ func Test_Install(t *testing.T) {
|
|||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
}
|
||||
|
||||
release, err := hspm.Install(installOpts)
|
||||
hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
release, err := hspm.Upgrade(installOpts)
|
||||
if release != nil {
|
||||
defer hspm.Uninstall(options.UninstallOptions{
|
||||
Name: "test-nginx",
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -60,9 +44,8 @@ func Test_Install(t *testing.T) {
|
|||
|
||||
t.Run("successfully installs nginx with values", func(t *testing.T) {
|
||||
// SDK equivalent of: helm install test-nginx-2 --repo https://kubernetes.github.io/ingress-nginx nginx --values /tmp/helm-values3161785816
|
||||
values, err := createValuesFile("service:\n port: 8081")
|
||||
values, err := test.CreateValuesFile("service:\n port: 8081")
|
||||
is.NoError(err, "should create a values file")
|
||||
|
||||
defer os.Remove(values)
|
||||
|
||||
installOpts := options.InstallOptions{
|
||||
|
@ -71,10 +54,15 @@ func Test_Install(t *testing.T) {
|
|||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
ValuesFile: values,
|
||||
}
|
||||
release, err := hspm.Install(installOpts)
|
||||
|
||||
hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
release, err := hspm.Upgrade(installOpts)
|
||||
if release != nil {
|
||||
defer hspm.Uninstall(options.UninstallOptions{
|
||||
Name: "test-nginx-2",
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -92,7 +80,12 @@ func Test_Install(t *testing.T) {
|
|||
Chart: "portainer",
|
||||
Repo: "https://portainer.github.io/k8s/",
|
||||
}
|
||||
release, err := hspm.Install(installOpts)
|
||||
|
||||
hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
release, err := hspm.Upgrade(installOpts)
|
||||
if release != nil {
|
||||
defer hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
|
@ -108,9 +101,8 @@ func Test_Install(t *testing.T) {
|
|||
|
||||
t.Run("install with values as string", func(t *testing.T) {
|
||||
// First create a values file since InstallOptions doesn't support values as string directly
|
||||
values, err := createValuesFile("service:\n port: 8082")
|
||||
values, err := test.CreateValuesFile("service:\n port: 8082")
|
||||
is.NoError(err, "should create a values file")
|
||||
|
||||
defer os.Remove(values)
|
||||
|
||||
// Install with values file
|
||||
|
@ -120,10 +112,15 @@ func Test_Install(t *testing.T) {
|
|||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
ValuesFile: values,
|
||||
}
|
||||
release, err := hspm.Install(installOpts)
|
||||
|
||||
hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
release, err := hspm.Upgrade(installOpts)
|
||||
if release != nil {
|
||||
defer hspm.Uninstall(options.UninstallOptions{
|
||||
Name: "test-nginx-3",
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -140,11 +137,15 @@ func Test_Install(t *testing.T) {
|
|||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
Namespace: "default",
|
||||
}
|
||||
release, err := hspm.Install(installOpts)
|
||||
|
||||
hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
release, err := hspm.Upgrade(installOpts)
|
||||
if release != nil {
|
||||
defer hspm.Uninstall(options.UninstallOptions{
|
||||
Name: "test-nginx-4",
|
||||
Namespace: "default",
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -159,10 +160,15 @@ func Test_Install(t *testing.T) {
|
|||
Chart: "ingress-nginx",
|
||||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
}
|
||||
_, err := hspm.Install(installOpts)
|
||||
|
||||
hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
_, err := hspm.Upgrade(installOpts)
|
||||
|
||||
is.Error(err, "should return an error when name is not provided")
|
||||
is.Equal(err.Error(), "name is required")
|
||||
// is.Equal(err.Error(), "name is required for helm release installation")
|
||||
})
|
||||
|
||||
t.Run("install with invalid chart", func(t *testing.T) {
|
||||
|
@ -172,9 +178,8 @@ func Test_Install(t *testing.T) {
|
|||
Chart: "non-existent-chart",
|
||||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
}
|
||||
_, err := hspm.Install(installOpts)
|
||||
_, err := hspm.Upgrade(installOpts)
|
||||
is.Error(err, "should return error when chart doesn't exist")
|
||||
is.Equal(err.Error(), "failed to find the helm chart at the path: https://kubernetes.github.io/ingress-nginx/non-existent-chart")
|
||||
})
|
||||
|
||||
t.Run("install with invalid repo", func(t *testing.T) {
|
||||
|
@ -184,7 +189,12 @@ func Test_Install(t *testing.T) {
|
|||
Chart: "nginx",
|
||||
Repo: "https://non-existent-repo.example.com",
|
||||
}
|
||||
_, err := hspm.Install(installOpts)
|
||||
|
||||
hspm.Uninstall(options.UninstallOptions{
|
||||
Name: installOpts.Name,
|
||||
})
|
||||
|
||||
_, err := hspm.Upgrade(installOpts)
|
||||
is.Error(err, "should return error when repo doesn't exist")
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue