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

Messages #1849

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func createAws(cmd *cobra.Command, args []string) error {
// If cluster setup is complete, return
clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete")
if clusterSetupComplete {
err = fmt.Errorf("this cluster install process has already completed successfully")
err = fmt.Errorf("the cluster install process from a previous execution has already completed successfully. to reset your local state and create a new cluster, run kubefirst reset.")
progress.Error(err.Error())
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func createCivo(cmd *cobra.Command, args []string) error {
// If cluster setup is complete, return
clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete")
if clusterSetupComplete {
err = fmt.Errorf("this cluster install process has already completed successfully")
err = fmt.Errorf("the cluster install process from a previous execution has already completed successfully. to reset your local state and create a new cluster, run kubefirst reset.")
progress.Error(err.Error())
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/digitalocean/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func createDigitalocean(cmd *cobra.Command, args []string) error {
// If cluster setup is complete, return
clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete")
if clusterSetupComplete {
err = fmt.Errorf("this cluster install process has already completed successfully")
err = fmt.Errorf("the cluster install process from a previous execution has already completed successfully. to reset your local state and create a new cluster, run kubefirst reset.")
progress.Error(err.Error())
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/google/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func createGoogle(cmd *cobra.Command, args []string) error {
// If cluster setup is complete, return
clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete")
if clusterSetupComplete {
err = fmt.Errorf("this cluster install process has already completed successfully")
err = fmt.Errorf("the cluster install process from a previous execution has already completed successfully. to reset your local state and create a new cluster, run kubefirst reset.")
progress.Error(err.Error())
return nil
}
Expand Down
92 changes: 37 additions & 55 deletions cmd/k3d/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ import (
githttps "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/kubefirst/kubefirst-api/pkg/handlers"
"github.com/kubefirst/kubefirst-api/pkg/reports"
runtimetypes "github.com/kubefirst/kubefirst-api/pkg/types"
utils "github.com/kubefirst/kubefirst-api/pkg/utils"
"github.com/kubefirst/kubefirst-api/pkg/wrappers"
"github.com/kubefirst/kubefirst/internal/gitShim"
"github.com/kubefirst/kubefirst/internal/telemetryShim"
"github.com/kubefirst/kubefirst/internal/utilities"
"github.com/kubefirst/runtime/configs"
"github.com/kubefirst/runtime/pkg"
"github.com/kubefirst/runtime/pkg/argocd"
"github.com/kubefirst/runtime/pkg/docker"
"github.com/kubefirst/runtime/pkg/gitClient"
"github.com/kubefirst/runtime/pkg/github"
gitlab "github.com/kubefirst/runtime/pkg/gitlab"
Expand Down Expand Up @@ -116,7 +113,7 @@ func runK3d(cmd *cobra.Command, args []string) error {
// If cluster setup is complete, return
clusterSetupComplete := viper.GetBool("kubefirst-checks.cluster-install-complete")
if clusterSetupComplete {
return fmt.Errorf("this cluster install process has already completed successfully")
return fmt.Errorf("the cluster install process from a previous execution has already completed successfully. to reset your local state and create a new cluster, run kubefirst reset.")
}

utilities.CreateK1ClusterDirectory(clusterNameFlag)
Expand Down Expand Up @@ -150,14 +147,14 @@ func runK3d(cmd *cobra.Command, args []string) error {
return fmt.Errorf("%s - this port is required to set up your kubefirst environment - please close any existing port forwards before continuing", err.Error())
}

// Verify Docker is running
dcli := docker.DockerClientWrapper{
Client: docker.NewDockerClient(),
}
_, err = dcli.CheckDockerReady()
if err != nil {
return err
}
// // Verify Docker is running
// dcli := docker.DockerClientWrapper{
// Client: docker.NewDockerClient(),
// }
// _, err = dcli.CheckDockerReady()
// if err != nil {
// return err
// }

// Global context
var ctx context.Context
Expand All @@ -176,7 +173,7 @@ func runK3d(cmd *cobra.Command, args []string) error {
viper.Set("flags.domain-name", k3d.DomainName)
viper.Set("flags.git-provider", gitProviderFlag)
viper.Set("flags.git-protocol", gitProtocolFlag)

viper.Set("kubefirst.cloud-provider", "k3d")
viper.WriteConfig()

// Switch based on git provider, set params
Expand Down Expand Up @@ -1336,40 +1333,23 @@ func runK3d(cmd *cobra.Command, args []string) error {
progressPrinter.IncrementTracker("wrapping-up", 1)

// Wait for console Deployment Pods to transition to Running
consoleDeployment, err := k8s.ReturnDeploymentObject(
argoDeployment, err := k8s.ReturnDeploymentObject(
kcfg.Clientset,
"app.kubernetes.io/instance",
"kubefirst",
"kubefirst",
"argo",
"argo",
600,
)
if err != nil {
log.Error().Msgf("Error finding console Deployment: %s", err)
log.Error().Msgf("Error finding argo workflows Deployment: %s", err)
return err
}
_, err = k8s.WaitForDeploymentReady(kcfg.Clientset, consoleDeployment, 120)
_, err = k8s.WaitForDeploymentReady(kcfg.Clientset, argoDeployment, 120)
if err != nil {
log.Error().Msgf("Error waiting for console Deployment ready state: %s", err)
log.Error().Msgf("Error waiting for argo workflows Deployment ready state: %s", err)
return err
}

// * console port-forward
consoleStopChannel := make(chan struct{}, 1)
defer func() {
close(consoleStopChannel)
}()
k8s.OpenPortForwardPodWrapper(
kcfg.Clientset,
kcfg.RestConfig,
"kubefirst-console",
"kubefirst",
8080,
9094,
consoleStopChannel,
)

progressPrinter.IncrementTracker("wrapping-up", 1)

// Mark cluster install as complete
telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricClusterInstallCompleted, "")
viper.Set("kubefirst-checks.cluster-install-complete", true)
Expand All @@ -1378,33 +1358,35 @@ func runK3d(cmd *cobra.Command, args []string) error {
// Set flags used to track status of active options
helpers.SetClusterStatusFlags(k3d.CloudProvider, config.GitProvider)

//Export and Import Cluster
cl := utilities.CreateClusterRecordFromRaw(useTelemetryFlag, cGitOwner, cGitUser, cGitToken, cGitlabOwnerGroupID, gitopsTemplateURLFlag, gitopsTemplateBranchFlag)
cluster := utilities.CreateClusterRecordFromRaw(useTelemetryFlag, cGitOwner, cGitUser, cGitToken, cGitlabOwnerGroupID, gitopsTemplateURLFlag, gitopsTemplateBranchFlag)

var localFilePath = fmt.Sprintf("%s/%s.json", "/tmp/api/cluster/export", clusterNameFlag)
utilities.CreateClusterRecordFile(clusterNameFlag, cl)

// Upload the zip file with FPutObject
info, err = minioClient.FPutObject(ctx, bucketName, fmt.Sprintf("%s.json", clusterNameFlag), localFilePath, minio.PutObjectOptions{ContentType: "application/json"})
if err != nil {
log.Info().Msgf("Error uploading to Minio bucket: %s", err)
}

kubernetesConfig := runtimetypes.KubernetesClient{
Clientset: kcfg.Clientset,
KubeConfigPath: kcfg.KubeConfigPath,
RestConfig: kcfg.RestConfig,
}

err = utils.ExportCluster(kubernetesConfig, cl)
err = utilities.ExportCluster(cluster, kcfg)
if err != nil {
log.Error().Err(err).Msg("error exporting cluster object")
viper.Set("kubefirst.setup-complete", false)
viper.Set("kubefirst-checks.cluster-install-complete", false)
viper.WriteConfig()
return err
} else {
err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLCloud)
kubefirstDeployment, err := k8s.ReturnDeploymentObject(
kcfg.Clientset,
"app.kubernetes.io/instance",
"kubefirst",
"kubefirst",
600,
)
if err != nil {
log.Error().Msgf("Error finding kubefirst Deployment: %s", err)
return err
}
_, err = k8s.WaitForDeploymentReady(kcfg.Clientset, kubefirstDeployment, 120)
if err != nil {
log.Error().Msgf("Error waiting for kubefirst Deployment ready state: %s", err)
return err
}
progressPrinter.IncrementTracker("wrapping-up", 1)

err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLTLS)
if err != nil {
log.Error().Err(err).Msg("")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func launchUp() *cobra.Command {
Use: "up",
Short: "launch new console and api instance",
TraverseChildren: true,
PreRun: common.CheckDocker,
// PreRun: common.CheckDocker,
Run: func(cmd *cobra.Command, args []string) {
launch.Up(additionalHelmFlags, false, true)
},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/go-git/go-git/v5 v5.6.1
github.com/hashicorp/vault/api v1.9.0
github.com/kubefirst/kubefirst-api v0.0.2
github.com/kubefirst/runtime v0.3.24
github.com/kubefirst/runtime v0.3.28
github.com/rs/zerolog v1.29.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubefirst/kubefirst-api v0.0.2 h1:ezvCOiafSJ9arapBAnewDU8a/r3VO6GAJywQrQs9QDU=
github.com/kubefirst/kubefirst-api v0.0.2/go.mod h1:SFnfUf9aY0sLmju1UvDGxLHL3mxGV94RzHwHrf27vsI=
github.com/kubefirst/runtime v0.3.24 h1:qXmQnn3kXmKNenY0DPn/0k6479Ydv3AZr7o7lOu9eTI=
github.com/kubefirst/runtime v0.3.24/go.mod h1:Ms1VyNgJW2thrAA+fj1V6bCN1DcbOyzIzw9Vc3WZkjg=
github.com/kubefirst/runtime v0.3.28 h1:Ac9NzqX+H0fa4tUauOMrjbtpSFnNluLYmSk6v5u++G4=
github.com/kubefirst/runtime v0.3.28/go.mod h1:9egAgF5cF594mIzra5nTB1kfE57Hr/Nvl79tjLsAWCQ=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo=
github.com/libopenstorage/openstorage v1.0.0/go.mod h1:Sp1sIObHjat1BeXhfMqLZ14wnOzEhNx2YQedreMcUyc=
Expand Down
11 changes: 9 additions & 2 deletions internal/gitShim/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ type GitInitParameters struct {

// InitializeGitProvider
func InitializeGitProvider(p *GitInitParameters) error {
progress.AddStep("Validate git environment")
cloudProvider := viper.Get("kubefirst.cloud-provider")
showProgress := cloudProvider != "k3d"

if showProgress {
progress.AddStep("Validate git environment")
}

switch p.GitProvider {
case "github":
Expand Down Expand Up @@ -114,7 +119,9 @@ func InitializeGitProvider(p *GitInitParameters) error {
}
}

progress.CompleteStep("Validate git environment")
if showProgress {
progress.CompleteStep("Validate git environment")
}

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/progress/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func createErrorLog(message string) errorMsg {
// Public Progress Functions
func DisplayLogHints(estimatedTime int) {
logFile := viper.GetString("k1-paths.log-file")
cloudProvider := viper.GetString("kubefirst.cloud-provider")
header := `
##
# Welcome to Kubefirst

### :bulb: To view verbose logs run below command in new terminal:
` + fmt.Sprintf("##### **tail -f -n +1 %s**", logFile) + `
### :blue_book: Documentation: https://docs.kubefirst.io/` + cloudProvider + `/quick-start/install/cli
### :blue_book: Documentation: https://docs.kubefirst.io/
### :family: Community Support: https://kubefirst.io/slack

### :alarm_clock: Estimated time:` + fmt.Sprintf("`%s minutes` \n\n", strconv.Itoa(estimatedTime))

Expand Down
36 changes: 24 additions & 12 deletions internal/utilities/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package utilities

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
Expand All @@ -17,9 +18,12 @@ import (
"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/progress"
"github.com/kubefirst/kubefirst/internal/types"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"go.mongodb.org/mongo-driver/bson/primitive"
v1secret "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// CreateK1ClusterDirectory
Expand Down Expand Up @@ -193,23 +197,31 @@ func CreateClusterDefinitionRecordFromRaw(gitAuth apiTypes.GitAuth, cliFlags typ
return cl
}

func CreateClusterRecordFile(clustername string, cluster apiTypes.Cluster) error {
var localFilePath = fmt.Sprintf("%s/%s.json", exportFilePath, clustername)
func ExportCluster(cluster apiTypes.Cluster, kcfg *k8s.KubernetesClient) error {
cluster.Status = "provisioned"
cluster.InProgress = false

log.Info().Msgf("creating export file %s", localFilePath)
time.Sleep(time.Second * 10)

if _, err := os.Stat(exportFilePath); os.IsNotExist(err) {
log.Info().Msgf("cluster exports directory does not exist, creating")
err := os.MkdirAll(exportFilePath, 0777)
if err != nil {
return err
}
payload, err := json.Marshal(cluster)
if err != nil {
log.Error().Msg(err.Error())
return err
}

secret := &v1secret.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "mongodb-state", Namespace: "kubefirst"},
Data: map[string][]byte{
"cluster-0": []byte(payload),
"cluster-name": []byte(cluster.ClusterName),
},
}

file, _ := json.MarshalIndent(cluster, "", " ")
_ = os.WriteFile(localFilePath, file, 0644)
err = k8s.CreateSecretV2(kcfg.Clientset, secret)

log.Info().Msgf("file created %s", localFilePath)
if err != nil {
return errors.New(fmt.Sprintf("unable to save secret to management cluster. %s", err))
}

return nil
}