Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #72 from gianlucam76/v1.21
Browse files Browse the repository at this point in the history
Golang v1.21
  • Loading branch information
gianlucam76 authored Jan 1, 2024
2 parents cce2c20 + 3957d34 commit 4c672ba
Show file tree
Hide file tree
Showing 21 changed files with 466 additions and 272 deletions.
181 changes: 181 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
linters-settings:
dupl:
threshold: 200
errorlint:
# Use '%w' to format errors.
errorf: true
exhaustive:
# Ignore auto-generated code.
check-generated: false
default-signifies-exhaustive: false
forbidigo:
forbid:
# Forbid 'fmt.Print[|f|ln]() in shipping code.
- 'fmt\.Print.*'
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint # conflicts with nolintlint config providing superset functionality
- wrapperFunc
gocyclo:
min-complexity: 20
goimports:
local-prefixes: github.com/projectsveltos
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: argument,case,condition,return
gomodguard:
# Although this is almost empty, we will evolve the list below with the
# modules we shouldn't use for technical and/or security reasons.
blocked:
modules:
- k8s.io/kubernetes:
reason: "There is no good, avoidable reason to use this package and often leads to issues such as https://bit.ly/3dlKScY. However, if you disagree please include @ravchama in code review highlighting the reason."
versions:
# Don't merge replace directives using local path.
local_replace_directives: true
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
grouper:
const-require-grouping: true
import-require-single-import: true
import-require-grouping: true
var-require-grouping: true
lll:
line-length: 160
maintidx:
# check https://bit.ly/3tlJX3n for maintainability index.
##
# starting with 25 to begin with, with the plan to bump it to 40 eventuallly.
##
under: 25
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
revive:
ignore-generated-header: true
# this is a new linter, so let's start with Warning instead of errors to
# begin with.
severity: warning
whitespace:
multi-if: true
multi-func: true

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
fast: false
enable:
- bidichk
- containedctx
- bodyclose
- dogsled
- dupl
- durationcheck
- errcheck
- errname
- errorlint
- exhaustive
- exportloopref
- forbidigo
- funlen
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- ineffassign
- lll
- misspell
- maintidx
- nakedret
- noctx
- nolintlint
- nosprintfhostport
- predeclared
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- whitespace

# don't enable:
# - asciicheck
# - exhaustivestruct # applicable to special cases.
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - golint # deprecated
# - interfacer # deprecated
# - maligned #deprecated
# - nestif
# - prealloc
# - scopelint # deprecated
# - testpackage
# - wsl

issues:
# Excluding configuration per path, per linter, per text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
- grouper
- maintidx

# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"
# Maximum issues count per one linter.
# Set to 0 to disable.
max-issues-per-linter: 0
# Maximum count of issues with the same text.
# Set to 0 to disable.
max-same-issues: 0

run:
# Allow multiple parallel golangci-lint instances running.
allow-parallel-runners: true
# Timeout for analysis
timeout: 5m
# files to skip: they will be analyzed, but issues from them won't be reported.
skip-dirs:
- cmd/example/gen
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.20 as builder
FROM golang:1.21 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ KIND := $(TOOLS_BIN_DIR)/kind
KUBECTL := $(TOOLS_BIN_DIR)/kubectl
CLUSTERCTL := $(TOOLS_BIN_DIR)/clusterctl

GOLANGCI_LINT_VERSION := "v1.52.2"
CLUSTERCTL_VERSION := "v1.6.0-rc.1"
GOLANGCI_LINT_VERSION := "v1.55.2"
CLUSTERCTL_VERSION := "v1.6.0"

$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
cd $(TOOLS_DIR); $(GOBUILD) -tags=tools -o $(subst $(TOOLS_DIR)/hack/tools/,,$@) sigs.k8s.io/controller-tools/cmd/controller-gen
Expand Down Expand Up @@ -186,6 +186,9 @@ create-cluster: $(KIND) $(KUBECTL) $(ENVSUBST) ## Create a new kind cluster desi
@echo wait for capi-kubeadm-control-plane-system pod
$(KUBECTL) wait --for=condition=Available deployment/capi-kubeadm-control-plane-controller-manager -n capi-kubeadm-control-plane-system --timeout=$(TIMEOUT)

@echo "sleep allowing webhook to be ready"
sleep 10

@echo "Create a workload cluster"
$(KUBECTL) apply -f $(KIND_CLUSTER_YAML)

Expand Down
36 changes: 9 additions & 27 deletions controllers/addoncompliance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (r *AddonComplianceReconciler) Reconcile(ctx context.Context, req ctrl.Requ

// Handle deleted addonConstraint
if !addonConstraint.DeletionTimestamp.IsZero() {
return r.reconcileDelete(ctx, addonConstraintScope)
return r.reconcileDelete(ctx, addonConstraintScope), nil
}

// Handle non-deleted addonConstraint
Expand All @@ -164,7 +164,7 @@ func (r *AddonComplianceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
func (r *AddonComplianceReconciler) reconcileDelete(
ctx context.Context,
addonConstraintScope *scope.AddonComplianceScope,
) (reconcile.Result, error) {
) reconcile.Result {

logger := addonConstraintScope.Logger
logger.V(logs.LogInfo).Info("Reconciling AddonCompliance delete")
Expand All @@ -173,15 +173,15 @@ func (r *AddonComplianceReconciler) reconcileDelete(

err := r.annotateClusters(ctx, addonConstraintScope, logger)
if err != nil {
return reconcile.Result{Requeue: true, RequeueAfter: deleteRequeueAfter}, nil
return reconcile.Result{Requeue: true, RequeueAfter: deleteRequeueAfter}
}

if controllerutil.ContainsFinalizer(addonConstraintScope.AddonCompliance, libsveltosv1alpha1.AddonComplianceFinalizer) {
controllerutil.RemoveFinalizer(addonConstraintScope.AddonCompliance, libsveltosv1alpha1.AddonComplianceFinalizer)
}

logger.V(logs.LogInfo).Info("Reconcile delete success")
return reconcile.Result{}, nil
return reconcile.Result{}
}

func (r *AddonComplianceReconciler) reconcileNormal(
Expand Down Expand Up @@ -472,7 +472,7 @@ func (r *AddonComplianceReconciler) getMatchingClusters(ctx context.Context,
var err error
if addonConstraintScope.GetSelector() != "" {
parsedSelector, _ := labels.Parse(addonConstraintScope.GetSelector())
matchingCluster, err = clusterproxy.GetMatchingClusters(ctx, r.Client, parsedSelector, logger)
matchingCluster, err = clusterproxy.GetMatchingClusters(ctx, r.Client, parsedSelector, "", logger)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -575,13 +575,7 @@ func (r *AddonComplianceReconciler) collectContentOfConfigMap(ctx context.Contex
return nil, err
}

var policies [][]byte
policies, err = collectContent(ctx, configMap.Data, logger)
if err != nil {
return nil, err
}

return policies, nil
return collectContent(configMap.Data), nil
}

func (r *AddonComplianceReconciler) collectContentOfSecret(ctx context.Context, ref *corev1.ObjectReference,
Expand All @@ -602,13 +596,7 @@ func (r *AddonComplianceReconciler) collectContentOfSecret(ctx context.Context,
data[key] = string(value)
}

var policies [][]byte
policies, err = collectContent(ctx, data, logger)
if err != nil {
return nil, err
}

return policies, nil
return collectContent(data), nil
}

func (r *AddonComplianceReconciler) collectContentFromFluxSource(ctx context.Context, ref *corev1.ObjectReference,
Expand Down Expand Up @@ -644,13 +632,7 @@ func (r *AddonComplianceReconciler) collectContentFromFluxSource(ctx context.Con
return nil, err
}

var policies [][]byte
policies, err = collectContent(ctx, fileContents, logger)
if err != nil {
return nil, err
}

return policies, nil
return collectContent(fileContents), nil
}

func (r *AddonComplianceReconciler) annotateClusters(ctx context.Context,
Expand Down Expand Up @@ -712,7 +694,7 @@ func (r *AddonComplianceReconciler) annotateCluster(ctx context.Context,
if _, ok := annotations[libsveltosv1alpha1.GetClusterAnnotation()]; ok {
return nil
}
annotations[libsveltosv1alpha1.GetClusterAnnotation()] = "ok"
annotations[libsveltosv1alpha1.GetClusterAnnotation()] = ok
cluster.SetAnnotations(annotations)
return r.Update(ctx, cluster)
})
Expand Down
Loading

0 comments on commit 4c672ba

Please sign in to comment.