diff --git a/cmd/api-server/main.go b/cmd/api-server/main.go index ad57c53c700..16d1c51baf7 100644 --- a/cmd/api-server/main.go +++ b/cmd/api-server/main.go @@ -122,7 +122,7 @@ func runMigrations() (err error) { return migrations.Migrator.Run(version.Version, migrator.MigrationTypeServer) } -func runMongoMigrations(ctx context.Context, db *mongo.Database, migrationsDir string) error { +func runMongoMigrations(ctx context.Context, db *mongo.Database, _ string) error { migrationsCollectionName := "__migrations" activeMigrations, err := dbmigrator.GetDbMigrationsFromFs(dbmigrations.MongoMigrationsFs) if err != nil { diff --git a/cmd/kubectl-testkube/commands/common/errors.go b/cmd/kubectl-testkube/commands/common/errors.go index 9dbfce1526c..92015d9fba7 100644 --- a/cmd/kubectl-testkube/commands/common/errors.go +++ b/cmd/kubectl-testkube/commands/common/errors.go @@ -34,6 +34,9 @@ const ( TKErrHelmCommandFailed ErrorCode = "TKERR-1301" // TKErrKubectlCommandFailed is returned when a kubectl command fail. TKErrKubectlCommandFailed ErrorCode = "TKERR-1302" + + // TKErrCleanOldMigrationJobFailed is returned in case of issues with old migration jobs. + TKErrCleanOldMigrationJobFailed ErrorCode = "TKERR-1401" ) const helpUrl = "https://testkubeworkspace.slack.com" diff --git a/cmd/kubectl-testkube/commands/common/helper.go b/cmd/kubectl-testkube/commands/common/helper.go index fb5b6363385..a42486e35a1 100644 --- a/cmd/kubectl-testkube/commands/common/helper.go +++ b/cmd/kubectl-testkube/commands/common/helper.go @@ -162,6 +162,30 @@ func updateHelmRepo(helmPath string, dryRun bool, isOnPrem bool) *CLIError { return nil } +// It cleans existing migrations job with long TTL +func CleanExistingCompletedMigrationJobs(namespace string) (cliErr *CLIError) { + kubectlPath, cliErr := lookupKubectlPath() + if cliErr != nil { + return cliErr + } + + // Clean the job only when it's found and it's state is successful - ignore pending migrations. + succeeded, _ := runKubectlCommand(kubectlPath, []string{"get", "job", "testkube-enterprise-api-migrations", "-n", namespace, "-o", "jsonpath={.status.succeeded}"}) + if succeeded == "1" { + _, err := runKubectlCommand(kubectlPath, []string{"delete", "job", "testkube-enterprise-api-migrations", "--namespace", namespace}) + if err != nil { + return NewCLIError( + TKErrCleanOldMigrationJobFailed, + "Can't clean old migrations job", + "Migration job can't be deleted from some reason, check for errors in installation namespace, check execution. As a workaround try to delete job manually and retry installation/upgrade process", + err, + ) + } + } + + return nil +} + func runHelmCommand(helmPath string, args []string, dryRun bool) (commandOutput string, cliErr *CLIError) { output, err := process.ExecuteWithOptions(process.Options{Command: helmPath, Args: args, DryRun: dryRun}) if err != nil { diff --git a/cmd/kubectl-testkube/commands/init.go b/cmd/kubectl-testkube/commands/init.go index 705ee10c7d0..0458ad99752 100644 --- a/cmd/kubectl-testkube/commands/init.go +++ b/cmd/kubectl-testkube/commands/init.go @@ -214,6 +214,17 @@ func NewInitCmdDemo() *cobra.Command { DemoValuesURL: demoValuesUrl, DryRun: dryRun, } + + cliErr = common.CleanExistingCompletedMigrationJobs(options.Namespace) + if cliErr != nil { + spinner.Fail("Failed to install Testkube On-Prem Demo") + if cfg.TelemetryEnabled { + cliErr.AddTelemetry(cmd, "installing", "install_failed", license) + _, _ = telemetry.HandleCLIErrorTelemetry(common.Version, cliErr) + } + common.HandleCLIError(cliErr) + } + cliErr = common.HelmUpgradeOrInstallTestkubeOnPremDemo(options) if cliErr != nil { spinner.Fail("Failed to install Testkube On-Prem Demo") diff --git a/cmd/testworkflow-init/obfuscator/obfuscator.go b/cmd/testworkflow-init/obfuscator/obfuscator.go index 0b6b5607bb2..74667d3b5eb 100644 --- a/cmd/testworkflow-init/obfuscator/obfuscator.go +++ b/cmd/testworkflow-init/obfuscator/obfuscator.go @@ -135,7 +135,7 @@ func (s *obfuscator) Write(p []byte) (n int, err error) { // Write the rest of data if len(p) > 0 { - nn, err = s.dst.Write(p) + _, err = s.dst.Write(p) return size, err } return size, nil diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go index 8d98b4ea2b5..9a15fcea8a0 100644 --- a/pkg/agent/agent.go +++ b/pkg/agent/agent.go @@ -378,7 +378,7 @@ func (ag *Agent) runWorkers(ctx context.Context, numWorkers int) error { return g.Wait() } -func (ag *Agent) executeCommand(ctx context.Context, cmd *cloud.ExecuteRequest) *cloud.ExecuteResponse { +func (ag *Agent) executeCommand(_ context.Context, cmd *cloud.ExecuteRequest) *cloud.ExecuteResponse { switch { case cmd.Url == healthcheckCommand: return &cloud.ExecuteResponse{MessageId: cmd.MessageId, Status: 0}