From 5e73f60ed05485dfafb353161db0870fc9b7f721 Mon Sep 17 00:00:00 2001 From: CristhianF7 Date: Thu, 19 Oct 2023 20:01:38 -0500 Subject: [PATCH 1/3] feat: k3d new chart --- cmd/k3d/create.go | 50 ++++++--------------------------- internal/gitShim/init.go | 11 ++++++-- internal/utilities/utilities.go | 36 ++++++++++++++++-------- 3 files changed, 41 insertions(+), 56 deletions(-) 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 } From f8b02e2481e0d8eab9d187b2b2dbe8c8eeaab1fb Mon Sep 17 00:00:00 2001 From: CristhianF7 Date: Thu, 19 Oct 2023 22:25:15 -0500 Subject: [PATCH 2/3] feat: runtime bump version --- cmd/k3d/create.go | 23 ++++++++++++++++++++--- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cmd/k3d/create.go b/cmd/k3d/create.go index 07b00af6d..ba154f4ed 100644 --- a/cmd/k3d/create.go +++ b/cmd/k3d/create.go @@ -1334,7 +1334,7 @@ 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", "argo", @@ -1345,12 +1345,11 @@ func runK3d(cmd *cobra.Command, args []string) error { 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 argo workflows Deployment ready state: %s", err) return err } - progressPrinter.IncrementTracker("wrapping-up", 1) // Mark cluster install as complete telemetryShim.Transmit(useTelemetryFlag, segmentClient, segment.MetricClusterInstallCompleted, "") @@ -1370,6 +1369,24 @@ func runK3d(cmd *cobra.Command, args []string) error { viper.WriteConfig() return err } else { + 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/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= From 02c98064ded9540151b61988fe7417bdfc7aadd1 Mon Sep 17 00:00:00 2001 From: CristhianF7 Date: Fri, 20 Oct 2023 09:58:48 -0500 Subject: [PATCH 3/3] feat: bump launch version --- internal/launch/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/launch/constants.go b/internal/launch/constants.go index 438f444c0..cb56e6fa3 100644 --- a/internal/launch/constants.go +++ b/internal/launch/constants.go @@ -11,7 +11,7 @@ const ( helmChartName = "kubefirst" helmChartRepoName = "kubefirst" helmChartRepoURL = "https://charts.kubefirst.com" - helmChartVersion = "2.3.0-rc42" + helmChartVersion = "2.3.0-rc46" namespace = "kubefirst" secretName = "kubefirst-initial-secrets" )