-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: migrate on upgrade * feat: migrate on upgrade + remove-rds fix * fix: typos
- Loading branch information
Showing
6 changed files
with
159 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" | ||
"github.com/kubeshop/testkube/internal/migrations" | ||
"github.com/kubeshop/testkube/pkg/process" | ||
"github.com/kubeshop/testkube/pkg/ui" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func RunMigrations(cmd *cobra.Command) (hasMigrations bool, err error) { | ||
client, _ := common.GetClient(cmd) | ||
info, err := client.GetServerInfo() | ||
ui.ExitOnError("getting server info", err) | ||
|
||
if info.Version == "" { | ||
ui.Failf("Can't detect cluster version") | ||
} | ||
|
||
migrator := migrations.Migrator | ||
ui.Info("Available migrations for", info.Version) | ||
migrations := migrator.GetValidMigrations(info.Version) | ||
if len(migrations) == 0 { | ||
ui.Warn("No migrations available for", info.Version) | ||
return false, nil | ||
} | ||
|
||
for _, migration := range migrations { | ||
fmt.Printf("- %+v - %s\n", migration.Version(), migration.Info()) | ||
} | ||
|
||
return true, migrator.Run(info.Version) | ||
} | ||
|
||
func HelmUpgradeOrInstalTestkube(name, namespace, chart string, noDashboard, noMinio, noJetstack bool) error { | ||
helmPath, err := exec.LookPath("helm") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !noJetstack { | ||
_, err = process.Execute("kubectl", "get", "crds", "certificates.cert-manager.io") | ||
if err != nil && !strings.Contains(err.Error(), "Error from server (NotFound)") { | ||
return err | ||
} | ||
|
||
if err != nil { | ||
ui.Info("Helm installing jetstack cert manager") | ||
_, err = process.Execute(helmPath, "repo", "add", "jetstack", "https://charts.jetstack.io") | ||
if err != nil && !strings.Contains(err.Error(), "Error: repository name (jetstack) already exists") { | ||
return err | ||
} | ||
|
||
_, err = process.Execute(helmPath, "repo", "update") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
command := []string{"upgrade", "--install", "--create-namespace", "--namespace", namespace, "--set", "installCRDs=true"} | ||
command = append(command, "jetstack", "jetstack/cert-manager") | ||
|
||
out, err := process.Execute(helmPath, command...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ui.Info("Helm install jetstack output", string(out)) | ||
} | ||
} | ||
|
||
ui.Info("Helm installing testkube framework") | ||
_, err = process.Execute(helmPath, "repo", "add", "kubeshop", "https://kubeshop.github.io/helm-charts") | ||
if err != nil && !strings.Contains(err.Error(), "Error: repository name (kubeshop) already exists, please specify a different name") { | ||
ui.WarnOnError("adding testkube repo", err) | ||
} | ||
|
||
_, err = process.Execute(helmPath, "repo", "update") | ||
ui.ExitOnError("updating helm repositories", err) | ||
|
||
command := []string{"upgrade", "--install", "--create-namespace", "--namespace", namespace} | ||
command = append(command, "--set", fmt.Sprintf("api-server.minio.enabled=%t", !noMinio)) | ||
command = append(command, "--set", fmt.Sprintf("testkube-dashboard.enabled=%t", !noDashboard)) | ||
command = append(command, name, chart) | ||
|
||
out, err := process.Execute(helmPath, command...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ui.Info("Helm install testkube output", string(out)) | ||
return nil | ||
} |
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
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,45 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/kubeshop/testkube/pkg/ui" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewUpgradeCmd() *cobra.Command { | ||
var ( | ||
noDashboard bool | ||
noMinio bool | ||
noJetstack bool | ||
chart, name, namespace string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "upgrade", | ||
Short: "Upgrade Helm chart and run migrations", | ||
Long: `Upgrade can be configured with use of particular `, | ||
Aliases: []string{"update"}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ui.Logo() | ||
|
||
hasMigrations, err := RunMigrations(cmd) | ||
ui.ExitOnError("Running migrations", err) | ||
if hasMigrations { | ||
ui.Success("All migrations executed successfully") | ||
} | ||
|
||
err = HelmUpgradeOrInstalTestkube(name, namespace, chart, noDashboard, noMinio, noJetstack) | ||
ui.ExitOnError("installing Testkube", err) | ||
|
||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&chart, "chart", "kubeshop/testkube", "chart name") | ||
cmd.Flags().StringVar(&name, "name", "testkube", "installation name") | ||
cmd.Flags().StringVar(&namespace, "namespace", "testkube", "namespace where to install") | ||
|
||
cmd.Flags().BoolVar(&noMinio, "no-minio", false, "don't install MinIO") | ||
cmd.Flags().BoolVar(&noDashboard, "no-dashboard", false, "don't install dashboard") | ||
cmd.Flags().BoolVar(&noJetstack, "no-jetstack", false, "don't install Jetstack") | ||
|
||
return cmd | ||
} |