Skip to content

Commit

Permalink
fix: Enable more linters (#10)
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 authored Mar 7, 2024
1 parent afb3611 commit 8d07f9f
Show file tree
Hide file tree
Showing 25 changed files with 1,002 additions and 800 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ jobs:
# TODO coverage report

- name: Go linters
run: make lint
if: ${{ matrix.go-version == '1.21' }}
uses: golangci/golangci-lint-action@v4
with:
version: v1.56.2
skip-pkg-cache: true

container-check:
runs-on: ubuntu-latest
Expand Down
131 changes: 110 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,129 @@
# Documentation reference https://github.com/golangci/golangci-lint/blob/v1.56.2/.golangci.reference.yml
run:
deadline: 5m
skip-dirs-use-default: false
modules-download-mode: readonly
allow-parallel-runners: true
skip-dirs:
- test/*

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
sort-results: true

linters-settings:
dogsled:
max-blank-identifiers: 2
errcheck:
check-type-assertions: true
check-blank: true
gci:
sections:
- standard
- default
- prefix(github.com/migtools/oadp-non-admin)
goconst:
min-len: 3
min-occurrences: 5
gofmt:
simplify: true
goheader:
# copy from ./hack/boilerplate.go.txt
template: |-
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
govet:
enable-all: true
misspell:
locale: US
nakedret:
max-func-lines: 30
nolintlint:
allow-unused: false
allow-no-explanation: []
require-explanation: true
require-specific: true
revive:
enable-all-rules: true
rules:
- name: line-length-limit
disabled: true
- name: function-length
disabled: true
# TODO remove
- name: cyclomatic
disabled: true
- name: cognitive-complexity
disabled: true
unparam:
check-exported: true

issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
# restore some of the defaults
# (fill in the rest as needed)
exclude-rules:
- path: "api/*"
linters:
- lll
- path: "internal/*"
linters:
- dupl
- lll
linters:
disable-all: true
enable:
- dupl
- asasalint
- asciicheck
- bidichk
- bodyclose
- dogsled
- dupword
- durationcheck
- errcheck
- errchkjson
- exportloopref
- gci
- ginkgolinter
- goconst
- gocyclo
- gofmt
- goimports
- goheader
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- nilerr
- noctx
- nolintlint
- nosprintfhostport
- revive
- staticcheck
- typecheck
- stylecheck
- unconvert
- unparam
- unused
- usestdlibvars
fast: false

issues:
exclude-use-default: false
exclude-rules:
- linters:
- revive
text: "^struct-tag: unknown option 'inline' in JSON tag$"
- linters:
- revive
text: "^add-constant: avoid magic numbers like '0', create a named constant for it$"
- linters:
- revive
text: "^add-constant: avoid magic numbers like '1', create a named constant for it$"
max-issues-per-linter: 0
max-same-issues: 0

severity:
default-severity: error
case-sensitive: false
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN go mod download
# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY internal/ internal/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
KUSTOMIZE_VERSION ?= v5.3.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0
ENVTEST_VERSION ?= latest
GOLANGCI_LINT_VERSION ?= v1.54.2
GOLANGCI_LINT_VERSION ?= v1.56.2

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down
16 changes: 8 additions & 8 deletions api/v1alpha1/nonadminbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ import (

// NonAdminBackupSpec defines the desired state of NonAdminBackup
type NonAdminBackupSpec struct {
// NonAdminBackup log level (use debug for the most logging, leave unset for default)
// +optional
// +kubebuilder:validation:Enum=trace;debug;info;warning;error;fatal;panic
LogLevel string `json:"logLevel,omitempty"`

// https://github.com/vmware-tanzu/velero/blob/main/pkg/apis/velero/v1/backup_types.go

// BackupSpec defines the specification for a Velero backup.
BackupSpec *velerov1api.BackupSpec `json:"backupSpec,omitempty"`

// BackupStatus captures the current status of a Velero backup.
BackupStatus *velerov1api.BackupStatus `json:"backupStatus,omitempty"`

// NonAdminBackup log level (use debug for the most logging, leave unset for default)
// +optional
// +kubebuilder:validation:Enum=trace;debug;info;warning;error;fatal;panic
LogLevel string `json:"logLevel,omitempty"`
}

// NonAdminBackupStatus defines the observed state of NonAdminBackup
type NonAdminBackupStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// NonAdminBackup is the Schema for the nonadminbackups API
type NonAdminBackup struct {
Expand All @@ -54,7 +54,7 @@ type NonAdminBackup struct {
Status NonAdminBackupStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// NonAdminBackupList contains a list of NonAdminBackup
type NonAdminBackupList struct {
Expand Down
14 changes: 6 additions & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Entrypoint of the project
package main

import (
Expand All @@ -22,14 +23,12 @@ import (
"os"

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand All @@ -38,7 +37,6 @@ import (

nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
"github.com/migtools/oadp-non-admin/internal/controller"
//+kubebuilder:scaffold:imports
)

var (
Expand All @@ -52,7 +50,7 @@ func init() {
utilruntime.Must(nacv1alpha1.AddToScheme(scheme))

utilruntime.Must(velerov1api.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
// +kubebuilder:scaffold:scheme
}

func main() {
Expand Down Expand Up @@ -133,7 +131,7 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "NonAdminBackup")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
Expand Down
31 changes: 31 additions & 0 deletions internal/common/constant/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package constant contains all common constants used in the project
package constant

// Common labels for objects manipulated by the Non Admin Controller
// Labels should be used to identify the NAC backup
// Annotations on the other hand should be used to define ownership
// of the specific Object, such as Backup.
const (
OadpLabel = "openshift.io/oadp" // TODO import?
ManagedByLabel = "app.kubernetes.io/managed-by"
ManagedByLabelValue = "oadp-nac-controller" // TODO why not use same project name as in PROJECT file?
NabOriginNameAnnotation = "openshift.io/oadp-nab-origin-name"
NabOriginNamespaceAnnotation = "openshift.io/oadp-nab-origin-namespace"
NabOriginUUIDAnnotation = "openshift.io/oadp-nab-origin-uuid"
)
Loading

0 comments on commit 8d07f9f

Please sign in to comment.