Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vault unseal #117

Merged
merged 4 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ 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"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)


// createCmd represents the create command
var createCmd = &cobra.Command{
Use: "create",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down