Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace logrus zerolog #114

Merged
merged 11 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Install dependencies
run: go mod download
- name: Install GolangCI Lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2

go-version-file: 'go.mod'
- name: golangci-lint
run: golangci-lint run --timeout=30m --max-same-issues=0 --out-format=github-actions
uses: golangci/golangci-lint-action@v4
with:
version: v1.55.2

test:
name: Test
Expand Down
16 changes: 16 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
run:
timeout: 30m

linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- zerologlint

linters-settings:
issues:
max-same-issues: 0
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.21
toolchain go1.21.0

require (
github.com/equinor/radix-common v1.7.1
github.com/equinor/radix-common v1.9.2
github.com/equinor/radix-operator v1.50.2
github.com/go-git/go-git/v5 v5.11.0
github.com/golang/mock v1.6.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/rs/zerolog v1.32.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
github.com/tektoncd/pipeline v0.55.0
Expand Down Expand Up @@ -69,6 +69,8 @@ require (
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -88,6 +90,7 @@ require (
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
Expand Down
16 changes: 14 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUK
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -97,8 +98,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/equinor/radix-common v1.7.1 h1:kl7Tuo2VEo2WHGm/vkvktrZ9t9S3Nht7Mob3CSIzcJI=
github.com/equinor/radix-common v1.7.1/go.mod h1:M6mhgHtFQ3rnjJnyOuECXiZOh7XQ5xVeHMyCAU+YPzQ=
github.com/equinor/radix-common v1.9.2 h1:pOYN/mSAoPe6KO/Nvudfd5DUETbLv4nLTLzFPr62ADw=
github.com/equinor/radix-common v1.9.2/go.mod h1:ekn86U68NT4ccSdt3GT+ukpiclzfuhr96a7zBJKv/jw=
github.com/equinor/radix-operator v1.50.2 h1:xa5kPUN77QT6QJq9+DJzF/ic2c7AJcl4KKztky38sdc=
github.com/equinor/radix-operator v1.50.2/go.mod h1:rl8Tbor0wvKfol67nd/p72MRh0iDTClGeQ2HcMRG/LQ=
github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ2tG6yudJd8LBksgI=
Expand Down Expand Up @@ -145,6 +146,7 @@ github.com/go-openapi/swag v0.22.7/go.mod h1:Gl91UqO+btAM0plGGxHqJcQZ1ZTy6jbmrid
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand Down Expand Up @@ -273,6 +275,11 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
Expand Down Expand Up @@ -341,6 +348,9 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
Expand Down Expand Up @@ -568,10 +578,12 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
23 changes: 12 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,36 @@ import (
"github.com/equinor/radix-tekton/pkg/models"
"github.com/equinor/radix-tekton/pkg/models/env"
"github.com/equinor/radix-tekton/pkg/pipeline"
log "github.com/sirupsen/logrus"
"github.com/equinor/radix-tekton/pkg/utils/logger"
"github.com/rs/zerolog/log"
)

func main() {
environment := env.NewEnvironment()
setLogLevel(environment)
level, err := environment.GetLogLevel()
if err != nil {
log.Fatal().Err(err).Msg("Failed to initialize log level")
}

logger.InitializeLogger(level, true)

kubeClient, radixClient, tektonClient, err := kubernetes.GetClients()
if err != nil {
log.Fatal(err.Error())
log.Fatal().Err(err).Msg("Failed to initialize kubeClient")
}

ctx := pipeline.NewPipelineContext(kubeClient, radixClient, tektonClient, environment)
err = runAction(ctx)
if err != nil {
log.Fatal(err.Error())
log.Fatal().Err(err).Msg("Failed to run ")
}

log.Infof("Completed")
log.Info().Msg("Completed")
}

func setLogLevel(environment env.Env) {
logLevel := environment.GetLogLevel()
log.SetLevel(logLevel)
log.Debugf("log-level '%v'", logLevel)
}
func runAction(ctx models.Context) error {
action := ctx.GetEnv().GetPipelinesAction()
log.Debugf("execute an action %s", action)
log.Debug().Msgf("execute an action %s", action)
switch action {
case pipelineDefaults.RadixPipelineActionPrepare:
return ctx.ProcessRadixAppConfig()
Expand Down
8 changes: 4 additions & 4 deletions pkg/internal/wait/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/equinor/radix-tekton/pkg/models/env"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
tektonclient "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
tektonInformerFactory "github.com/tektoncd/pipeline/pkg/client/informers/externalversions"
Expand Down Expand Up @@ -70,18 +70,18 @@ func waitForCompletionOf(pipelineRuns map[string]*pipelinev1.PipelineRun, tekton

switch {
case lastCondition.Reason == pipelinev1.PipelineRunReasonCompleted.String():
log.Infof("pipelineRun completed: %s", lastCondition.Message)
log.Info().Msgf("pipelineRun completed: %s", lastCondition.Message)
case lastCondition.Reason == pipelinev1.PipelineRunReasonFailed.String():
errChan <- fmt.Errorf("PipelineRun failed: %s", lastCondition.Message)
return
default:
log.Infof("pipelineRun status %s: %s", lastCondition.Reason, lastCondition.Message)
log.Info().Msgf("pipelineRun status %s: %s", lastCondition.Reason, lastCondition.Message)
}
if len(pipelineRuns) == 0 {
errChan <- nil
}
} else {
log.Debugf("Ongoing - PipelineRun has not completed yet")
log.Debug().Msgf("Ongoing - PipelineRun has not completed yet")
}
},
DeleteFunc: func(old interface{}) {
Expand Down
18 changes: 8 additions & 10 deletions pkg/models/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/equinor/radix-operator/pkg/apis/utils/git"
tektonDefaults "github.com/equinor/radix-tekton/pkg/defaults"
"github.com/equinor/radix-tekton/pkg/models/env/internal"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog"
"github.com/spf13/viper"
)

Expand Down Expand Up @@ -106,15 +106,13 @@ func (e *env) GetDNSConfig() *dnsalias.DNSConfig {
}

// GetLogLevel Log level: ERROR, INFO (default), DEBUG
func (e *env) GetLogLevel() log.Level {
switch viper.GetString(defaults.LogLevel) {
case "DEBUG":
return log.DebugLevel
case "ERROR":
return log.ErrorLevel
default:
return log.InfoLevel
func (e *env) GetLogLevel() (zerolog.Level, error) {
level := viper.GetString(defaults.LogLevel)
if level == "" {
return zerolog.InfoLevel, nil
}

return zerolog.ParseLevel(level)
}

// GetGitRepositoryWorkspace Path to the cloned GitHub repository
Expand Down Expand Up @@ -143,7 +141,7 @@ type Env interface {
GetRadixImageTag() string
GetBranch() string
GetPipelinesAction() string
GetLogLevel() log.Level
GetLogLevel() (zerolog.Level, error)
GetGitRepositoryWorkspace() string
GetSourceDeploymentGitCommitHash() string
GetSourceDeploymentGitBranch() string
Expand Down
9 changes: 5 additions & 4 deletions pkg/models/env/env_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/pipeline/pipeline_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/equinor/radix-tekton/pkg/models"
"github.com/equinor/radix-tekton/pkg/models/env"
ownerreferences "github.com/equinor/radix-tekton/pkg/utils/owner_references"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
tektonclient "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -67,7 +67,7 @@ func (ctx *pipelineContext) setPipelineRunParamsFromBuild(envVarsMap v1.EnvVarsM
if ctx.radixApplication.Spec.Build == nil ||
ctx.radixApplication.Spec.Build.Variables == nil ||
len(ctx.radixApplication.Spec.Build.Variables) == 0 {
log.Debugln("No radixApplication build variables")
log.Debug().Msg("No radixApplication build variables")
return
}

Expand All @@ -90,7 +90,7 @@ func (ctx *pipelineContext) setPipelineRunParamsFromEnvironmentBuilds(targetEnv
// getGitHash return git commit to which the user repository should be reset before parsing sub-pipelines.
func (ctx *pipelineContext) getGitHash() (string, error) {
if ctx.env.GetRadixPipelineType() == v1.Build {
log.Infof("build job with no deployment, skipping sub-pipelines.")
log.Info().Msg("build job with no deployment, skipping sub-pipelines.")
return "", nil
}

Expand All @@ -101,7 +101,7 @@ func (ctx *pipelineContext) getGitHash() (string, error) {
return sourceRdHashFromAnnotation, nil
}
if sourceDeploymentGitBranch == "" {
log.Infof("source deployment has no git metadata, skipping sub-pipelines")
log.Info().Msg("source deployment has no git metadata, skipping sub-pipelines")
return "", nil
}
sourceRdHashFromBranchHead, err := git.GetGitCommitHashFromHead(ctx.env.GetGitRepositoryWorkspace(), sourceDeploymentGitBranch)
Expand All @@ -118,7 +118,7 @@ func (ctx *pipelineContext) getGitHash() (string, error) {
pipelineJobBranch = re.Build.From
}
if pipelineJobBranch == "" {
log.Infof("deploy job with no build branch, skipping sub-pipelines.")
log.Info().Msg("deploy job with no build branch, skipping sub-pipelines.")
return "", nil
}
gitHash, err := git.GetGitCommitHashFromHead(ctx.env.GetGitRepositoryWorkspace(), pipelineJobBranch)
Expand Down
Loading
Loading