diff --git a/cmd/aws/create.go b/cmd/aws/create.go index d2c25db77..a8407ffdd 100644 --- a/cmd/aws/create.go +++ b/cmd/aws/create.go @@ -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 } diff --git a/cmd/civo/create.go b/cmd/civo/create.go index 2469ec692..831c0f1f2 100644 --- a/cmd/civo/create.go +++ b/cmd/civo/create.go @@ -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 } diff --git a/cmd/digitalocean/create.go b/cmd/digitalocean/create.go index af54c20c2..a9fcd5907 100644 --- a/cmd/digitalocean/create.go +++ b/cmd/digitalocean/create.go @@ -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 } diff --git a/cmd/google/create.go b/cmd/google/create.go index c979db231..84ae9bade 100644 --- a/cmd/google/create.go +++ b/cmd/google/create.go @@ -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 } diff --git a/cmd/k3d/create.go b/cmd/k3d/create.go index 68a4381a6..408ef131e 100644 --- a/cmd/k3d/create.go +++ b/cmd/k3d/create.go @@ -25,8 +25,6 @@ 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" @@ -34,7 +32,6 @@ import ( "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" @@ -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) @@ -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 @@ -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 @@ -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) @@ -1378,25 +1358,9 @@ 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) @@ -1404,7 +1368,25 @@ func runK3d(cmd *cobra.Command, args []string) error { 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("") } diff --git a/cmd/launch.go b/cmd/launch.go index 055225c1e..a4fd7811a 100644 --- a/cmd/launch.go +++ b/cmd/launch.go @@ -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) }, diff --git a/go.mod b/go.mod index 238be2be3..271e8c184 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index f1bc9fcb7..bdb030ec4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/gitShim/init.go b/internal/gitShim/init.go index 397d54960..d0f9b26ff 100644 --- a/internal/gitShim/init.go +++ b/internal/gitShim/init.go @@ -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": @@ -114,7 +119,9 @@ func InitializeGitProvider(p *GitInitParameters) error { } } - progress.CompleteStep("Validate git environment") + if showProgress { + progress.CompleteStep("Validate git environment") + } return nil } diff --git a/internal/progress/message.go b/internal/progress/message.go index d04b78719..d87fbe20f 100644 --- a/internal/progress/message.go +++ b/internal/progress/message.go @@ -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)) diff --git a/internal/utilities/utilities.go b/internal/utilities/utilities.go index 0148a22a7..c6e5d5188 100644 --- a/internal/utilities/utilities.go +++ b/internal/utilities/utilities.go @@ -8,6 +8,7 @@ package utilities import ( "encoding/json" + "errors" "fmt" "io/ioutil" "os" @@ -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 @@ -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 }