From ccd331f18442fbc8a2f6894c830fe3db4132812e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristhian=20Fern=C3=A1ndez?= Date: Tue, 16 Jul 2024 11:48:00 -0500 Subject: [PATCH] feat: runtime migration (#368) --- {internal/configs => configs}/config.go | 1 + .../configs => configs}/kubefirstDirectory.go | 0 .../configs => configs}/kubefirstFile.go | 0 {internal/configs => configs}/viperConfig.go | 0 internal/argocd/argocd_test.go | 2 +- internal/common.go | 2 +- internal/constants.go | 2 +- internal/controller/controller.go | 6 +--- internal/env/env.go | 2 +- internal/helpers.go | 4 +-- internal/helpers_test.go | 2 +- internal/k3d/detokenize.go | 2 +- pkg/k8s/secret.go => internal/k8s/k8s.go | 32 +------------------ internal/log.go | 2 +- internal/mocks.go | 2 +- internal/progress_bar.go | 2 +- internal/router/api/v1/secrets.go | 4 +-- internal/secrets/clusters.go | 4 +-- internal/secrets/environments.go | 4 +-- internal/secrets/gitopsCatalog.go | 4 +-- internal/secrets/import.go | 4 +-- internal/secrets/reference.go | 4 +-- internal/secrets/services.go | 4 +-- internal/shell.go | 2 +- internal/utils/utils.go | 2 +- internal/validations.go | 2 +- pkg/argocd/argocd.go | 7 ++++ pkg/aws/client.go | 6 ++++ pkg/configs/configs.go | 9 ++++++ pkg/constants/constants.go | 13 ++++++++ pkg/docker/docker.go | 7 ++++ pkg/downloadManager/downloadManager.go | 6 ++++ pkg/gitClient/gitClient.go | 5 +++ pkg/github/github.go | 6 ++++ pkg/gitlab/gitlab.go | 8 +++++ pkg/k3d/k3d.go | 31 ++++++++++++++++++ pkg/k8s/client.go | 7 ++-- pkg/k8s/k8s.go | 22 +++++++++++++ pkg/k8s/types.go | 11 ------- pkg/progressPrinter/progressPrinter.go | 9 ++++++ pkg/services/services.go | 5 +++ pkg/shell/shell.go | 5 +++ pkg/ssl/ssl.go | 7 ++++ pkg/terraform/terraform.go | 6 ++++ pkg/types/kubernetes.go | 12 ------- pkg/utils/cluster.go | 4 ++- pkg/utils/helpers.go | 18 +++++++++++ pkg/vault/vault.go | 7 ++++ 48 files changed, 215 insertions(+), 91 deletions(-) rename {internal/configs => configs}/config.go (99%) rename {internal/configs => configs}/kubefirstDirectory.go (100%) rename {internal/configs => configs}/kubefirstFile.go (100%) rename {internal/configs => configs}/viperConfig.go (100%) rename pkg/k8s/secret.go => internal/k8s/k8s.go (65%) create mode 100644 pkg/argocd/argocd.go create mode 100644 pkg/configs/configs.go create mode 100644 pkg/constants/constants.go create mode 100644 pkg/docker/docker.go create mode 100644 pkg/downloadManager/downloadManager.go create mode 100644 pkg/gitClient/gitClient.go create mode 100644 pkg/github/github.go create mode 100644 pkg/gitlab/gitlab.go create mode 100644 pkg/k3d/k3d.go create mode 100644 pkg/k8s/k8s.go create mode 100644 pkg/progressPrinter/progressPrinter.go create mode 100644 pkg/services/services.go create mode 100644 pkg/shell/shell.go create mode 100644 pkg/ssl/ssl.go create mode 100644 pkg/terraform/terraform.go delete mode 100644 pkg/types/kubernetes.go create mode 100644 pkg/vault/vault.go diff --git a/internal/configs/config.go b/configs/config.go similarity index 99% rename from internal/configs/config.go rename to configs/config.go index 0383f7fb..fe87c016 100644 --- a/internal/configs/config.go +++ b/configs/config.go @@ -23,6 +23,7 @@ environment variables and general config data. */ const DefaultK1Version = "development" +const DefaultGitOpsTemplateBranch = "main" // K1Version is used on version command. The value is dynamically updated on build time via ldflag. Built Kubefirst // versions will follow semver value like 1.9.0, when not using the built version, "development" is used. diff --git a/internal/configs/kubefirstDirectory.go b/configs/kubefirstDirectory.go similarity index 100% rename from internal/configs/kubefirstDirectory.go rename to configs/kubefirstDirectory.go diff --git a/internal/configs/kubefirstFile.go b/configs/kubefirstFile.go similarity index 100% rename from internal/configs/kubefirstFile.go rename to configs/kubefirstFile.go diff --git a/internal/configs/viperConfig.go b/configs/viperConfig.go similarity index 100% rename from internal/configs/viperConfig.go rename to configs/viperConfig.go diff --git a/internal/argocd/argocd_test.go b/internal/argocd/argocd_test.go index d0bdd87e..cad2a426 100644 --- a/internal/argocd/argocd_test.go +++ b/internal/argocd/argocd_test.go @@ -11,8 +11,8 @@ import ( "net/http" "testing" + "github.com/kubefirst/kubefirst-api/configs" pkg "github.com/kubefirst/kubefirst-api/internal" - "github.com/kubefirst/kubefirst-api/internal/configs" "github.com/spf13/viper" ) diff --git a/internal/common.go b/internal/common.go index b8f8bc5d..7a35af3a 100644 --- a/internal/common.go +++ b/internal/common.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package pkg +package internal import ( "net/http" diff --git a/internal/constants.go b/internal/constants.go index 197c148c..33930c34 100644 --- a/internal/constants.go +++ b/internal/constants.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package pkg +package internal import ( "fmt" diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 3494b920..592f8ec0 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -34,10 +34,6 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" ) -const ( - gitopsTemplateVersion = "v2.4.12" -) - type ClusterController struct { CloudProvider string CloudRegion string @@ -210,7 +206,7 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition) if def.GitopsTemplateBranch != "" { clctrl.GitopsTemplateBranch = def.GitopsTemplateBranch } else { - clctrl.GitopsTemplateBranch = gitopsTemplateVersion + clctrl.GitopsTemplateBranch = env.KubefirstVersion } if def.GitopsTemplateURL != "" { diff --git a/internal/env/env.go b/internal/env/env.go index 96275158..02760f15 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -9,7 +9,7 @@ import ( type Env struct { ServerPort string `env:"SERVER_PORT" envDefault:"8081"` K1AccessToken string `env:"K1_ACCESS_TOKEN"` - KubefirstVersion string `env:"KUBEFIRST_VERSION" envDefault:"development"` + KubefirstVersion string `env:"KUBEFIRST_VERSION" envDefault:"main"` CloudProvider string `env:"CLOUD_PROVIDER"` ClusterId string `env:"CLUSTER_ID"` ClusterType string `env:"CLUSTER_TYPE"` diff --git a/internal/helpers.go b/internal/helpers.go index 292af1cd..f3b70609 100644 --- a/internal/helpers.go +++ b/internal/helpers.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package pkg +package internal import ( "errors" @@ -24,7 +24,7 @@ import ( "github.com/kubefirst/kubefirst-api/internal/progressPrinter" - "github.com/kubefirst/kubefirst-api/internal/configs" + "github.com/kubefirst/kubefirst-api/configs" "github.com/spf13/viper" ) diff --git a/internal/helpers_test.go b/internal/helpers_test.go index 3aefde19..aa13c309 100644 --- a/internal/helpers_test.go +++ b/internal/helpers_test.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package pkg +package internal import ( "fmt" diff --git a/internal/k3d/detokenize.go b/internal/k3d/detokenize.go index 75974bcc..2c84f3af 100644 --- a/internal/k3d/detokenize.go +++ b/internal/k3d/detokenize.go @@ -14,7 +14,7 @@ import ( "strconv" "strings" - "github.com/kubefirst/kubefirst-api/internal/configs" + "github.com/kubefirst/kubefirst-api/configs" ) // detokenizeGitGitops - Translate tokens by values on a given path diff --git a/pkg/k8s/secret.go b/internal/k8s/k8s.go similarity index 65% rename from pkg/k8s/secret.go rename to internal/k8s/k8s.go index eae79cdc..07473ecd 100644 --- a/pkg/k8s/secret.go +++ b/internal/k8s/k8s.go @@ -1,37 +1,15 @@ -/* -Copyright (C) 2021-2023, Kubefirst - -This program is licensed under MIT. -See the LICENSE file for more details. -*/ package k8s import ( "context" - "encoding/json" "github.com/rs/zerolog/log" - v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" ) -// CreateSecretV2 creates a Kubernetes Secret -func CreateSecretV2(clientset *kubernetes.Clientset, secret *v1.Secret) error { - _, err := clientset.CoreV1().Secrets(secret.Namespace).Create( - context.Background(), - secret, - metav1.CreateOptions{}, - ) - if err != nil { - return err - } - log.Info().Msgf("created Secret %s in Namespace %s\n", secret.Name, secret.Namespace) - return nil -} - // ReadSecretV2 reads the content of a Kubernetes Secret -func ReadSecretV2(clientset *kubernetes.Clientset, namespace string, secretName string) (map[string]interface{}, error) { +func ReadSecretV2Old(clientset *kubernetes.Clientset, namespace string, secretName string) (map[string]interface{}, error) { secret, err := clientset.CoreV1().Secrets(namespace).Get(context.Background(), secretName, metav1.GetOptions{}) if err != nil { log.Warn().Msgf("no secret found: %s\n", err) @@ -78,11 +56,3 @@ func UpdateSecretV2(clientset *kubernetes.Clientset, namespace string, secretNam log.Info().Msgf("updated Secret %s in Namespace %s\n", currentSecret.Name, currentSecret.Namespace) return nil } - -func mapToJSON(data map[string]interface{}) (string, error) { - jsonBytes, err := json.Marshal(data) - if err != nil { - return "", err // Handle error. - } - return string(jsonBytes), nil -} diff --git a/internal/log.go b/internal/log.go index cb172114..072dc2eb 100644 --- a/internal/log.go +++ b/internal/log.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package pkg +package internal import ( "os" diff --git a/internal/mocks.go b/internal/mocks.go index 86cc9429..7bf80e8c 100644 --- a/internal/mocks.go +++ b/internal/mocks.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package pkg +package internal import ( "net/http" diff --git a/internal/progress_bar.go b/internal/progress_bar.go index 11442be2..55fd5449 100644 --- a/internal/progress_bar.go +++ b/internal/progress_bar.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package pkg +package internal import ( "fmt" diff --git a/internal/router/api/v1/secrets.go b/internal/router/api/v1/secrets.go index 2ccb6f0f..8548612d 100644 --- a/internal/router/api/v1/secrets.go +++ b/internal/router/api/v1/secrets.go @@ -11,10 +11,10 @@ import ( "net/http" "github.com/gin-gonic/gin" + "github.com/kubefirst/kubefirst-api/internal/k8s" "github.com/kubefirst/kubefirst-api/internal/secrets" "github.com/kubefirst/kubefirst-api/internal/types" "github.com/kubefirst/kubefirst-api/internal/utils" - "github.com/kubefirst/kubefirst-api/pkg/k8s" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -37,7 +37,7 @@ func GetClusterSecret(c *gin.Context) { } kcfg := utils.GetKubernetesClient(clusterName) - kubefirstSecrets, _ := k8s.ReadSecretV2(kcfg.Clientset, "kubefirst", secret) + kubefirstSecrets, _ := k8s.ReadSecretV2Old(kcfg.Clientset, "kubefirst", secret) jsonString, err := secrets.MapToStructuredJSON(kubefirstSecrets) diff --git a/internal/secrets/clusters.go b/internal/secrets/clusters.go index 6f002e23..66ac3d31 100644 --- a/internal/secrets/clusters.go +++ b/internal/secrets/clusters.go @@ -10,7 +10,7 @@ import ( "encoding/json" "fmt" - "github.com/kubefirst/kubefirst-api/pkg/k8s" + "github.com/kubefirst/kubefirst-api/internal/k8s" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" log "github.com/rs/zerolog/log" v1 "k8s.io/api/core/v1" @@ -42,7 +42,7 @@ func DeleteCluster(clientSet *kubernetes.Clientset, clusterName string) error { func GetCluster(clientSet *kubernetes.Clientset, clusterName string) (pkgtypes.Cluster, error) { cluster := pkgtypes.Cluster{} - clusterSecret, err := k8s.ReadSecretV2(clientSet, "kubefirst", fmt.Sprintf("%s-%s", KUBEFIRST_CLUSTER_PREFIX, clusterName)) + clusterSecret, err := k8s.ReadSecretV2Old(clientSet, "kubefirst", fmt.Sprintf("%s-%s", KUBEFIRST_CLUSTER_PREFIX, clusterName)) if err != nil { return cluster, fmt.Errorf("secret not found: %s", err) } diff --git a/internal/secrets/environments.go b/internal/secrets/environments.go index fe688d85..7959118b 100644 --- a/internal/secrets/environments.go +++ b/internal/secrets/environments.go @@ -4,8 +4,8 @@ import ( "encoding/json" "fmt" + "github.com/kubefirst/kubefirst-api/internal/k8s" "github.com/kubefirst/kubefirst-api/internal/types" - "github.com/kubefirst/kubefirst-api/pkg/k8s" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" log "github.com/rs/zerolog/log" "go.mongodb.org/mongo-driver/bson/primitive" @@ -35,7 +35,7 @@ func GetEnvironments(clientSet *kubernetes.Clientset) ([]pkgtypes.Environment, e func GetEnvironment(clientSet *kubernetes.Clientset, name string) (pkgtypes.Environment, error) { environment := pkgtypes.Environment{} - kubefirstSecrets, _ := k8s.ReadSecretV2(clientSet, "kubefirst", fmt.Sprintf("%s-%s", KUBEFIRST_ENVIRONMENT_PREFIX, name)) + kubefirstSecrets, _ := k8s.ReadSecretV2Old(clientSet, "kubefirst", fmt.Sprintf("%s-%s", KUBEFIRST_ENVIRONMENT_PREFIX, name)) jsonString, _ := MapToStructuredJSON(kubefirstSecrets) jsonData, err := json.Marshal(jsonString) diff --git a/internal/secrets/gitopsCatalog.go b/internal/secrets/gitopsCatalog.go index fd087e36..216c5524 100644 --- a/internal/secrets/gitopsCatalog.go +++ b/internal/secrets/gitopsCatalog.go @@ -11,7 +11,7 @@ import ( "fmt" "github.com/kubefirst/kubefirst-api/internal/gitopsCatalog" - "github.com/kubefirst/kubefirst-api/pkg/k8s" + "github.com/kubefirst/kubefirst-api/internal/k8s" "github.com/kubefirst/kubefirst-api/pkg/types" log "github.com/rs/zerolog/log" "golang.org/x/exp/slices" @@ -48,7 +48,7 @@ func CreateGitopsCatalogApps(clientSet *kubernetes.Clientset, catalogApps types. func GetGitopsCatalogApps(clientSet *kubernetes.Clientset) (types.GitopsCatalogApps, error) { catalogApps := types.GitopsCatalogApps{} - kubefirstSecrets, err := k8s.ReadSecretV2(clientSet, "kubefirst", KUBEFIRST_CATALOG_SECRET_NAME) + kubefirstSecrets, err := k8s.ReadSecretV2Old(clientSet, "kubefirst", KUBEFIRST_CATALOG_SECRET_NAME) if err != nil { return catalogApps, err } diff --git a/internal/secrets/import.go b/internal/secrets/import.go index 3bdf41e2..9a6d87ee 100644 --- a/internal/secrets/import.go +++ b/internal/secrets/import.go @@ -12,7 +12,7 @@ import ( "github.com/kubefirst/kubefirst-api/internal/constants" "github.com/kubefirst/kubefirst-api/internal/env" - "github.com/kubefirst/kubefirst-api/pkg/k8s" + "github.com/kubefirst/kubefirst-api/internal/k8s" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" "github.com/rs/zerolog/log" ) @@ -34,7 +34,7 @@ func ImportClusterIfEmpty(silent bool) (pkgtypes.Cluster, error) { kcfg := k8s.CreateKubeConfig(true, "") log.Info().Msg("reading secret kubefirst-initial-state to determine if import is needed") - secData, err := k8s.ReadSecretV2(kcfg.Clientset, "kubefirst", "kubefirst-initial-state") + secData, err := k8s.ReadSecretV2Old(kcfg.Clientset, "kubefirst", "kubefirst-initial-state") if err != nil { log.Info().Msgf("error reading secret kubefirst-initial-state. %s", err) return cluster, err diff --git a/internal/secrets/reference.go b/internal/secrets/reference.go index 732be95c..6fa6f197 100644 --- a/internal/secrets/reference.go +++ b/internal/secrets/reference.go @@ -10,7 +10,7 @@ import ( "encoding/json" "fmt" - "github.com/kubefirst/kubefirst-api/pkg/k8s" + "github.com/kubefirst/kubefirst-api/internal/k8s" pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -20,7 +20,7 @@ import ( func GetSecretReference(clientSet *kubernetes.Clientset, secretName string) (pkgtypes.SecretListReference, error) { secretReference := pkgtypes.SecretListReference{} - kubefirstSecrets, err := k8s.ReadSecretV2(clientSet, "kubefirst", secretName) + kubefirstSecrets, err := k8s.ReadSecretV2Old(clientSet, "kubefirst", secretName) if err != nil { return secretReference, fmt.Errorf("secret not found: %s", err) } diff --git a/internal/secrets/services.go b/internal/secrets/services.go index 68a86cec..f273615a 100644 --- a/internal/secrets/services.go +++ b/internal/secrets/services.go @@ -10,7 +10,7 @@ import ( "encoding/json" "fmt" - "github.com/kubefirst/kubefirst-api/pkg/k8s" + "github.com/kubefirst/kubefirst-api/internal/k8s" "github.com/kubefirst/kubefirst-api/pkg/types" log "github.com/rs/zerolog/log" v1 "k8s.io/api/core/v1" @@ -97,7 +97,7 @@ func GetService(clientSet *kubernetes.Clientset, clusterName string, serviceName func GetServices(clientSet *kubernetes.Clientset, clusterName string) (types.ClusterServiceList, error) { clusterServices := types.ClusterServiceList{} - kubefirstSecrets, err := k8s.ReadSecretV2(clientSet, "kubefirst", fmt.Sprintf("%s-%s", KUBEFIRST_SERVICES_PREFIX, clusterName)) + kubefirstSecrets, err := k8s.ReadSecretV2Old(clientSet, "kubefirst", fmt.Sprintf("%s-%s", KUBEFIRST_SERVICES_PREFIX, clusterName)) jsonString, err := MapToStructuredJSON(kubefirstSecrets) diff --git a/internal/shell.go b/internal/shell.go index 755046df..3a6c085f 100644 --- a/internal/shell.go +++ b/internal/shell.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package pkg +package internal import ( "bufio" diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 1c66aab5..931f5d4d 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -16,8 +16,8 @@ import ( "github.com/kubefirst/kubefirst-api/internal/constants" "github.com/kubefirst/kubefirst-api/internal/env" + "github.com/kubefirst/kubefirst-api/internal/k8s" "github.com/kubefirst/kubefirst-api/internal/secrets" - "github.com/kubefirst/kubefirst-api/pkg/k8s" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" diff --git a/internal/validations.go b/internal/validations.go index 06c4299d..7ce385e1 100644 --- a/internal/validations.go +++ b/internal/validations.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package pkg +package internal import "syscall" diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go new file mode 100644 index 00000000..adb27c8f --- /dev/null +++ b/pkg/argocd/argocd.go @@ -0,0 +1,7 @@ +package argocd + +import "github.com/kubefirst/kubefirst-api/internal/argocd" + +var ArgocdSecretClient = argocd.ArgocdSecretClient +var GetArgocdTokenV2 = argocd.GetArgocdTokenV2 +var GetArgoCDApplicationObject = argocd.GetArgoCDApplicationObject diff --git a/pkg/aws/client.go b/pkg/aws/client.go index c9ba9d4c..cf2a146c 100644 --- a/pkg/aws/client.go +++ b/pkg/aws/client.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" + awsinternal "github.com/kubefirst/kubefirst-api/internal/aws" "github.com/rs/zerolog/log" ) @@ -39,3 +40,8 @@ func NewEKSServiceAccountClientV1() aws.Config { return awsClient } + +type AWSConfiguration = awsinternal.AWSConfiguration +type QuotaDetailResponse = awsinternal.QuotaDetailResponse + +var NewAwsV2 = awsinternal.NewAwsV2 diff --git a/pkg/configs/configs.go b/pkg/configs/configs.go new file mode 100644 index 00000000..2b773133 --- /dev/null +++ b/pkg/configs/configs.go @@ -0,0 +1,9 @@ +package configs + +import "github.com/kubefirst/kubefirst-api/configs" + +const DefaultK1Version = configs.DefaultK1Version + +var K1Version = configs.K1Version +var ReadConfig = configs.ReadConfig +var InitializeViperConfig = configs.InitializeViperConfig diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go new file mode 100644 index 00000000..09baa84f --- /dev/null +++ b/pkg/constants/constants.go @@ -0,0 +1,13 @@ +package constants + +import internal "github.com/kubefirst/kubefirst-api/internal" + +const MinimumAvailableDiskSize = internal.MinimumAvailableDiskSize +const MinioDefaultUsername = internal.MinioDefaultUsername +const MinioDefaultPassword = internal.MinioDefaultPassword +const KubefirstManifestRepoRef = internal.KubefirstManifestRepoRef +const MinioPortForwardEndpoint = internal.MinioPortForwardEndpoint +const MinioRegion = internal.MinioRegion + +var ArgoCDLocalURLTLS = internal.ArgoCDLocalURLTLS +var KubefirstConsoleLocalURLTLS = internal.KubefirstConsoleLocalURLTLS diff --git a/pkg/docker/docker.go b/pkg/docker/docker.go new file mode 100644 index 00000000..7a5844d3 --- /dev/null +++ b/pkg/docker/docker.go @@ -0,0 +1,7 @@ +package docker + +import internal "github.com/kubefirst/kubefirst-api/internal/docker" + +type DockerClientWrapper = internal.DockerClientWrapper + +var NewDockerClient = internal.NewDockerClient diff --git a/pkg/downloadManager/downloadManager.go b/pkg/downloadManager/downloadManager.go new file mode 100644 index 00000000..eee9f8a3 --- /dev/null +++ b/pkg/downloadManager/downloadManager.go @@ -0,0 +1,6 @@ +package downloadManager + +import internal "github.com/kubefirst/kubefirst-api/internal/downloadManager" + +var DownloadFile = internal.DownloadFile +var ExtractFileFromTarGz = internal.ExtractFileFromTarGz diff --git a/pkg/gitClient/gitClient.go b/pkg/gitClient/gitClient.go new file mode 100644 index 00000000..0822b731 --- /dev/null +++ b/pkg/gitClient/gitClient.go @@ -0,0 +1,5 @@ +package gitClient + +import "github.com/kubefirst/kubefirst-api/internal/gitClient" + +var Commit = gitClient.Commit diff --git a/pkg/github/github.go b/pkg/github/github.go new file mode 100644 index 00000000..3ba9900c --- /dev/null +++ b/pkg/github/github.go @@ -0,0 +1,6 @@ +package github + +import internal "github.com/kubefirst/kubefirst-api/internal/github" + +var VerifyTokenPermissions = internal.VerifyTokenPermissions +var New = internal.New diff --git a/pkg/gitlab/gitlab.go b/pkg/gitlab/gitlab.go new file mode 100644 index 00000000..e96d6f1d --- /dev/null +++ b/pkg/gitlab/gitlab.go @@ -0,0 +1,8 @@ +package gitlab + +import internal "github.com/kubefirst/kubefirst-api/internal/gitlab" + +type DeployTokenCreateParameters = internal.DeployTokenCreateParameters + +var VerifyTokenPermissions = internal.VerifyTokenPermissions +var NewGitLabClient = internal.NewGitLabClient diff --git a/pkg/k3d/k3d.go b/pkg/k3d/k3d.go new file mode 100644 index 00000000..6e44eeac --- /dev/null +++ b/pkg/k3d/k3d.go @@ -0,0 +1,31 @@ +package k3d + +import internal "github.com/kubefirst/kubefirst-api/internal/k3d" + +const DomainName = internal.DomainName +const GithubHost = internal.GithubHost +const GitlabHost = internal.GitlabHost +const K3dVersion = internal.K3dVersion +const LocalhostOS = internal.LocalhostOS +const LocalhostARCH = internal.LocalhostARCH +const CloudProvider = internal.CloudProvider +const VaultPortForwardURL = internal.VaultPortForwardURL + +type GitopsDirectoryValues = internal.GitopsDirectoryValues +type MetaphorTokenValues = internal.MetaphorTokenValues + +var GetConfig = internal.GetConfig +var PrepareGitRepositories = internal.PrepareGitRepositories +var GetGithubTerraformEnvs = internal.GetGithubTerraformEnvs +var ClusterCreate = internal.ClusterCreate +var GenerateTLSSecrets = internal.GenerateTLSSecrets +var AddK3DSecrets = internal.AddK3DSecrets +var ArgocdURL = internal.ArgocdURL +var VaultURL = internal.VaultURL +var PostRunPrepareGitopsRepository = internal.PostRunPrepareGitopsRepository +var DownloadTools = internal.DownloadTools +var ResolveMinioLocal = internal.ResolveMinioLocal +var DeleteK3dCluster = internal.DeleteK3dCluster +var GenerateSingleTLSSecret = internal.GenerateSingleTLSSecret + +var ClusterCreateConsoleAPI = internal.ClusterCreateConsoleAPI diff --git a/pkg/k8s/client.go b/pkg/k8s/client.go index eb508cce..23519960 100644 --- a/pkg/k8s/client.go +++ b/pkg/k8s/client.go @@ -11,6 +11,7 @@ import ( "os" "path/filepath" + "github.com/kubefirst/kubefirst-api/internal/k8s" log "github.com/rs/zerolog/log" "github.com/spf13/afero" "k8s.io/client-go/kubernetes" @@ -23,7 +24,7 @@ var fs afero.Fs = afero.NewOsFs() // CreateKubeConfig returns a struct KubernetesClient with references to a clientset, // restConfig, and path to the Kubernetes config used to generate the client -func CreateKubeConfig(inCluster bool, kubeConfigPath string) *KubernetesClient { +func CreateKubeConfigOld(inCluster bool, kubeConfigPath string) *k8s.KubernetesClient { // inCluster is either true or false // If it's true, we pull Kubernetes API authentication from Pod SA // If it's false, we use local machine settings @@ -38,7 +39,7 @@ func CreateKubeConfig(inCluster bool, kubeConfigPath string) *KubernetesClient { log.Error().Msgf("error creating kubernetes client: %s", err) } - return &KubernetesClient{ + return &k8s.KubernetesClient{ Clientset: clientset, RestConfig: config, KubeConfigPath: "in-cluster", @@ -60,7 +61,7 @@ func CreateKubeConfig(inCluster bool, kubeConfigPath string) *KubernetesClient { log.Error().Msgf("error creating kubernetes client: %s", err) } - return &KubernetesClient{ + return &k8s.KubernetesClient{ Clientset: clientset, RestConfig: config, KubeConfigPath: kubeconfig, diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go new file mode 100644 index 00000000..92236396 --- /dev/null +++ b/pkg/k8s/k8s.go @@ -0,0 +1,22 @@ +package k8s + +import internal "github.com/kubefirst/kubefirst-api/internal/k8s" + +type KubernetesClient = internal.KubernetesClient + +var CheckForExistingPortForwards = internal.CheckForExistingPortForwards + +var CreateKubeConfig = internal.CreateKubeConfig +var ReturnDeploymentObject = internal.ReturnDeploymentObject +var WaitForDeploymentReady = internal.WaitForDeploymentReady +var VerifyArgoCDReadiness = internal.VerifyArgoCDReadiness +var GetSecretValue = internal.GetSecretValue +var OpenPortForwardPodWrapper = internal.OpenPortForwardPodWrapper +var ReturnStatefulSetObject = internal.ReturnStatefulSetObject +var WaitForStatefulSetReady = internal.WaitForStatefulSetReady +var ReturnJobObject = internal.ReturnJobObject +var WaitForJobComplete = internal.WaitForJobComplete + +var ReadSecretV2 = internal.ReadSecretV2 +var ReadService = internal.ReadService +var CreateSecretV2 = internal.CreateSecretV2 diff --git a/pkg/k8s/types.go b/pkg/k8s/types.go index d6739bcd..d9af634c 100644 --- a/pkg/k8s/types.go +++ b/pkg/k8s/types.go @@ -1,10 +1,5 @@ package k8s -import ( - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" -) - type UpdateSecretArgs struct { ConsoleTour string `json:"console-tour"` } @@ -12,9 +7,3 @@ type UpdateSecretArgs struct { type CloudAccountsArgs struct { CloudAccounts string `json:"cloud_accounts"` } - -type KubernetesClient struct { - Clientset *kubernetes.Clientset - RestConfig *rest.Config - KubeConfigPath string -} diff --git a/pkg/progressPrinter/progressPrinter.go b/pkg/progressPrinter/progressPrinter.go new file mode 100644 index 00000000..8686d216 --- /dev/null +++ b/pkg/progressPrinter/progressPrinter.go @@ -0,0 +1,9 @@ +package progressPrinter + +import internal "github.com/kubefirst/kubefirst-api/internal/progressPrinter" + +var IncrementTracker = internal.IncrementTracker +var AddTracker = internal.AddTracker +var SetupProgress = internal.SetupProgress +var TotalOfTrackers = internal.TotalOfTrackers +var GetInstance = internal.GetInstance diff --git a/pkg/services/services.go b/pkg/services/services.go new file mode 100644 index 00000000..350d4533 --- /dev/null +++ b/pkg/services/services.go @@ -0,0 +1,5 @@ +package services + +import internal "github.com/kubefirst/kubefirst-api/internal/services" + +var NewGitHubService = internal.NewGitHubService diff --git a/pkg/shell/shell.go b/pkg/shell/shell.go new file mode 100644 index 00000000..6a8c2d84 --- /dev/null +++ b/pkg/shell/shell.go @@ -0,0 +1,5 @@ +package shell + +import internal "github.com/kubefirst/kubefirst-api/internal" + +var ExecShellReturnStrings = internal.ExecShellReturnStrings diff --git a/pkg/ssl/ssl.go b/pkg/ssl/ssl.go new file mode 100644 index 00000000..bf557e4f --- /dev/null +++ b/pkg/ssl/ssl.go @@ -0,0 +1,7 @@ +package ssl + +import ( + internal "github.com/kubefirst/kubefirst-api/internal/ssl" +) + +var Backup = internal.Backup diff --git a/pkg/terraform/terraform.go b/pkg/terraform/terraform.go new file mode 100644 index 00000000..3308fbd2 --- /dev/null +++ b/pkg/terraform/terraform.go @@ -0,0 +1,6 @@ +package terraform + +import internal "github.com/kubefirst/kubefirst-api/internal/terraform" + +var InitApplyAutoApprove = internal.InitApplyAutoApprove +var InitDestroyAutoApprove = internal.InitDestroyAutoApprove diff --git a/pkg/types/kubernetes.go b/pkg/types/kubernetes.go deleted file mode 100644 index 90cffc48..00000000 --- a/pkg/types/kubernetes.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -import ( - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" -) - -type KubernetesClient struct { - Clientset *kubernetes.Clientset - RestConfig *rest.Config - KubeConfigPath string -} diff --git a/pkg/utils/cluster.go b/pkg/utils/cluster.go index 1012de49..f3947813 100644 --- a/pkg/utils/cluster.go +++ b/pkg/utils/cluster.go @@ -12,7 +12,9 @@ import ( "time" pkg "github.com/kubefirst/kubefirst-api/internal" + "github.com/kubefirst/kubefirst-api/internal/k8s" "github.com/kubefirst/kubefirst-api/pkg/types" + "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" "github.com/rs/zerolog/log" @@ -66,7 +68,7 @@ func PutClusterObject(cr *types.StateStoreCredentials, d *types.StateStoreDetail } // ExportCluster proxy to kubefirst api /cluster/import to restore the database -func ExportCluster(kcfg types.KubernetesClient, cl types.Cluster) error { +func ExportCluster(kcfg k8s.KubernetesClient, cl types.Cluster) error { time.Sleep(time.Second * 10) err := pkg.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", pkg.KubefirstConsoleLocalURLCloud), "kubefirst api") diff --git a/pkg/utils/helpers.go b/pkg/utils/helpers.go index 1e74713b..da3c8432 100644 --- a/pkg/utils/helpers.go +++ b/pkg/utils/helpers.go @@ -3,6 +3,9 @@ package pkg import ( "math/rand" "time" + + internal "github.com/kubefirst/kubefirst-api/internal" + helpers "github.com/kubefirst/kubefirst-api/internal/helpers" ) func randSeq(n int) string { @@ -18,3 +21,18 @@ func Random(seq int) string { rand.Seed(time.Now().UnixNano()) return randSeq(seq) } + +// internal exports +var IsAppAvailable = internal.IsAppAvailable +var GenerateClusterID = internal.GenerateClusterID +var GetAvailableDiskSize = internal.GetAvailableDiskSize +var OpenBrowser = internal.OpenBrowser +var ResetK1Dir = internal.ResetK1Dir +var SetupViper = internal.SetupViper +var OpenLogFile = internal.OpenLogFile + +// helper exports +var DisplayLogHints = helpers.DisplayLogHints +var TestEndpointTLS = helpers.TestEndpointTLS +var SetClusterStatusFlags = helpers.SetClusterStatusFlags +var GetClusterStatusFlags = helpers.GetClusterStatusFlags diff --git a/pkg/vault/vault.go b/pkg/vault/vault.go new file mode 100644 index 00000000..2337591b --- /dev/null +++ b/pkg/vault/vault.go @@ -0,0 +1,7 @@ +package vault + +import internal "github.com/kubefirst/kubefirst-api/internal/vault" + +type VaultConfiguration = internal.VaultConfiguration + +var NewVault = internal.NewVault