Skip to content

Commit

Permalink
Update using final standard linters
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdappollonio committed Sep 3, 2024
1 parent 9d52cd4 commit 3825c3e
Show file tree
Hide file tree
Showing 51 changed files with 232 additions and 280 deletions.
2 changes: 1 addition & 1 deletion cmd/akamai/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions cmd/akamai/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/aws/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions cmd/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion cmd/civo/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/civo/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions cmd/civo/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/civo/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cmd/digitalocean/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions cmd/digitalocean/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/google/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
6 changes: 3 additions & 3 deletions cmd/google/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/k3d/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
87 changes: 46 additions & 41 deletions cmd/k3d/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/k3d/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions cmd/k3s/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <VALUES> --tls-san <VALUES> 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)")
Expand Down
6 changes: 3 additions & 3 deletions cmd/k3s/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 3825c3e

Please sign in to comment.