diff --git a/cmd/create.go b/cmd/create.go index d923ad563..28cd03cb8 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -13,7 +13,6 @@ import ( "github.com/kubefirst/kubefirst/internal/gitlab" "github.com/kubefirst/kubefirst/internal/helm" "github.com/kubefirst/kubefirst/internal/progressPrinter" - "github.com/kubefirst/kubefirst/internal/reports" "github.com/kubefirst/kubefirst/internal/softserve" "github.com/kubefirst/kubefirst/internal/terraform" "github.com/kubefirst/kubefirst/internal/vault" @@ -21,6 +20,7 @@ import ( "github.com/spf13/viper" ) + // createCmd represents the create command var createCmd = &cobra.Command{ Use: "create", @@ -49,11 +49,7 @@ to quickly create a Cobra application.`, log.Panic(err) } - // todo: - // isolate commands, in case we want to run some validations on the create, it would be a good idea to call the - // functions that does the validations infoCmd.Run(cmd, args) - progressPrinter.IncrementTracker("step-0", 1) progressPrinter.AddTracker("step-softserve", "Prepare Temporary Repo ", 4) @@ -208,13 +204,15 @@ to quickly create a Cobra application.`, progressPrinter.AddTracker("step-vault", "Configure Vault", 4) informUser("waiting for vault unseal") + /** - informUser("Vault initialized") + */ + waitVaultToBeRunning(dryRun) + informUser("Vault running") progressPrinter.IncrementTracker("step-vault", 1) - // todo need to make sure this is not needed - // waitForVaultUnseal(dryRun, config) - // informUser("Vault unseal") + waitForVaultUnseal(dryRun, config) + informUser("Vault unseal") progressPrinter.IncrementTracker("step-vault", 1) log.Println("configuring vault") @@ -226,7 +224,9 @@ to quickly create a Cobra application.`, createVaultConfiguredSecret(dryRun, config) informUser("Vault secret created") progressPrinter.IncrementTracker("step-vault", 1) + } + if !viper.GetBool("gitlab.oidc-created") { progressPrinter.AddTracker("step-post-gitlab", "Finalize Gitlab updates", 5) vault.AddGitlabOidcApplications(dryRun) informUser("Added Gitlab OIDC") @@ -238,24 +238,34 @@ to quickly create a Cobra application.`, informUser("Pushing gitops repo to origin gitlab") // refactor: sounds like a new functions, should PushGitOpsToGitLab be renamed/update signature? - + viper.Set("gitlab.oidc-created", true) + viper.WriteConfig() + } + if !viper.GetBool("gitlab.gitops-pushed") { gitlab.PushGitRepo(dryRun, config, "gitlab", "gitops") // todo: need to handle if this was already pushed, errors on failure) progressPrinter.IncrementTracker("step-post-gitlab", 1) // todo: keep one of the two git push functions, they're similar, but not exactly the same //gitlab.PushGitOpsToGitLab(dryRun) - + viper.Set("gitlab.gitops-pushed", true) + viper.WriteConfig() + } + if !viper.GetBool("gitlab.metaphor-pushed") { informUser("Pushing metaphor repo to origin gitlab") gitlab.PushGitRepo(dryRun, config, "gitlab", "metaphor") progressPrinter.IncrementTracker("step-post-gitlab", 1) // todo: keep one of the two git push functions, they're similar, but not exactly the same //gitlab.PushGitOpsToGitLab(dryRun) - + viper.Set("gitlab.metaphor-pushed", true) + viper.WriteConfig() + } + if !viper.GetBool("gitlab.registered") { informUser("Changing registry to Gitlab") gitlab.ChangeRegistryToGitLab(dryRun) progressPrinter.IncrementTracker("step-post-gitlab", 1) - // todo triage / force apply the contents adjusting // todo kind: Application .repoURL: + viper.Set("gitlab.registered", true) + viper.WriteConfig() } } sendCompleteInstallTelemetry(dryRun) diff --git a/internal/gitlab/gitlab.go b/internal/gitlab/gitlab.go index 265d32e90..c2ae2f84c 100644 --- a/internal/gitlab/gitlab.go +++ b/internal/gitlab/gitlab.go @@ -560,7 +560,13 @@ func PushGitRepo(dryRun bool, config *configs.Config, gitOrigin, repoName string } if gitOrigin == "gitlab" { - + pkg.Detokenize(repoDir) + os.RemoveAll(repoDir + "/terraform/base/.terraform") + os.RemoveAll(repoDir + "/terraform/gitlab/.terraform") + os.RemoveAll(repoDir + "/terraform/vault/.terraform") + os.Remove(repoDir + "/terraform/base/.terraform.lock.hcl") + os.Remove(repoDir + "/terraform/gitlab/.terraform.lock.hcl") + CommitToRepo(repo, repoName) auth := &gitHttp.BasicAuth{ Username: "root", Password: viper.GetString("gitlab.token"),