diff --git a/cmd/akamai/command.go b/cmd/akamai/command.go index 167a86197..f3e4566e6 100644 --- a/cmd/akamai/command.go +++ b/cmd/akamai/command.go @@ -54,7 +54,7 @@ func NewCommand() *cobra.Command { Use: "akamai", Short: "kubefirst akamai installation", Long: "kubefirst akamai", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println("To learn more about akamai in kubefirst, run:") fmt.Println(" kubefirst beta akamai --help") diff --git a/cmd/akamai/create.go b/cmd/akamai/create.go index b4e23a51f..9179beec3 100644 --- a/cmd/akamai/create.go +++ b/cmd/akamai/create.go @@ -25,7 +25,7 @@ import ( "github.com/spf13/viper" ) -func createAkamai(cmd *cobra.Command, args []string) error { +func createAkamai(cmd *cobra.Command, _ []string) error { cliFlags, err := utilities.GetFlags(cmd, "akamai") if err != nil { progress.Error(err.Error()) @@ -82,7 +82,7 @@ func createAkamai(cmd *cobra.Command, args []string) error { launch.Up(nil, true, cliFlags.UseTelemetry) } - err = pkg.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresUrl()), "kubefirst api") + err = pkg.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresURL()), "kubefirst api") if err != nil { progress.Error("unable to start kubefirst api") return fmt.Errorf("kubefirst api is unavailable: %w", err) diff --git a/cmd/aws/command.go b/cmd/aws/command.go index bdf801290..f011c82a2 100644 --- a/cmd/aws/command.go +++ b/cmd/aws/command.go @@ -49,7 +49,7 @@ func NewCommand() *cobra.Command { Use: "aws", Short: "kubefirst aws installation", Long: "kubefirst aws", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println("To learn more about aws in kubefirst, run:") fmt.Println(" kubefirst help") diff --git a/cmd/aws/create.go b/cmd/aws/create.go index 4c9a00ef6..a19203af0 100644 --- a/cmd/aws/create.go +++ b/cmd/aws/create.go @@ -27,7 +27,7 @@ import ( "github.com/spf13/viper" ) -func createAws(cmd *cobra.Command, args []string) error { +func createAws(cmd *cobra.Command, _ []string) error { cliFlags, err := utilities.GetFlags(cmd, "aws") if err != nil { progress.Error(err.Error()) @@ -118,7 +118,7 @@ func createAws(cmd *cobra.Command, args []string) error { launch.Up(nil, true, cliFlags.UseTelemetry) } - err = pkg.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresUrl()), "kubefirst api") + err = pkg.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresURL()), "kubefirst api") if err != nil { progress.Error("unable to start kubefirst api") return fmt.Errorf("failed to check kubefirst API availability: %w", err) diff --git a/cmd/beta.go b/cmd/beta.go index 395311dac..9afd9155a 100644 --- a/cmd/beta.go +++ b/cmd/beta.go @@ -22,7 +22,7 @@ var betaCmd = &cobra.Command{ Use: "beta", Short: "access Kubefirst beta features", Long: `access Kubefirst beta features`, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println("To learn more about Kubefirst, run:") fmt.Println(" kubefirst help") diff --git a/cmd/civo/backup.go b/cmd/civo/backup.go index 74d37e685..c6694f659 100644 --- a/cmd/civo/backup.go +++ b/cmd/civo/backup.go @@ -18,7 +18,7 @@ import ( "github.com/spf13/viper" ) -func backupCivoSSL(cmd *cobra.Command, _ []string) error { +func backupCivoSSL(_ *cobra.Command, _ []string) error { utils.DisplayLogHints() clusterName := viper.GetString("flags.cluster-name") diff --git a/cmd/civo/command.go b/cmd/civo/command.go index 1c09088a8..2ea8bbc78 100644 --- a/cmd/civo/command.go +++ b/cmd/civo/command.go @@ -54,7 +54,7 @@ func NewCommand() *cobra.Command { Use: "civo", Short: "Kubefirst Civo installation", Long: "Kubefirst Civo", - Run: func(cmd *cobra.Command, _ []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println("To learn more about Civo in Kubefirst, run:") fmt.Println(" kubefirst civo --help") diff --git a/cmd/civo/create.go b/cmd/civo/create.go index d59699eeb..d6ad36d96 100644 --- a/cmd/civo/create.go +++ b/cmd/civo/create.go @@ -25,7 +25,7 @@ import ( "github.com/spf13/viper" ) -func createCivo(cmd *cobra.Command, args []string) error { +func createCivo(cmd *cobra.Command, _ []string) error { cliFlags, err := utilities.GetFlags(cmd, "civo") if err != nil { progress.Error(err.Error()) @@ -87,7 +87,7 @@ func createCivo(cmd *cobra.Command, args []string) error { launch.Up(nil, true, cliFlags.UseTelemetry) } - err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresUrl()), "kubefirst api") + err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresURL()), "kubefirst api") if err != nil { progress.Error("unable to start kubefirst api") return fmt.Errorf("API availability check failed: %w", err) diff --git a/cmd/civo/quota.go b/cmd/civo/quota.go index a5d129d6d..e171f2fe0 100644 --- a/cmd/civo/quota.go +++ b/cmd/civo/quota.go @@ -165,7 +165,7 @@ func printCivoQuotaWarning(messageHeader string, output []string) string { } // evalCivoQuota provides an interface to the command-line -func evalCivoQuota(cmd *cobra.Command, args []string) error { +func evalCivoQuota(cmd *cobra.Command, _ []string) error { civoToken := os.Getenv("CIVO_TOKEN") if len(civoToken) == 0 { return fmt.Errorf("your CIVO_TOKEN environment variable isn't set, visit this link https://dashboard.civo.com/security and set CIVO_TOKEN") diff --git a/cmd/digitalocean/command.go b/cmd/digitalocean/command.go index 3ab8a3f07..2ca962a05 100644 --- a/cmd/digitalocean/command.go +++ b/cmd/digitalocean/command.go @@ -54,7 +54,7 @@ func NewCommand() *cobra.Command { Use: "digitalocean", Short: "Kubefirst DigitalOcean installation", Long: "Kubefirst DigitalOcean", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println("To learn more about DigitalOcean in Kubefirst, run:") fmt.Println(" kubefirst digitalocean --help") diff --git a/cmd/digitalocean/create.go b/cmd/digitalocean/create.go index 3c705b0f0..a600c6199 100644 --- a/cmd/digitalocean/create.go +++ b/cmd/digitalocean/create.go @@ -26,7 +26,7 @@ import ( "github.com/spf13/viper" ) -func createDigitalocean(cmd *cobra.Command, args []string) error { +func createDigitalocean(cmd *cobra.Command, _ []string) error { cliFlags, err := utilities.GetFlags(cmd, "digitalocean") if err != nil { progress.Error(err.Error()) @@ -96,7 +96,7 @@ func createDigitalocean(cmd *cobra.Command, args []string) error { launch.Up(nil, true, cliFlags.UseTelemetry) } - err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresUrl()), "kubefirst api") + err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresURL()), "kubefirst api") if err != nil { progress.Error("unable to start kubefirst api") return fmt.Errorf("failed to check app availability for Kubefirst API: %w", err) diff --git a/cmd/google/command.go b/cmd/google/command.go index 009e0e30b..bed2ddc20 100644 --- a/cmd/google/command.go +++ b/cmd/google/command.go @@ -57,7 +57,7 @@ func NewCommand() *cobra.Command { Use: "google", Short: "kubefirst Google installation", Long: "kubefirst google", - Run: func(cmd *cobra.Command, _ []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println("To learn more about google in kubefirst, run:") fmt.Println(" kubefirst beta google --help") diff --git a/cmd/google/create.go b/cmd/google/create.go index 087eb928f..00fd53dc2 100644 --- a/cmd/google/create.go +++ b/cmd/google/create.go @@ -23,10 +23,10 @@ import ( "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" - _ "k8s.io/client-go/plugin/pkg/client/auth" + _ "k8s.io/client-go/plugin/pkg/client/auth" // required for authentication ) -func createGoogle(cmd *cobra.Command, args []string) error { +func createGoogle(cmd *cobra.Command, _ []string) error { cliFlags, err := utilities.GetFlags(cmd, "google") if err != nil { progress.Error(err.Error()) @@ -89,7 +89,7 @@ func createGoogle(cmd *cobra.Command, args []string) error { launch.Up(nil, true, cliFlags.UseTelemetry) } - err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresUrl()), "kubefirst api") + err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresURL()), "kubefirst api") if err != nil { progress.Error("unable to start kubefirst api") return fmt.Errorf("kubefirst api availability check failed: %w", err) diff --git a/cmd/info.go b/cmd/info.go index 5b6cc2e4e..8581cd3f2 100755 --- a/cmd/info.go +++ b/cmd/info.go @@ -22,7 +22,7 @@ var infoCmd = &cobra.Command{ Use: "info", Short: "provides general Kubefirst setup data", Long: `Provides machine data, files and folders paths`, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { config := configs.ReadConfig() var buf bytes.Buffer diff --git a/cmd/k3d/command.go b/cmd/k3d/command.go index 13bc7422d..5417f7678 100644 --- a/cmd/k3d/command.go +++ b/cmd/k3d/command.go @@ -48,7 +48,7 @@ func NewCommand() *cobra.Command { Use: "k3d", Short: "kubefirst k3d installation", Long: "kubefirst k3d", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println("To learn more about k3d in kubefirst, run:") fmt.Println(" kubefirst k3d --help") diff --git a/cmd/k3d/create.go b/cmd/k3d/create.go index 1d55f5965..f70fefb4a 100644 --- a/cmd/k3d/create.go +++ b/cmd/k3d/create.go @@ -56,7 +56,8 @@ import ( "k8s.io/apimachinery/pkg/util/wait" ) -func runK3d(cmd *cobra.Command, args []string) error { +//nolint:gocyclo // this function is complex and needs to be refactored +func runK3d(cmd *cobra.Command, _ []string) error { ciFlag, err := cmd.Flags().GetBool("ci") if err != nil { return fmt.Errorf("failed to get 'ci' flag: %w", err) @@ -121,8 +122,12 @@ func runK3d(cmd *cobra.Command, args []string) error { utils.DisplayLogHints() isValid, catalogApps, err := catalog.ValidateCatalogApps(installCatalogAppsFlag) + if err != nil { + return fmt.Errorf("failed to validate catalog apps: %w", err) + } + if !isValid { - return err + return errors.New("catalog apps validation failed") } switch gitProviderFlag { @@ -271,14 +276,14 @@ func runK3d(cmd *cobra.Command, args []string) error { var sshPrivateKey, sshPublicKey string // todo placed in configmap in kubefirst namespace, included in telemetry - clusterId := viper.GetString("kubefirst.cluster-id") - if clusterId == "" { - clusterId = utils.GenerateClusterID() - viper.Set("kubefirst.cluster-id", clusterId) + clusterID := viper.GetString("kubefirst.cluster-id") + if clusterID == "" { + clusterID = utils.GenerateClusterID() + viper.Set("kubefirst.cluster-id", clusterID) viper.WriteConfig() } - segClient, err := segment.InitClient(clusterId, clusterTypeFlag, gitProviderFlag) + segClient, err := segment.InitClient(clusterID, clusterTypeFlag, gitProviderFlag) if err != nil { return fmt.Errorf("failed to initialize segment client: %w", err) } @@ -438,7 +443,7 @@ func runK3d(cmd *cobra.Command, args []string) error { KubeconfigPath: config.Kubeconfig, GitopsRepoURL: gitopsRepoURL, GitProvider: config.GitProvider, - ClusterId: clusterId, + ClusterId: clusterID, CloudProvider: k3d.CloudProvider, } @@ -642,7 +647,7 @@ func runK3d(cmd *cobra.Command, args []string) error { msg := fmt.Errorf("error pushing detokenized gitops repository to remote %q: %w", config.DestinationGitopsRepoGitURL, err) telemetry.SendEvent(segClient, telemetry.GitopsRepoPushFailed, msg.Error()) if !strings.Contains(msg.Error(), "already up-to-date") { - log.Printf(msg.Error()) + log.Print(msg.Error()) return msg } } @@ -867,12 +872,12 @@ func runK3d(cmd *cobra.Command, args []string) error { ) + ":8080" argoCDToken, err = argocd.GetArgocdTokenV2(httpClient, argoCDHTTPURL, "admin", argocdPassword) if err != nil { - return err + return fmt.Errorf("failed to get ArgoCD token: %w", err) } } else { argoCDToken, err = argocd.GetArgocdTokenV2(httpClient, k3d.ArgocdURL, "admin", argocdPassword) if err != nil { - return err + return fmt.Errorf("failed to get ArgoCD token: %w", err) } } @@ -1228,41 +1233,41 @@ func runK3d(cmd *cobra.Command, args []string) error { viper.Set("kubefirst-checks.cluster-install-complete", false) viper.WriteConfig() return fmt.Errorf("failed to export cluster object: %w", err) - } else { - kubefirstDeployment, err := k8s.ReturnDeploymentObject( - kcfg.Clientset, - "app.kubernetes.io/instance", - "kubefirst", - "kubefirst", - 600, - ) - if err != nil { - return fmt.Errorf("error finding kubefirst Deployment: %w", err) - } - _, err = k8s.WaitForDeploymentReady(kcfg.Clientset, kubefirstDeployment, 120) - if err != nil { - return fmt.Errorf("error waiting for kubefirst Deployment ready state: %w", err) - } - progressPrinter.IncrementTracker("wrapping-up", 1) + } - err = utils.OpenBrowser(constants.KubefirstConsoleLocalURLTLS) - if err != nil { - log.Error().Err(err).Msg("failed to open Kubefirst console in browser") - } + kubefirstDeployment, err := k8s.ReturnDeploymentObject( + kcfg.Clientset, + "app.kubernetes.io/instance", + "kubefirst", + "kubefirst", + 600, + ) + if err != nil { + return fmt.Errorf("error finding kubefirst Deployment: %w", err) + } + _, err = k8s.WaitForDeploymentReady(kcfg.Clientset, kubefirstDeployment, 120) + if err != nil { + return fmt.Errorf("error waiting for kubefirst Deployment ready state: %w", err) + } + progressPrinter.IncrementTracker("wrapping-up", 1) - telemetry.SendEvent(segClient, telemetry.ClusterInstallCompleted, "") - viper.Set("kubefirst-checks.cluster-install-complete", true) - viper.WriteConfig() + err = utils.OpenBrowser(constants.KubefirstConsoleLocalURLTLS) + if err != nil { + log.Error().Err(err).Msg("failed to open Kubefirst console in browser") + } - log.Info().Msg("kubefirst installation complete") - log.Info().Msg("welcome to your new Kubefirst platform running in K3D") - time.Sleep(1 * time.Second) + telemetry.SendEvent(segClient, telemetry.ClusterInstallCompleted, "") + viper.Set("kubefirst-checks.cluster-install-complete", true) + viper.WriteConfig() - reports.LocalHandoffScreenV2(viper.GetString("components.argocd.password"), clusterNameFlag, gitDestDescriptor, cGitOwner, config, ciFlag) + log.Info().Msg("kubefirst installation complete") + log.Info().Msg("welcome to your new Kubefirst platform running in K3D") + time.Sleep(1 * time.Second) - if ciFlag { - progress.Progress.Quit() - } + reports.LocalHandoffScreenV2(viper.GetString("components.argocd.password"), clusterNameFlag, gitDestDescriptor, cGitOwner, config, ciFlag) + + if ciFlag { + progress.Progress.Quit() } return nil diff --git a/cmd/k3d/vault.go b/cmd/k3d/vault.go index 485e49bbd..a044b1154 100644 --- a/cmd/k3d/vault.go +++ b/cmd/k3d/vault.go @@ -33,7 +33,7 @@ const ( secretThreshold = 3 ) -func unsealVault(cmd *cobra.Command, args []string) error { +func unsealVault(_ *cobra.Command, _ []string) error { flags := utils.GetClusterStatusFlags() if !flags.SetupComplete { return fmt.Errorf("failed to unseal vault: there doesn't appear to be an active k3d cluster") diff --git a/cmd/k3s/command.go b/cmd/k3s/command.go index 7fda362f0..48b7c28fa 100644 --- a/cmd/k3s/command.go +++ b/cmd/k3s/command.go @@ -25,8 +25,8 @@ var ( clusterTypeFlag string k3sServersPrivateIpsFlag []string k3sServersPublicIpsFlag []string - k3sSshUserflag string - k3sSshPrivateKeyflag string + k3sSSHUserflag string + k3sSSHPrivateKeyflag string K3sServersArgsFlags []string dnsProviderFlag string subdomainNameFlag string @@ -93,8 +93,8 @@ func Create() *cobra.Command { createCmd.MarkFlagRequired("servers-private-ips") createCmd.Flags().StringSliceVar(&k3sServersPublicIpsFlag, "servers-public-ips", []string{}, "the list of k3s (servers) public ip x.x.x.x,y.y.y.y comma separated (required)") createCmd.Flags().StringSliceVar(&K3sServersArgsFlags, "servers-args", []string{"--disable traefik", "--write-kubeconfig-mode 644"}, "list of k3s extras args to add to the k3s server installation,comma separated in between quote, if --servers-public-ips --tls-san is added to default --servers-args") - createCmd.Flags().StringVar(&k3sSshUserflag, "ssh-user", "root", "the user used to log into servers with ssh connection") - createCmd.Flags().StringVar(&k3sSshPrivateKeyflag, "ssh-privatekey", "", "the private key used to log into servers with ssh connection") + createCmd.Flags().StringVar(&k3sSSHUserflag, "ssh-user", "root", "the user used to log into servers with ssh connection") + createCmd.Flags().StringVar(&k3sSSHPrivateKeyflag, "ssh-privatekey", "", "the private key used to log into servers with ssh connection") createCmd.MarkFlagRequired("ssh-privatekey") createCmd.Flags().StringVar(&dnsProviderFlag, "dns-provider", "cloudflare", fmt.Sprintf("the dns provider - one of: %q", supportedDNSProviders)) createCmd.Flags().StringVar(&subdomainNameFlag, "subdomain", "", "the subdomain to use for DNS records (Cloudflare)") diff --git a/cmd/k3s/create.go b/cmd/k3s/create.go index c1e87ae4f..ae7ce75c3 100644 --- a/cmd/k3s/create.go +++ b/cmd/k3s/create.go @@ -25,10 +25,10 @@ import ( "github.com/konstructio/kubefirst/internal/utilities" "github.com/spf13/cobra" "github.com/spf13/viper" - _ "k8s.io/client-go/plugin/pkg/client/auth" + _ "k8s.io/client-go/plugin/pkg/client/auth" // required for k8s authentication ) -func createK3s(cmd *cobra.Command, args []string) error { +func createK3s(cmd *cobra.Command, _ []string) error { cliFlags, err := utilities.GetFlags(cmd, "k3s") if err != nil { progress.Error(err.Error()) @@ -99,7 +99,7 @@ func createK3s(cmd *cobra.Command, args []string) error { launch.Up(nil, true, cliFlags.UseTelemetry) } - err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresUrl()), "kubefirst api") + err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresURL()), "kubefirst api") if err != nil { progress.Error("unable to start kubefirst api") return fmt.Errorf("app availability check failed: %w", err) diff --git a/cmd/launch.go b/cmd/launch.go index 89d963b8e..88b23c5ac 100644 --- a/cmd/launch.go +++ b/cmd/launch.go @@ -35,7 +35,7 @@ func launchUp() *cobra.Command { Use: "up", Short: "launch new console and api instance", TraverseChildren: true, - Run: func(cmd *cobra.Command, _ []string) { + Run: func(_ *cobra.Command, _ []string) { launch.Up(additionalHelmFlags, false, true) }, } @@ -51,7 +51,7 @@ func launchDown() *cobra.Command { Use: "down", Short: "remove console and api instance", TraverseChildren: true, - Run: func(cmd *cobra.Command, _ []string) { + Run: func(_ *cobra.Command, _ []string) { launch.Down(false) }, } @@ -78,7 +78,7 @@ func launchListClusters() *cobra.Command { Use: "list", Short: "list clusters created by the Kubefirst console", TraverseChildren: true, - Run: func(cmd *cobra.Command, _ []string) { + Run: func(_ *cobra.Command, _ []string) { launch.ListClusters() }, } @@ -98,7 +98,7 @@ func launchDeleteCluster() *cobra.Command { } return nil }, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { launch.DeleteCluster(args[0]) }, } diff --git a/cmd/letsencrypt.go b/cmd/letsencrypt.go index 1075338cf..1a1071d5e 100644 --- a/cmd/letsencrypt.go +++ b/cmd/letsencrypt.go @@ -35,7 +35,7 @@ func status() *cobra.Command { Use: "status", Short: "check the usage statistics for a LetsEncrypt certificate", TraverseChildren: true, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { if err := certificates.CheckCertificateUsage(domainNameFlag); err != nil { fmt.Printf("failed to check certificate usage for domain %q: %s\n", domainNameFlag, err) } diff --git a/cmd/logs.go b/cmd/logs.go index 24355df02..426db0374 100755 --- a/cmd/logs.go +++ b/cmd/logs.go @@ -21,7 +21,7 @@ var logsCmd = &cobra.Command{ Use: "logs", Short: "kubefirst real time logs", Long: `kubefirst real time logs`, - RunE: func(cmd *cobra.Command, _ []string) error { + RunE: func(_ *cobra.Command, _ []string) error { provisionLogs.InitializeProvisionLogsTerminal() go func() { diff --git a/cmd/reset.go b/cmd/reset.go index e26789cfd..25312faba 100755 --- a/cmd/reset.go +++ b/cmd/reset.go @@ -25,7 +25,7 @@ var resetCmd = &cobra.Command{ Use: "reset", Short: "removes local kubefirst content to provision a new platform", Long: "removes local kubefirst content to provision a new platform", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { gitProvider := viper.GetString("kubefirst.git-provider") cloudProvider := viper.GetString("kubefirst.cloud-provider") diff --git a/cmd/root.go b/cmd/root.go index 36411b4e7..88659b299 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,7 +31,7 @@ var rootCmd = &cobra.Command{ // wire viper config for flags for all commands return configs.InitializeViperConfig(cmd) }, - Run: func(cmd *cobra.Command, _ []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println("To learn more about kubefirst, run:") fmt.Println(" kubefirst help") progress.Progress.Quit() diff --git a/cmd/terraform.go b/cmd/terraform.go index 54f75cd50..ec50bedb8 100644 --- a/cmd/terraform.go +++ b/cmd/terraform.go @@ -40,7 +40,7 @@ func terraformSetEnv() *cobra.Command { Use: "set-env", Short: "retrieve data from a target vault secret and format it for use in the local shell via environment variables", TraverseChildren: true, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { v := vault.VaultConfiguration{ Config: vault.NewVault(), } diff --git a/cmd/version.go b/cmd/version.go index 4b5e67752..f446bb0eb 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -20,7 +20,7 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "print the version number for kubefirst-cli", Long: `All software has versions. This is kubefirst's`, - Run: func(cmd *cobra.Command, _ []string) { + Run: func(_ *cobra.Command, _ []string) { versionMsg := ` ## ### kubefirst-cli golang utility version: ` + configs.K1Version diff --git a/cmd/vultr/command.go b/cmd/vultr/command.go index 1958a4f95..3490f6ddb 100644 --- a/cmd/vultr/command.go +++ b/cmd/vultr/command.go @@ -54,7 +54,7 @@ func NewCommand() *cobra.Command { Use: "vultr", Short: "Kubefirst Vultr installation", Long: "kubefirst vultr", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Println("To learn more about Vultr in Kubefirst, run:") fmt.Println(" kubefirst beta vultr --help") diff --git a/cmd/vultr/create.go b/cmd/vultr/create.go index 26a4233da..5066b5c29 100644 --- a/cmd/vultr/create.go +++ b/cmd/vultr/create.go @@ -22,12 +22,11 @@ import ( "github.com/konstructio/kubefirst/internal/provision" "github.com/konstructio/kubefirst/internal/utilities" "github.com/rs/zerolog/log" - "github.com/spf13/cobra" "github.com/spf13/viper" ) -func createVultr(cmd *cobra.Command, args []string) error { +func createVultr(cmd *cobra.Command, _ []string) error { cliFlags, err := utilities.GetFlags(cmd, "vultr") if err != nil { progress.Error(err.Error()) @@ -97,7 +96,7 @@ func createVultr(cmd *cobra.Command, args []string) error { launch.Up(nil, true, cliFlags.UseTelemetry) } - err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresUrl()), "kubefirst api") + err = utils.IsAppAvailable(fmt.Sprintf("%s/api/proxyHealth", cluster.GetConsoleIngresURL()), "kubefirst api") if err != nil { progress.Error("unable to start kubefirst api") return fmt.Errorf("kubefirst api availability check failed: %w", err) diff --git a/go.mod b/go.mod index 27aba6c90..a84cb186e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/konstructio/kubefirst -go 1.18 +go 1.23 require ( github.com/argoproj/argo-cd/v2 v2.6.7 diff --git a/internal/cluster/cluster.go b/internal/cluster/cluster.go index f34b22518..e9630376f 100644 --- a/internal/cluster/cluster.go +++ b/internal/cluster/cluster.go @@ -21,7 +21,7 @@ import ( "github.com/konstructio/kubefirst/internal/types" ) -func GetConsoleIngresUrl() string { +func GetConsoleIngresURL() string { if strings.ToLower(os.Getenv("K1_LOCAL_DEBUG")) == "true" { // allow using local console running on port 3000 return os.Getenv("K1_CONSOLE_REMOTE_URL") } @@ -35,7 +35,7 @@ func CreateCluster(cluster apiTypes.ClusterDefinition) error { requestObject := types.ProxyCreateClusterRequest{ Body: cluster, - Url: fmt.Sprintf("/cluster/%s", cluster.ClusterName), + URL: fmt.Sprintf("/cluster/%s", cluster.ClusterName), } payload, err := json.Marshal(requestObject) @@ -43,7 +43,7 @@ func CreateCluster(cluster apiTypes.ClusterDefinition) error { return fmt.Errorf("failed to marshal request object: %w", err) } - req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/api/proxy", GetConsoleIngresUrl()), bytes.NewReader(payload)) + req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/api/proxy", GetConsoleIngresURL()), bytes.NewReader(payload)) if err != nil { log.Printf("error creating request: %s", err) return fmt.Errorf("failed to create request: %w", err) @@ -79,7 +79,7 @@ func ResetClusterProgress(clusterName string) error { httpClient := http.Client{Transport: customTransport} requestObject := types.ProxyResetClusterRequest{ - Url: fmt.Sprintf("/cluster/%s/reset_progress", clusterName), + URL: fmt.Sprintf("/cluster/%s/reset_progress", clusterName), } payload, err := json.Marshal(requestObject) @@ -87,7 +87,7 @@ func ResetClusterProgress(clusterName string) error { return fmt.Errorf("failed to marshal request object: %w", err) } - req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/api/proxy", GetConsoleIngresUrl()), bytes.NewReader(payload)) + req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/api/proxy", GetConsoleIngresURL()), bytes.NewReader(payload)) if err != nil { log.Printf("error creating request: %v", err) return fmt.Errorf("failed to create request: %w", err) @@ -122,7 +122,7 @@ func GetCluster(clusterName string) (apiTypes.Cluster, error) { httpClient := http.Client{Transport: customTransport} cluster := apiTypes.Cluster{} - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/api/proxy?url=/cluster/%s", GetConsoleIngresUrl(), clusterName), nil) + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/api/proxy?url=/cluster/%s", GetConsoleIngresURL(), clusterName), nil) if err != nil { log.Printf("error creating request: %v", err) return cluster, fmt.Errorf("failed to create request: %w", err) @@ -162,7 +162,7 @@ func GetClusters() ([]apiTypes.Cluster, error) { httpClient := http.Client{Transport: customTransport} clusters := []apiTypes.Cluster{} - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/api/proxy?url=/cluster", GetConsoleIngresUrl()), nil) + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/api/proxy?url=/cluster", GetConsoleIngresURL()), nil) if err != nil { log.Printf("error creating request: %v", err) return clusters, fmt.Errorf("failed to create request: %w", err) @@ -201,7 +201,7 @@ func DeleteCluster(clusterName string) error { customTransport := http.DefaultTransport.(*http.Transport).Clone() httpClient := http.Client{Transport: customTransport} - req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/api/proxy?url=/cluster/%s", GetConsoleIngresUrl(), clusterName), nil) + req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/api/proxy?url=/cluster/%s", GetConsoleIngresURL(), clusterName), nil) if err != nil { log.Printf("error creating request: %v", err) return fmt.Errorf("failed to create request: %w", err) @@ -214,6 +214,7 @@ func DeleteCluster(clusterName string) error { log.Printf("error executing request: %v", err) return fmt.Errorf("failed to execute request: %w", err) } + defer res.Body.Close() if res.StatusCode != http.StatusOK { log.Printf("unable to delete cluster: %q, continuing", res.Status) diff --git a/internal/common/common.go b/internal/common/common.go index be94af311..e95ac74e6 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -58,7 +58,7 @@ func CheckForVersionUpdate() { } // versionCheck compares local to remote version -func versionCheck() (res *CheckResponse, skip bool) { +func versionCheck() (*CheckResponse, bool) { var latestVersion string flatVersion := strings.ReplaceAll(configs.K1Version, "v", "") @@ -116,7 +116,7 @@ func GetRootCredentials(_ *cobra.Command, _ []string) error { return nil } -func Destroy(cmd *cobra.Command, args []string) error { +func Destroy(_ *cobra.Command, _ []string) error { // Determine if there are active installs gitProvider := viper.GetString("flags.git-provider") gitProtocol := viper.GetString("flags.git-protocol") @@ -128,7 +128,7 @@ func Destroy(cmd *cobra.Command, args []string) error { domainName := viper.GetString("flags.domain-name") // Switch based on git provider, set params - cGitOwner := "" + var cGitOwner string switch gitProvider { case "github": cGitOwner = viper.GetString("flags.github-owner") diff --git a/internal/gitShim/containerRegistryAuth.go b/internal/gitShim/containerRegistryAuth.go index f497a3e80..6a0b64847 100644 --- a/internal/gitShim/containerRegistryAuth.go +++ b/internal/gitShim/containerRegistryAuth.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package gitShim +package gitShim //nolint:revive // allowed during refactoring import ( "encoding/base64" @@ -34,7 +34,6 @@ type ContainerRegistryAuth struct { func CreateContainerRegistrySecret(obj *ContainerRegistryAuth) (string, error) { // Handle secret creation for container registry authentication switch obj.GitProvider { - // GitHub docker auth secret // kaniko requires a specific format for Docker auth created as a secret // For GitHub, this becomes the provided token (pat) diff --git a/internal/gitShim/init.go b/internal/gitShim/init.go index 124bffe77..c60a05a7f 100644 --- a/internal/gitShim/init.go +++ b/internal/gitShim/init.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package gitShim +package gitShim //nolint:revive // allowed during refactoring import ( "errors" diff --git a/internal/helm/types.go b/internal/helm/types.go index 66405985c..1845390c8 100644 --- a/internal/helm/types.go +++ b/internal/helm/types.go @@ -6,12 +6,12 @@ See the LICENSE file for more details. */ package helm -type HelmRepo struct { +type Repo struct { Name string `yaml:"name"` URL string `yaml:"url"` } -type HelmRelease struct { +type Release struct { AppVersion string `yaml:"app_version"` Chart string `yaml:"chart"` Name string `yaml:"name"` diff --git a/internal/k3d/menu.go b/internal/k3d/menu.go index 76ccc29c9..662ba587a 100644 --- a/internal/k3d/menu.go +++ b/internal/k3d/menu.go @@ -37,9 +37,9 @@ func (i Item) FilterValue() string { return "" } type ItemDelegate struct{} -func (d ItemDelegate) Height() int { return 1 } -func (d ItemDelegate) Spacing() int { return 0 } -func (d ItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil } +func (d ItemDelegate) Height() int { return 1 } +func (d ItemDelegate) Spacing() int { return 0 } +func (d ItemDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil } func (d ItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) { i, ok := listItem.(Item) if !ok { @@ -104,7 +104,7 @@ func (m Model) View() string { return "\n" + m.List.View() } -func MongoDestinationChooser(inCluster bool) (result string, err error) { +func MongoDestinationChooser(inCluster bool) (string, error) { if inCluster { return "in-cluster", nil } diff --git a/internal/launch/cmd.go b/internal/launch/cmd.go index 41661cf04..0463dde9e 100644 --- a/internal/launch/cmd.go +++ b/internal/launch/cmd.go @@ -73,13 +73,13 @@ func Up(additionalHelmFlags []string, inCluster, useTelemetry bool) { _, err = os.Stat(k3dClient) if err != nil { log.Info().Msg("Downloading k3d...") - k3dDownloadUrl := fmt.Sprintf( + k3dDownloadURL := fmt.Sprintf( "https://github.com/k3d-io/k3d/releases/download/%s/k3d-%s-%s", k3d.K3dVersion, k3d.LocalhostOS, k3d.LocalhostARCH, ) - err = downloadManager.DownloadFile(k3dClient, k3dDownloadUrl) + err = downloadManager.DownloadFile(k3dClient, k3dDownloadURL) if err != nil { progress.Error(fmt.Sprintf("error while trying to download k3d: %s", err)) return @@ -100,14 +100,14 @@ func Up(additionalHelmFlags []string, inCluster, useTelemetry bool) { if err != nil { log.Info().Msg("Downloading helm...") helmVersion := "v3.12.0" - helmDownloadUrl := fmt.Sprintf( + helmDownloadURL := fmt.Sprintf( "https://get.helm.sh/helm-%s-%s-%s.tar.gz", helmVersion, k3d.LocalhostOS, k3d.LocalhostARCH, ) helmDownloadTarGzPath := fmt.Sprintf("%s/helm.tar.gz", toolsDir) - err = downloadManager.DownloadFile(helmDownloadTarGzPath, helmDownloadUrl) + err = downloadManager.DownloadFile(helmDownloadTarGzPath, helmDownloadURL) if err != nil { progress.Error(fmt.Sprintf("error while trying to download helm: %s", err)) return @@ -223,7 +223,7 @@ func Up(additionalHelmFlags []string, inCluster, useTelemetry bool) { return } - var existingHelmRepositories []helm.HelmRepo + var existingHelmRepositories []helm.Repo repoExists := false err = yaml.Unmarshal([]byte(res), &existingHelmRepositories) @@ -283,7 +283,7 @@ func Up(additionalHelmFlags []string, inCluster, useTelemetry bool) { return } - var existingHelmReleases []helm.HelmRelease + var existingHelmReleases []helm.Release chartInstalled := false err = yaml.Unmarshal([]byte(res), &existingHelmReleases) @@ -429,7 +429,7 @@ func Up(additionalHelmFlags []string, inCluster, useTelemetry bool) { return } - //* read certificate files + // * read certificate files certPem, err := os.ReadFile(fmt.Sprintf("%s/%s-cert.pem", mkcertPemDir, "kubefirst-console")) if err != nil { progress.Error(fmt.Sprintf("error reading certificate for console: %s", err)) diff --git a/internal/progress/command.go b/internal/progress/command.go index 7d69d3556..a76a3e4bb 100644 --- a/internal/progress/command.go +++ b/internal/progress/command.go @@ -17,7 +17,7 @@ import ( // Commands func GetClusterInterval(clusterName string) tea.Cmd { - return tea.Every(time.Second*10, func(t time.Time) tea.Msg { + return tea.Every(time.Second*10, func(_ time.Time) tea.Msg { provisioningCluster, err := cluster.GetCluster(clusterName) if err != nil { log.Printf("failed to get cluster %q: %v", clusterName, err) @@ -29,70 +29,70 @@ func GetClusterInterval(clusterName string) tea.Cmd { } func AddSuccesMessage(cluster types.Cluster) tea.Cmd { - return tea.Tick(0, func(t time.Time) tea.Msg { + return tea.Tick(0, func(_ time.Time) tea.Msg { successMessage := DisplaySuccessMessage(cluster) - return successMsg(successMessage) + return successMessage }) } -func BuildCompletedSteps(cluster types.Cluster, model progressModel) ([]string, string) { +func BuildCompletedSteps(cluster types.Cluster) ([]string, string) { completedSteps := []string{} nextStep := "" if cluster.InstallToolsCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.install_tools_check) - nextStep = CompletedStepsLabels.domain_liveness_check + completedSteps = append(completedSteps, CompletedStepsLabels.installToolsCheck) + nextStep = CompletedStepsLabels.domainLivenessCheck } if cluster.DomainLivenessCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.domain_liveness_check) - nextStep = CompletedStepsLabels.kbot_setup_check + completedSteps = append(completedSteps, CompletedStepsLabels.domainLivenessCheck) + nextStep = CompletedStepsLabels.kbotSetupCheck } if cluster.KbotSetupCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.kbot_setup_check) - nextStep = CompletedStepsLabels.git_init_check + completedSteps = append(completedSteps, CompletedStepsLabels.kbotSetupCheck) + nextStep = CompletedStepsLabels.gitInitCheck } if cluster.GitInitCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.git_init_check) - nextStep = CompletedStepsLabels.gitops_ready_check + completedSteps = append(completedSteps, CompletedStepsLabels.gitInitCheck) + nextStep = CompletedStepsLabels.gitopsReadyCheck } if cluster.GitopsReadyCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.gitops_ready_check) - nextStep = CompletedStepsLabels.git_terraform_apply_check + completedSteps = append(completedSteps, CompletedStepsLabels.gitopsReadyCheck) + nextStep = CompletedStepsLabels.gitTerraformApplyCheck } if cluster.GitTerraformApplyCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.git_terraform_apply_check) - nextStep = CompletedStepsLabels.gitops_pushed_check + completedSteps = append(completedSteps, CompletedStepsLabels.gitTerraformApplyCheck) + nextStep = CompletedStepsLabels.gitopsPushedCheck } if cluster.GitopsPushedCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.gitops_pushed_check) - nextStep = CompletedStepsLabels.cloud_terraform_apply_check + completedSteps = append(completedSteps, CompletedStepsLabels.gitopsPushedCheck) + nextStep = CompletedStepsLabels.cloudTerraformApplyCheck } if cluster.CloudTerraformApplyCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.cloud_terraform_apply_check) - nextStep = CompletedStepsLabels.cluster_secrets_created_check + completedSteps = append(completedSteps, CompletedStepsLabels.cloudTerraformApplyCheck) + nextStep = CompletedStepsLabels.clusterSecretsCreatedCheck } if cluster.ClusterSecretsCreatedCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.cluster_secrets_created_check) - nextStep = CompletedStepsLabels.argocd_install_check + completedSteps = append(completedSteps, CompletedStepsLabels.clusterSecretsCreatedCheck) + nextStep = CompletedStepsLabels.argoCDInstallCheck } if cluster.ArgoCDInstallCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.argocd_install_check) - nextStep = CompletedStepsLabels.argocd_initialize_check + completedSteps = append(completedSteps, CompletedStepsLabels.argoCDInstallCheck) + nextStep = CompletedStepsLabels.argoCDInitializeCheck } if cluster.ArgoCDInitializeCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.argocd_initialize_check) - nextStep = CompletedStepsLabels.vault_initialized_check + completedSteps = append(completedSteps, CompletedStepsLabels.argoCDInitializeCheck) + nextStep = CompletedStepsLabels.vaultInitializedCheck } if cluster.VaultInitializedCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.vault_initialized_check) - nextStep = CompletedStepsLabels.vault_terraform_apply_check + completedSteps = append(completedSteps, CompletedStepsLabels.vaultInitializedCheck) + nextStep = CompletedStepsLabels.vaultTerraformApplyCheck } if cluster.VaultTerraformApplyCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.vault_terraform_apply_check) - nextStep = CompletedStepsLabels.users_terraform_apply_check + completedSteps = append(completedSteps, CompletedStepsLabels.vaultTerraformApplyCheck) + nextStep = CompletedStepsLabels.usersTerraformApplyCheck } if cluster.UsersTerraformApplyCheck { - completedSteps = append(completedSteps, CompletedStepsLabels.users_terraform_apply_check) + completedSteps = append(completedSteps, CompletedStepsLabels.usersTerraformApplyCheck) nextStep = "Wrapping up" } diff --git a/internal/progress/constants.go b/internal/progress/constants.go index 41335b835..a3dc7d7d9 100644 --- a/internal/progress/constants.go +++ b/internal/progress/constants.go @@ -6,41 +6,19 @@ See the LICENSE file for more details. */ package progress -import ( - "time" - - "github.com/charmbracelet/lipgloss" -) - -const ( - padding = 2 - maxWidth = 80 -) - -const debounceDuration = time.Second * 10 - -var ( - currentPkgNameStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("211")) - doneStyle = lipgloss.NewStyle().Margin(1, 2) - checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).SetString("✓") - helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")).Render - StatusStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFFFF")).Bold(true).Render - spinnerStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("69")) -) - var CompletedStepsLabels = ProvisionSteps{ - install_tools_check: "Installing tools", - domain_liveness_check: "Domain liveness check", - kbot_setup_check: "Kbot setup", - git_init_check: "Initializing Git", - gitops_ready_check: "Initializing GitOps", - git_terraform_apply_check: "Git Terraform apply", - gitops_pushed_check: "GitOps repos pushed", - cloud_terraform_apply_check: "Cloud Terraform apply", - cluster_secrets_created_check: "Creating cluster secrets", - argocd_install_check: "Installing ArgoCD", - argocd_initialize_check: "Initializing ArgoCD", - vault_initialized_check: "Initializing Vault", - vault_terraform_apply_check: "Vault Terraform apply", - users_terraform_apply_check: "Users Terraform apply", + installToolsCheck: "Installing tools", + domainLivenessCheck: "Domain liveness check", + kbotSetupCheck: "Kbot setup", + gitInitCheck: "Initializing Git", + gitopsReadyCheck: "Initializing GitOps", + gitTerraformApplyCheck: "Git Terraform apply", + gitopsPushedCheck: "GitOps repos pushed", + cloudTerraformApplyCheck: "Cloud Terraform apply", + clusterSecretsCreatedCheck: "Creating cluster secrets", + argoCDInstallCheck: "Installing ArgoCD", + argoCDInitializeCheck: "Initializing ArgoCD", + vaultInitializedCheck: "Initializing Vault", + vaultTerraformApplyCheck: "Vault Terraform apply", + usersTerraformApplyCheck: "Users Terraform apply", } diff --git a/internal/progress/message.go b/internal/progress/message.go index daceb3aa7..d016eaf00 100644 --- a/internal/progress/message.go +++ b/internal/progress/message.go @@ -76,6 +76,7 @@ func DisplayLogHints(estimatedTime int) { }) } +//nolint:revive // will be fixed in the future func DisplaySuccessMessage(cluster types.Cluster) successMsg { cloudCliKubeconfig := "" diff --git a/internal/progress/progress.go b/internal/progress/progress.go index b33d9ba7e..6d0b42c7f 100644 --- a/internal/progress/progress.go +++ b/internal/progress/progress.go @@ -16,6 +16,7 @@ import ( var Progress *tea.Program +//nolint:revive // will be removed after refactoring func NewModel() progressModel { return progressModel{ isProvisioned: false, @@ -68,7 +69,7 @@ func (m progressModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case CusterProvisioningMsg: m.provisioningCluster = types.Cluster(msg) - completedSteps, nextStep := BuildCompletedSteps(types.Cluster(msg), m) + completedSteps, nextStep := BuildCompletedSteps(types.Cluster(msg)) m.completedSteps = append(m.completedSteps, completedSteps...) m.nextStep = renderMessage(fmt.Sprintf(":dizzy: %s", nextStep)) @@ -104,7 +105,7 @@ func (m progressModel) View() string { completedSteps := "" for i := index; i < len(m.completedSteps); i++ { - completedSteps = completedSteps + renderMessage(fmt.Sprintf(":white_check_mark: %s", m.completedSteps[i])) + completedSteps += renderMessage(fmt.Sprintf(":white_check_mark: %s", m.completedSteps[i])) } if m.header != "" { diff --git a/internal/progress/types.go b/internal/progress/types.go index ac276fbe9..258260193 100644 --- a/internal/progress/types.go +++ b/internal/progress/types.go @@ -57,18 +57,18 @@ type successMsg struct { // Custom type ProvisionSteps struct { - install_tools_check string - domain_liveness_check string - kbot_setup_check string - git_init_check string - gitops_ready_check string - git_terraform_apply_check string - gitops_pushed_check string - cloud_terraform_apply_check string - cluster_secrets_created_check string - argocd_install_check string - argocd_initialize_check string - vault_initialized_check string - vault_terraform_apply_check string - users_terraform_apply_check string + installToolsCheck string + domainLivenessCheck string + kbotSetupCheck string + gitInitCheck string + gitopsReadyCheck string + gitTerraformApplyCheck string + gitopsPushedCheck string + cloudTerraformApplyCheck string + clusterSecretsCreatedCheck string + argoCDInstallCheck string + argoCDInitializeCheck string + vaultInitializedCheck string + vaultTerraformApplyCheck string + usersTerraformApplyCheck string } diff --git a/internal/provisionLogs/command.go b/internal/provisionLogs/command.go index e8b2c7393..47859bf05 100644 --- a/internal/provisionLogs/command.go +++ b/internal/provisionLogs/command.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package provisionLogs +package provisionLogs //nolint:revive // allowed during refactoring import ( "encoding/json" diff --git a/internal/provisionLogs/message.go b/internal/provisionLogs/message.go deleted file mode 100644 index 1b5ec5043..000000000 --- a/internal/provisionLogs/message.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright (C) 2021-2023, Kubefirst - -This program is licensed under MIT. -See the LICENSE file for more details. - -Emojis definition https://github.com/yuin/goldmark-emoji/blob/master/definition/github.go -Color definition https://www.ditig.com/256-colors-cheat-sheet -*/ -package provisionLogs - -import ( - "fmt" - "log" - - "github.com/charmbracelet/glamour" - "github.com/konstructio/kubefirst/internal/progress" -) - -func renderMessage(message string) string { - r, _ := glamour.NewTermRenderer( - glamour.WithStyles(progress.StyleConfig), - glamour.WithEmoji(), - ) - - out, err := r.Render(message) - if err != nil { - s := fmt.Errorf("rendering message failed: %w", err) - log.Println(s) - return s.Error() - } - return out -} diff --git a/internal/provisionLogs/provisionLogs.go b/internal/provisionLogs/provisionLogs.go index 4b63fb7e5..b2618e8cb 100644 --- a/internal/provisionLogs/provisionLogs.go +++ b/internal/provisionLogs/provisionLogs.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package provisionLogs +package provisionLogs //nolint:revive // allowed during refactoring import ( tea "github.com/charmbracelet/bubbletea" @@ -15,6 +15,7 @@ var quitStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render var ProvisionLogs *tea.Program +//nolint:revive // will be removed after refactoring func NewModel() provisionLogsModel { return provisionLogsModel{} } diff --git a/internal/provisionLogs/types.go b/internal/provisionLogs/types.go index a67905f25..3dd3906c7 100644 --- a/internal/provisionLogs/types.go +++ b/internal/provisionLogs/types.go @@ -4,7 +4,7 @@ Copyright (C) 2021-2023, Kubefirst This program is licensed under MIT. See the LICENSE file for more details. */ -package provisionLogs +package provisionLogs //nolint:revive // allowed during refactoring // Terminal model type provisionLogsModel struct { diff --git a/internal/segment/segment.go b/internal/segment/segment.go index 927b7c3ef..ba6616d7e 100644 --- a/internal/segment/segment.go +++ b/internal/segment/segment.go @@ -14,7 +14,7 @@ const ( kubefirstClient string = "api" ) -func InitClient(clusterId, clusterType, gitProvider string) (telemetry.TelemetryEvent, error) { +func InitClient(clusterID, clusterType, gitProvider string) (telemetry.TelemetryEvent, error) { machineID, err := machineid.ID() if err != nil { return telemetry.TelemetryEvent{}, fmt.Errorf("failed to get machine ID: %w", err) @@ -23,7 +23,7 @@ func InitClient(clusterId, clusterType, gitProvider string) (telemetry.Telemetry c := telemetry.TelemetryEvent{ CliVersion: configs.K1Version, CloudProvider: k3d.CloudProvider, - ClusterID: clusterId, + ClusterID: clusterID, ClusterType: clusterType, DomainName: k3d.DomainName, GitProvider: gitProvider, diff --git a/internal/types/flags.go b/internal/types/flags.go index 43795f157..84c3777d4 100644 --- a/internal/types/flags.go +++ b/internal/types/flags.go @@ -13,7 +13,7 @@ type CliFlags struct { CloudProvider string ClusterName string ClusterType string - DnsProvider string + DNSProvider string DomainName string SubDomainName string GitProvider string @@ -24,14 +24,14 @@ type CliFlags struct { GitopsTemplateURL string GoogleProject string UseTelemetry bool - Ecr bool + ECR bool NodeType string NodeCount string InstallCatalogApps string - K3sSshUser string - K3sSshPrivateKey string - K3sServersPrivateIps []string - K3sServersPublicIps []string + K3sSSHUser string + K3sSSHPrivateKey string + K3sServersPrivateIPs []string + K3sServersPublicIPs []string K3sServersArgs []string InstallKubefirstPro bool } diff --git a/internal/types/proxy.go b/internal/types/proxy.go index dc16ceb2c..a4b444d1c 100644 --- a/internal/types/proxy.go +++ b/internal/types/proxy.go @@ -12,9 +12,9 @@ import ( type ProxyCreateClusterRequest struct { Body apiTypes.ClusterDefinition `bson:"body" json:"body"` - Url string `bson:"url" json:"url"` + URL string `bson:"url" json:"url"` } type ProxyResetClusterRequest struct { - Url string `bson:"url" json:"url"` + URL string `bson:"url" json:"url"` } diff --git a/internal/utilities/flags.go b/internal/utilities/flags.go index ed0ff19ce..12306966d 100644 --- a/internal/utilities/flags.go +++ b/internal/utilities/flags.go @@ -130,7 +130,7 @@ func GetFlags(cmd *cobra.Command, cloudProvider string) (types.CliFlags, error) return cliFlags, fmt.Errorf("failed to get ecr flag: %w", err) } - cliFlags.Ecr = ecrFlag + cliFlags.ECR = ecrFlag } if cloudProvider == "google" { @@ -149,28 +149,28 @@ func GetFlags(cmd *cobra.Command, cloudProvider string) (types.CliFlags, error) progress.Error(err.Error()) return cliFlags, fmt.Errorf("failed to get servers-private-ips flag: %w", err) } - cliFlags.K3sServersPrivateIps = k3sServersPrivateIps + cliFlags.K3sServersPrivateIPs = k3sServersPrivateIps k3sServersPublicIps, err := cmd.Flags().GetStringSlice("servers-public-ips") if err != nil { progress.Error(err.Error()) return cliFlags, fmt.Errorf("failed to get servers-public-ips flag: %w", err) } - cliFlags.K3sServersPublicIps = k3sServersPublicIps + cliFlags.K3sServersPublicIPs = k3sServersPublicIps - k3sSshUserFlag, err := cmd.Flags().GetString("ssh-user") + k3sSSHUserFlag, err := cmd.Flags().GetString("ssh-user") if err != nil { progress.Error(err.Error()) return cliFlags, fmt.Errorf("failed to get ssh-user flag: %w", err) } - cliFlags.K3sSshUser = k3sSshUserFlag + cliFlags.K3sSSHUser = k3sSSHUserFlag - k3sSshPrivateKeyFlag, err := cmd.Flags().GetString("ssh-privatekey") + k3sSSHPrivateKeyFlag, err := cmd.Flags().GetString("ssh-privatekey") if err != nil { progress.Error(err.Error()) return cliFlags, fmt.Errorf("failed to get ssh-privatekey flag: %w", err) } - cliFlags.K3sSshPrivateKey = k3sSshPrivateKeyFlag + cliFlags.K3sSSHPrivateKey = k3sSSHPrivateKeyFlag K3sServersArgsFlags, err := cmd.Flags().GetStringSlice("servers-args") if err != nil { @@ -183,7 +183,7 @@ func GetFlags(cmd *cobra.Command, cloudProvider string) (types.CliFlags, error) cliFlags.AlertsEmail = alertsEmailFlag cliFlags.CloudRegion = cloudRegionFlag cliFlags.ClusterName = clusterNameFlag - cliFlags.DnsProvider = dnsProviderFlag + cliFlags.DNSProvider = dnsProviderFlag cliFlags.SubDomainName = subdomainFlag cliFlags.DomainName = domainNameFlag cliFlags.GitProtocol = gitProtocolFlag @@ -201,17 +201,17 @@ func GetFlags(cmd *cobra.Command, cloudProvider string) (types.CliFlags, error) viper.Set("flags.alerts-email", cliFlags.AlertsEmail) viper.Set("flags.cluster-name", cliFlags.ClusterName) - viper.Set("flags.dns-provider", cliFlags.DnsProvider) + viper.Set("flags.dns-provider", cliFlags.DNSProvider) viper.Set("flags.domain-name", cliFlags.DomainName) viper.Set("flags.git-provider", cliFlags.GitProvider) viper.Set("flags.git-protocol", cliFlags.GitProtocol) viper.Set("flags.cloud-region", cliFlags.CloudRegion) viper.Set("kubefirst.cloud-provider", cloudProvider) if cloudProvider == "k3s" { - viper.Set("flags.servers-private-ips", cliFlags.K3sServersPrivateIps) - viper.Set("flags.servers-public-ips", cliFlags.K3sServersPublicIps) - viper.Set("flags.ssh-user", cliFlags.K3sSshUser) - viper.Set("flags.ssh-privatekey", cliFlags.K3sSshPrivateKey) + viper.Set("flags.servers-private-ips", cliFlags.K3sServersPrivateIPs) + viper.Set("flags.servers-public-ips", cliFlags.K3sServersPublicIPs) + viper.Set("flags.ssh-user", cliFlags.K3sSSHUser) + viper.Set("flags.ssh-privatekey", cliFlags.K3sSSHPrivateKey) viper.Set("flags.servers-args", cliFlags.K3sServersArgs) } if err := viper.WriteConfig(); err != nil { diff --git a/internal/utilities/utilities.go b/internal/utilities/utilities.go index 9b9b759d2..bf953c1ec 100644 --- a/internal/utilities/utilities.go +++ b/internal/utilities/utilities.go @@ -139,7 +139,7 @@ func CreateClusterDefinitionRecordFromRaw(gitAuth apiTypes.GitAuth, cliFlags typ kubefirstTeam := os.Getenv("KUBEFIRST_TEAM") if kubefirstTeam == "" { - kubefirstTeam = "false" + kubefirstTeam = "false" //nolint:ineffassign,wastedassign // will be fixed in the future } stringToIntNodeCount, err := strconv.Atoi(cliFlags.NodeCount) @@ -192,7 +192,7 @@ func CreateClusterDefinitionRecordFromRaw(gitAuth apiTypes.GitAuth, cliFlags typ cl.AWSAuth.AccessKeyID = viper.GetString("kubefirst.state-store-creds.access-key-id") cl.AWSAuth.SecretAccessKey = viper.GetString("kubefirst.state-store-creds.secret-access-key-id") cl.AWSAuth.SessionToken = viper.GetString("kubefirst.state-store-creds.token") - cl.ECR = cliFlags.Ecr + cl.ECR = cliFlags.ECR case "civo": cl.CivoAuth.Token = os.Getenv("CIVO_TOKEN") case "digitalocean": @@ -271,7 +271,7 @@ func ExportCluster(cluster apiTypes.Cluster, kcfg *k8s.KubernetesClient) error { func ConsumeStream(url string) { client := &http.Client{} - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { log.Error().Msgf("Error creating request: %s", err) return diff --git a/main.go b/main.go index c5e4ea0fb..d7227eb57 100644 --- a/main.go +++ b/main.go @@ -12,16 +12,14 @@ import ( "os" "time" - "golang.org/x/exp/slices" - - zeroLog "github.com/rs/zerolog" - "github.com/rs/zerolog/log" - "github.com/konstructio/kubefirst-api/pkg/configs" utils "github.com/konstructio/kubefirst-api/pkg/utils" "github.com/konstructio/kubefirst/cmd" "github.com/konstructio/kubefirst/internal/progress" + zeroLog "github.com/rs/zerolog" + "github.com/rs/zerolog/log" "github.com/spf13/viper" + "golang.org/x/exp/slices" ) func main() { @@ -40,7 +38,8 @@ func main() { config := configs.ReadConfig() if err := utils.SetupViper(config, true); err != nil { - stdLog.Panic(err) + log.Error().Msgf("failed to setup Viper: %v", err) + return } now := time.Now() @@ -74,38 +73,39 @@ func main() { homePath, err := os.UserHomeDir() if err != nil { - log.Info().Msg(err.Error()) + log.Error().Msgf("failed to get user home directory: %v", err) + return } k1Dir := fmt.Sprintf("%s/.k1", homePath) - //* create k1Dir if it doesn't exist + // * create k1Dir if it doesn't exist if _, err := os.Stat(k1Dir); os.IsNotExist(err) { - err := os.MkdirAll(k1Dir, os.ModePerm) - if err != nil { - log.Info().Msgf("%s directory already exists, continuing", k1Dir) + if err := os.MkdirAll(k1Dir, os.ModePerm); err != nil { + log.Error().Msgf("error creating directory %q: %v", k1Dir, err) + return } } - //* create log directory + // * create log directory logsFolder := fmt.Sprintf("%s/logs", k1Dir) - _ = os.Mkdir(logsFolder, 0o700) - if err != nil { - log.Fatal().Msgf("error creating logs directory: %s", err) + if err := os.Mkdir(logsFolder, 0o700); err != nil { + log.Error().Msgf("error creating logs directory: %v", err) + return } - //* create session log file + // * create session log file logfile := fmt.Sprintf("%s/%s", logsFolder, logfileName) logFileObj, err := utils.OpenLogFile(logfile) if err != nil { - stdLog.Panicf("unable to store log location, error is: %s - please verify the current user has write access to this directory", err) + log.Error().Msgf("unable to store log location, error is: %v - please verify the current user has write access to this directory", err) + return } // handle file close request defer func(logFileObj *os.File) { - err = logFileObj.Close() - if err != nil { - log.Print(err) + if err := logFileObj.Close(); err != nil { + log.Error().Msgf("error closing log file: %v", err) } }(logFileObj) @@ -121,9 +121,9 @@ func main() { viper.Set("k1-paths.log-file", logfile) viper.Set("k1-paths.log-file-name", logfileName) - err = viper.WriteConfig() - if err != nil { - stdLog.Panicf("unable to set log-file-location, error is: %s", err) + if err := viper.WriteConfig(); err != nil { + log.Error().Msgf("failed to write config: %v", err) + return } if canRunBubbleTea {