Skip to content

Commit

Permalink
fix #514 (#561)
Browse files Browse the repository at this point in the history
Signed-off-by: 6za <[email protected]>

Signed-off-by: 6za <[email protected]>
  • Loading branch information
6za authored Oct 13, 2022
1 parent ffbc824 commit e63e337
Showing 1 changed file with 58 additions and 39 deletions.
97 changes: 58 additions & 39 deletions cmd/createGitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package cmd
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"os/exec"
"syscall"
"time"

"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/argocd"
"github.com/kubefirst/kubefirst/internal/flagset"
Expand All @@ -16,12 +22,6 @@ import (
"github.com/kubefirst/kubefirst/pkg"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"net/http"
"os"
"os/exec"
"syscall"
"time"
)

// createGitlabCmd represents the createGitlab command
Expand Down Expand Up @@ -372,42 +372,61 @@ var createGitlabCmd = &cobra.Command{
log.Println(err)
}
}

kPortForwardVault, err = k8s.PortForward(globalFlags.DryRun, "vault", "svc/vault", "8200:8200")
defer func(Process *os.Process, sig os.Signal) {
err := Process.Signal(sig)
if err != nil {
log.Println(err)
// enable GitLab port forward connection for Terraform
if !globalFlags.DryRun {
// force close port forward, GitLab port forward is not available at this point anymore
//Close PF before creating new ones in the loop
if kPortForwardGitlab != nil {
err = kPortForwardGitlab.Process.Signal(syscall.SIGTERM)
if err != nil {
log.Println(err)
}
}
}(kPortForwardVault.Process, syscall.SIGTERM)

// force close port forward, GitLab port forward is not available at this point anymore
if kPortForwardGitlab != nil {
err = kPortForwardGitlab.Process.Signal(syscall.SIGTERM)
if err != nil {
log.Println(err)
if kPortForwardVault != nil {
err = kPortForwardVault.Process.Signal(syscall.SIGTERM)
if err != nil {
log.Println(err)
}
}
}

kPortForwardGitlab, err = k8s.PortForward(globalFlags.DryRun, "gitlab", "svc/gitlab-webservice-default", "8888:8080")
defer func(Process *os.Process, sig os.Signal) {
err := Process.Signal(sig)
if err != nil {
log.Println(err)
if !viper.GetBool("create.terraformapplied.users") {
for i := 0; i < totalAttempts; i++ {
kPortForwardVault, err = k8s.PortForward(globalFlags.DryRun, "vault", "svc/vault", "8200:8200")
defer func() {
_ = kPortForwardVault.Process.Signal(syscall.SIGTERM)
}()
kPortForwardGitlab, err = k8s.PortForward(globalFlags.DryRun, "gitlab", "svc/gitlab-webservice-default", "8888:8080")
defer func() {
_ = kPortForwardGitlab.Process.Signal(syscall.SIGTERM)
}()
if err != nil {
log.Println("Error creating port-forward")
return err
}
//Wait the universe to sort itself out before creating more changes
time.Sleep(20 * time.Second)

// manage users via Terraform
directory = fmt.Sprintf("%s/gitops/terraform/users", config.K1FolderPath)
informUser("applying users terraform", globalFlags.SilentMode)
gitProvider := viper.GetString("git.mode")
err = terraform.ApplyUsersTerraform(globalFlags.DryRun, directory, gitProvider)
if err != nil {
log.Println("Error applying users")
log.Println(err)
}
if viper.GetBool("create.terraformapplied.users") || err == nil {
log.Println("Users configured")
break
} else {
log.Println("Users not configured - waiting before trying again")
time.Sleep(20 * time.Second)
_ = kPortForwardGitlab.Process.Signal(syscall.SIGTERM)
_ = kPortForwardVault.Process.Signal(syscall.SIGTERM)
}
}
} else {
log.Println("Skipped - Users configured")
}
}(kPortForwardGitlab.Process, syscall.SIGTERM)
if err != nil {
log.Println("Error creating port-forward")
return err
}

// manage users via Terraform
directory = fmt.Sprintf("%s/gitops/terraform/users", config.K1FolderPath)
informUser("applying users terraform", globalFlags.SilentMode)
gitProvider := viper.GetString("git.mode")
err = terraform.ApplyUsersTerraform(globalFlags.DryRun, directory, gitProvider)
if err != nil {
return err
}

return nil
Expand Down

0 comments on commit e63e337

Please sign in to comment.