Skip to content

Commit

Permalink
fix imports and use zerolog (#308)
Browse files Browse the repository at this point in the history
* fix imports and use zerolog

* update runtime package
  • Loading branch information
jarededwards authored Mar 12, 2024
1 parent 84b81e9 commit 8ff2581
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 42 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/charmbracelet/bubbles v0.15.0
github.com/charmbracelet/bubbletea v0.23.2
github.com/charmbracelet/lipgloss v0.9.1
github.com/charmbracelet/log v0.3.1
github.com/civo/civogo v0.3.53
github.com/cloudflare/cloudflare-go v0.73.0
github.com/gin-contrib/cors v1.4.0
Expand All @@ -29,7 +28,7 @@ require (
github.com/hashicorp/vault/api v1.9.0
github.com/joho/godotenv v1.5.1
github.com/kubefirst/metrics-client v0.3.0
github.com/kubefirst/runtime v0.4.1
github.com/kubefirst/runtime v0.4.2
github.com/linode/linodego v1.29.0
github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a
github.com/minio/minio-go/v7 v7.0.49
Expand All @@ -54,7 +53,6 @@ require (

require (
github.com/aws/aws-sdk-go-v2/service/ec2 v1.91.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-resty/resty/v2 v2.11.0 // indirect
github.com/segmentio/analytics-go v3.1.0+incompatible // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJ
github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk=
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
github.com/charmbracelet/log v0.3.1 h1:TjuY4OBNbxmHWSwO3tosgqs5I3biyY8sQPny/eCMTYw=
github.com/charmbracelet/log v0.3.1/go.mod h1:OR4E1hutLsax3ZKpXbgUqPtTjQfrh1pG3zwHGWuuq8g=
github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down Expand Up @@ -422,8 +420,6 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
Expand Down Expand Up @@ -745,8 +741,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubefirst/metrics-client v0.3.0 h1:zCug82pEzeWhHhpeYQvdhytRNDxrLxX18dPQ5PSxY3s=
github.com/kubefirst/metrics-client v0.3.0/go.mod h1:GR7wsMcyYhd+EU67PeuMCBYFE6OJ7P/j5OI5BLOoRMc=
github.com/kubefirst/runtime v0.4.1 h1:0aqBZa3bPwHb5pFFA1eaZ5VObNjuVxDO4d8m9VFs4Jo=
github.com/kubefirst/runtime v0.4.1/go.mod h1:0CnYy+8JTG+/0f3QlkTQJqTT654Su6JXk30OufFVY98=
github.com/kubefirst/runtime v0.4.2 h1:qFoFEjyv9WSnmmKhclkux++xGA15yPt7/XwQbdQYVDs=
github.com/kubefirst/runtime v0.4.2/go.mod h1:GWsDhvffBMeJaHFgcCCyQrHIldclwVHwKD/j07UDYk4=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (clctrl *ClusterController) ClusterSecretsBootstrap() error {
case "k3s":
err := k3sext.BootstrapK3sMgmtCluster(clientSet, &cl, destinationGitopsRepoGitURL)
if err != nil {
log.Errorf("error adding kubernetes secrets for bootstrap: %s", err)
log.Fatal().Msgf("error adding kubernetes secrets for bootstrap: %s", err)
return err
}
}
Expand Down
8 changes: 2 additions & 6 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ type ClusterController struct {
AlertsEmail string

// auth
<<<<<<< HEAD
AkamaiAuth pkgtypes.AkamaiAuth
=======

>>>>>>> 5293e10f177cf27268d16dccf5b06bb8cef3f9ee
AWSAuth pkgtypes.AWSAuth
CivoAuth pkgtypes.CivoAuth
DigitaloceanAuth pkgtypes.DigitaloceanAuth
Expand All @@ -62,7 +58,7 @@ type ClusterController struct {
GitAuth pkgtypes.GitAuth
VaultAuth pkgtypes.VaultAuth
GoogleAuth pkgtypes.GoogleAuth
K3sAuth pkgtypes.K3sAuth
K3sAuth pkgtypes.K3sAuth
AwsAccessKeyID string
AwsSecretAccessKey string
NodeType string
Expand Down Expand Up @@ -218,7 +214,7 @@ func (clctrl *ClusterController) InitController(def *pkgtypes.ClusterDefinition)
if def.GitopsTemplateBranch != "" {
clctrl.GitopsTemplateURL = def.GitopsTemplateURL
} else {
return fmt.Errorf("must supply branch of gitops template repo when supplying a gitops template url")
return fmt.Errorf("must supply branch of gitops templatelog.Fatal().Msg( repo when supplying a gitops template url")
}
} else {
clctrl.GitopsTemplateURL = "https://github.com/kubefirst/gitops-template.git"
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (clctrl *ClusterController) DownloadTools(toolsDir string) error {
toolsDir,
)
if err != nil {
log.Errorf("error downloading dependencies: %s", err)
log.Fatal().Msgf("error downloading dependencies: %s", err)
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/router/api/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func PostCreateCluster(c *gin.Context) {
go func() {
err = k3s.CreateK3sCluster(&clusterDefinition)
if err != nil {
log.Errorf(err.Error())
log.Fatal().Msg(err.Error())
}
}()

Expand Down
7 changes: 4 additions & 3 deletions pkg/google/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ package google

import (
"fmt"
"log"
"os"

log "github.com/rs/zerolog/log"
)

// WriteGoogleApplicationCredentialsFile writes credentials file for use throughout installation
Expand All @@ -22,14 +23,14 @@ func WriteGoogleApplicationCredentialsFile(googleApplicationCredentials, homeDir

_, err = file.WriteString(googleApplicationCredentials)
if err != nil {
log.Fatal("error writing google application credentials file")
log.Fatal().Msg("error writing google application credentials file")
return err
}

// Close the file writer.
err = file.Close()
if err != nil {
log.Fatal("error closing file writer")
log.Fatal().Msg("error closing file writer")
return err
}
return nil
Expand Down
9 changes: 5 additions & 4 deletions pkg/providerConfigs/detokenize.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
"strings"

log "github.com/rs/zerolog/log"
)

// DetokenizeGitGitops - Translate tokens by values on a given path
Expand Down Expand Up @@ -103,23 +104,23 @@ func detokenizeGitops(path string, tokens *GitopsDirectoryValues, gitProtocol st
var terraformServersPrivateIpsList string
jsonBytes, err := json.Marshal(tokens.K3sServersPrivateIps)
if err != nil {
log.Fatalf("detokenise issue on %s", err)
log.Fatal().Msgf("detokenise issue on %s", err)
}
terraformServersPrivateIpsList = string(jsonBytes)
newContents = strings.Replace(newContents, "<K3S_SERVERS_PRIVATE_IPS>", terraformServersPrivateIpsList, -1)

var terraformServersPublicIpsList string
jsonBytes2, err := json.Marshal(tokens.K3sServersPublicIps)
if err != nil {
log.Fatalf("detokenise issue on %s", err)
log.Fatal().Msgf("detokenise issue on %s", err)
}
terraformServersPublicIpsList = string(jsonBytes2)
newContents = strings.Replace(newContents, "<K3S_SERVERS_PUBLIC_IPS>", terraformServersPublicIpsList, -1)

var terraformServersArgsList string
jsonBytes3, err := json.Marshal(tokens.K3sServersArgs)
if err != nil {
log.Fatalf("detokenise issue on %s", err)
log.Fatal().Msgf("detokenise issue on %s", err)
}
terraformServersArgsList = string(jsonBytes3)
newContents = strings.Replace(newContents, "<K3S_SERVERS_ARGS>", terraformServersArgsList, -1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"os"
"strings"

"github.com/charmbracelet/log"
"github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/runtime/pkg/gitlab"
"github.com/mikesmitty/edkey"
log "github.com/rs/zerolog/log"
"github.com/spf13/viper"
"golang.org/x/crypto/ssh"
)
Expand Down
32 changes: 16 additions & 16 deletions providers/k3s/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
pkgtypes "github.com/kubefirst/kubefirst-api/pkg/types"
"github.com/kubefirst/runtime/pkg/k8s"
"github.com/kubefirst/runtime/pkg/ssl"
log "github.com/sirupsen/logrus"
log "github.com/rs/zerolog/log"
)

// Createk3sCluster
Expand Down Expand Up @@ -99,21 +99,21 @@ func CreateK3sCluster(definition *pkgtypes.ClusterDefinition) error {
}

//* check for ssl restore
log.Info("checking for tls secrets to restore")
log.Info().Msg("checking for tls secrets to restore")
secretsFilesToRestore, err := os.ReadDir(ctrl.ProviderConfig.SSLBackupDir + "/secrets")
if err != nil {
log.Infof("%s", err)
log.Info().Msgf("%s", err)
}
if len(secretsFilesToRestore) != 0 {
// todo would like these but requires CRD's and is not currently supported
// add crds ( use execShellReturnErrors? )
// https://raw.githubusercontent.com/cert-manager/cert-manager/v1.11.0/deploy/crds/crd-clusterissuers.yaml
// https://raw.githubusercontent.com/cert-manager/cert-manager/v1.11.0/deploy/crds/crd-certificates.yaml
// add certificates, and clusterissuers
log.Infof("found %d tls secrets to restore", len(secretsFilesToRestore))
log.Info().Msgf("found %d tls secrets to restore", len(secretsFilesToRestore))
ssl.Restore(ctrl.ProviderConfig.SSLBackupDir, ctrl.DomainName, ctrl.ProviderConfig.Kubeconfig)
} else {
log.Info("no files found in secrets directory, continuing")
log.Info().Msg("no files found in secrets directory, continuing")
}

err = ctrl.InstallArgoCD()
Expand Down Expand Up @@ -186,7 +186,7 @@ func CreateK3sCluster(definition *pkgtypes.ClusterDefinition) error {
}

// Wait for last sync wave app transition to Running
log.Info("waiting for final sync wave Deployment to transition to Running")
log.Info().Msg("waiting for final sync wave Deployment to transition to Running")
crossplaneDeployment, err := k8s.ReturnDeploymentObject(
kcfg.Clientset,
"app.kubernetes.io/instance",
Expand All @@ -195,14 +195,14 @@ func CreateK3sCluster(definition *pkgtypes.ClusterDefinition) error {
3600,
)
if err != nil {
log.Errorf("Error finding crossplane Deployment: %s", err)
log.Fatal().Msgf("Error finding crossplane Deployment: %s", err)
ctrl.HandleError(err.Error())
return err
}
log.Infof("waiting on dns, tls certificates from letsencrypt and remaining sync waves.\n this may take up to 60 minutes but regularly completes in under 20 minutes")
log.Info().Msgf("waiting on dns, tls certificates from letsencrypt and remaining sync waves.\n this may take up to 60 minutes but regularly completes in under 20 minutes")
_, err = k8s.WaitForDeploymentReady(kcfg.Clientset, crossplaneDeployment, 3600)
if err != nil {
log.Errorf("Error waiting for all Apps to sync ready state: %s", err)
log.Fatal().Msgf("Error waiting for all Apps to sync ready state: %s", err)

ctrl.HandleError(err.Error())
return err
Expand All @@ -211,7 +211,7 @@ func CreateK3sCluster(definition *pkgtypes.ClusterDefinition) error {
//* export and import cluster
err = ctrl.ExportClusterRecord()
if err != nil {
log.Errorf("Error exporting cluster record: %s", err)
log.Fatal().Msgf("Error exporting cluster record: %s", err)
return err
} else {
err = ctrl.MdbCl.UpdateCluster(ctrl.ClusterName, "status", constants.ClusterStatusProvisioned)
Expand All @@ -224,17 +224,17 @@ func CreateK3sCluster(definition *pkgtypes.ClusterDefinition) error {
return err
}

log.Info("cluster creation complete")
log.Info().Msg("cluster creation complete")

// Create default service entries
cl, _ := db.Client.GetCluster(ctrl.ClusterName)
err = services.AddDefaultServices(&cl)
if err != nil {
log.Errorf("error adding default service entries for cluster %s: %s", cl.ClusterName, err)
log.Fatal().Msgf("error adding default service entries for cluster %s: %s", cl.ClusterName, err)
}
}

log.Info("waiting for kubefirst-api Deployment to transition to Running")
log.Info().Msg("waiting for kubefirst-api Deployment to transition to Running")
kubefirstAPI, err := k8s.ReturnDeploymentObject(
kcfg.Clientset,
"app.kubernetes.io/name",
Expand All @@ -243,19 +243,19 @@ func CreateK3sCluster(definition *pkgtypes.ClusterDefinition) error {
1200,
)
if err != nil {
log.Errorf("Error finding kubefirst api Deployment: %s", err)
log.Fatal().Msgf("Error finding kubefirst api Deployment: %s", err)
ctrl.HandleError(err.Error())
return err
}
_, err = k8s.WaitForDeploymentReady(kcfg.Clientset, kubefirstAPI, 300)
if err != nil {
log.Errorf("Error waiting for kubefirst-api to transition to Running: %s", err)
log.Fatal().Msgf("Error waiting for kubefirst-api to transition to Running: %s", err)

ctrl.HandleError(err.Error())
return err
}

log.Info("cluster creation complete")
log.Info().Msg("cluster creation complete")

return nil
}

0 comments on commit 8ff2581

Please sign in to comment.