diff --git a/cmd/k3d/create.go b/cmd/k3d/create.go index 68a4381a6..07b00af6d 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" @@ -176,7 +174,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 @@ -1339,35 +1337,19 @@ func runK3d(cmd *cobra.Command, args []string) error { consoleDeployment, 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) 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 @@ -1378,25 +1360,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) - - 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, - } + cluster := utilities.CreateClusterRecordFromRaw(useTelemetryFlag, cGitOwner, cGitUser, cGitToken, cGitlabOwnerGroupID, gitopsTemplateURLFlag, gitopsTemplateBranchFlag) - 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 +1370,7 @@ func runK3d(cmd *cobra.Command, args []string) error { viper.WriteConfig() return err } else { - err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLCloud) + err = pkg.OpenBrowser(pkg.KubefirstConsoleLocalURLTLS) if err != nil { log.Error().Err(err).Msg("") } 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/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 }