Skip to content

Commit a19303b

Browse files
authored
Merge pull request #45 from xrstf/bump-golangci
Bump golangci
2 parents 280fca6 + 809d7e9 commit a19303b

File tree

10 files changed

+75
-60
lines changed

10 files changed

+75
-60
lines changed

.golangci.yml

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1+
version: "2"
12
run:
2-
timeout: 10m
33
allow-parallel-runners: true
4-
5-
issues:
6-
max-same-issues: 0
7-
8-
# don't skip warning about doc comments
9-
# don't exclude the default set of lint
10-
exclude-use-default: false
11-
124
linters:
13-
disable-all: true
5+
default: none
146
enable:
157
- copyloopvar
168
- errcheck
179
- ginkgolinter
1810
- goconst
1911
- gocyclo
20-
- gofmt
21-
- goimports
22-
- gosimple
2312
- govet
2413
- importas
2514
- ineffassign
@@ -28,34 +17,47 @@ linters:
2817
- prealloc
2918
- revive
3019
- staticcheck
31-
- typecheck
3220
- unconvert
3321
- unparam
3422
- unused
35-
36-
linters-settings:
37-
revive:
38-
rules:
39-
- name: comment-spacings
40-
- name: duplicated-imports
41-
severity: warning
42-
importas:
43-
no-unaliased: true
44-
alias:
45-
# kcp operator
46-
- pkg: github.com/kcp-dev/kcp-operator/sdk/apis/(\w+)/(v[\w\d]+)
47-
alias: $1$2
48-
# Kubernetes
49-
- pkg: k8s.io/api/(\w+)/(v[\w\d]+)
50-
alias: $1$2
51-
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
52-
alias: metav1
53-
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
54-
alias: apiextensionsv1
55-
- pkg: k8s.io/apimachinery/pkg/api/errors
56-
alias: apierrors
57-
- pkg: k8s.io/apimachinery/pkg/util/errors
58-
alias: kerrors
59-
# Controller Runtime (otherwise this will usually lead to shadowing a local "client" variable)
60-
- pkg: sigs.k8s.io/controller-runtime/pkg/client
61-
alias: ctrlruntimeclient
23+
settings:
24+
importas:
25+
alias:
26+
- pkg: github.com/kcp-dev/kcp-operator/sdk/apis/(\w+)/(v[\w\d]+)
27+
alias: $1$2
28+
- pkg: k8s.io/api/(\w+)/(v[\w\d]+)
29+
alias: $1$2
30+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
31+
alias: metav1
32+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
33+
alias: apiextensionsv1
34+
- pkg: k8s.io/apimachinery/pkg/api/errors
35+
alias: apierrors
36+
- pkg: k8s.io/apimachinery/pkg/util/errors
37+
alias: kerrors
38+
- pkg: sigs.k8s.io/controller-runtime/pkg/client
39+
alias: ctrlruntimeclient
40+
no-unaliased: true
41+
revive:
42+
rules:
43+
- name: comment-spacings
44+
- name: duplicated-imports
45+
severity: warning
46+
exclusions:
47+
generated: lax
48+
paths:
49+
- third_party$
50+
- builtin$
51+
- examples$
52+
issues:
53+
max-same-issues: 0
54+
formatters:
55+
enable:
56+
- gofmt
57+
- goimports
58+
exclusions:
59+
generated: lax
60+
paths:
61+
- third_party$
62+
- builtin$
63+
- examples$

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ KUBECTL_VERSION ?= v1.32.0
99
KUSTOMIZE_VERSION ?= v5.4.3
1010
CONTROLLER_TOOLS_VERSION ?= v0.16.1
1111
ENVTEST_VERSION ?= release-0.19
12-
GOLANGCI_LINT_VERSION ?= 1.63.4
12+
GOLANGCI_LINT_VERSION ?= 2.1.6
1313

1414
# Image URL to use all building/pushing image targets
1515
IMG ?= ghcr.io/kcp-dev/kcp-operator
@@ -72,11 +72,11 @@ test-e2e:
7272

7373
.PHONY: lint
7474
lint: golangci-lint ## Run golangci-lint linter.
75-
$(GOLANGCI_LINT) run
75+
$(GOLANGCI_LINT) run --timeout 10m
7676

7777
.PHONY: lint-fix
7878
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes.
79-
$(GOLANGCI_LINT) run --fix
79+
$(GOLANGCI_LINT) run --timeout 10m --fix
8080

8181
.PHONY: modules
8282
modules: ## Run go mod tidy to ensure modules are up to date.
@@ -156,30 +156,42 @@ OPENSHIFT_GOIMPORTS := $(TOOLS_DIR)/openshift-goimports
156156

157157
.PHONY: kubectl
158158
kubectl: $(KUBECTL) ## Download kubectl locally if necessary.
159+
160+
.PHONY: $(KUBECTL)
159161
$(KUBECTL):
160162
@UNCOMPRESSED=true hack/download-tool.sh https://dl.k8s.io/$(KUBECTL_VERSION)/bin/$(shell go env GOOS)/$(shell go env GOARCH)/kubectl kubectl $(KUBECTL_VERSION) kubectl
161163

162164
.PHONY: kustomize
163165
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
166+
167+
.PHONY: $(KUSTOMIZE)
164168
$(KUSTOMIZE):
165169
@GO_MODULE=true hack/download-tool.sh sigs.k8s.io/kustomize/kustomize/v5 kustomize $(KUSTOMIZE_VERSION)
166170

167171
.PHONY: envtest
168172
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
173+
174+
.PHONY: $(ENVTEST)
169175
$(ENVTEST):
170176
@GO_MODULE=true hack/download-tool.sh sigs.k8s.io/controller-runtime/tools/setup-envtest setup-envtest $(ENVTEST_VERSION)
171177

172178
.PHONY: golangci-lint
173179
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
180+
181+
.PHONY: $(GOLANGCI_LINT)
174182
$(GOLANGCI_LINT):
175183
@hack/download-tool.sh https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-$(shell go env GOOS)-$(shell go env GOARCH).tar.gz golangci-lint $(GOLANGCI_LINT_VERSION)
176184

177185
.PHONY: reconciler-gen
178186
reconciler-gen: $(RECONCILER_GEN) ## Download reconciler-gen locally if necessary.
187+
188+
.PHONY: $(RECONCILER_GEN)
179189
$(RECONCILER_GEN):
180190
@GO_MODULE=true hack/download-tool.sh k8c.io/reconciler/cmd/reconciler-gen reconciler-gen $(RECONCILER_GEN_VER)
181191

182192
.PHONY: openshift-goimports
183193
openshift-goimports: $(OPENSHIFT_GOIMPORTS) ## Download openshift-goimports locally if necessary.
194+
195+
.PHONY: $(OPENSHIFT_GOIMPORTS)
184196
$(OPENSHIFT_GOIMPORTS):
185197
@GO_MODULE=true hack/download-tool.sh github.com/openshift-eng/openshift-goimports openshift-goimports $(OPENSHIFT_GOIMPORTS_VER)

internal/controller/frontproxy_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (r *FrontProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
9494
logger.V(4).Info("Reconciling")
9595

9696
var frontProxy operatorv1alpha1.FrontProxy
97-
if err := r.Client.Get(ctx, req.NamespacedName, &frontProxy); err != nil {
97+
if err := r.Get(ctx, req.NamespacedName, &frontProxy); err != nil {
9898
if ctrlruntimeclient.IgnoreNotFound(err) != nil {
9999
return ctrl.Result{}, fmt.Errorf("failed to get FrontProxy object: %w", err)
100100
}
@@ -204,7 +204,7 @@ func (r *FrontProxyReconciler) reconcileStatus(ctx context.Context, oldFrontProx
204204

205205
// only patch the status if there are actual changes.
206206
if !equality.Semantic.DeepEqual(oldFrontProxy.Status, frontProxy.Status) {
207-
if err := r.Client.Status().Patch(ctx, frontProxy, ctrlruntimeclient.MergeFrom(oldFrontProxy)); err != nil {
207+
if err := r.Status().Patch(ctx, frontProxy, ctrlruntimeclient.MergeFrom(oldFrontProxy)); err != nil {
208208
errs = append(errs, err)
209209
}
210210
}

internal/controller/kubeconfig_controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (r *KubeconfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
6969
logger.V(4).Info("Reconciling")
7070

7171
var kc operatorv1alpha1.Kubeconfig
72-
if err := r.Client.Get(ctx, req.NamespacedName, &kc); err != nil {
72+
if err := r.Get(ctx, req.NamespacedName, &kc); err != nil {
7373
return ctrl.Result{}, err
7474
}
7575

@@ -80,7 +80,7 @@ func (r *KubeconfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
8080
switch {
8181
case kc.Spec.Target.RootShardRef != nil:
8282
var rootShard operatorv1alpha1.RootShard
83-
if err := r.Client.Get(ctx, types.NamespacedName{Name: kc.Spec.Target.RootShardRef.Name, Namespace: req.Namespace}, &rootShard); err != nil {
83+
if err := r.Get(ctx, types.NamespacedName{Name: kc.Spec.Target.RootShardRef.Name, Namespace: req.Namespace}, &rootShard); err != nil {
8484
return ctrl.Result{}, fmt.Errorf("failed to get RootShard: %w", err)
8585
}
8686

@@ -91,7 +91,7 @@ func (r *KubeconfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
9191

9292
case kc.Spec.Target.ShardRef != nil:
9393
var shard operatorv1alpha1.Shard
94-
if err := r.Client.Get(ctx, types.NamespacedName{Name: kc.Spec.Target.ShardRef.Name, Namespace: req.Namespace}, &shard); err != nil {
94+
if err := r.Get(ctx, types.NamespacedName{Name: kc.Spec.Target.ShardRef.Name, Namespace: req.Namespace}, &shard); err != nil {
9595
return ctrl.Result{}, fmt.Errorf("failed to get Shard: %w", err)
9696
}
9797

@@ -100,7 +100,7 @@ func (r *KubeconfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
100100
return ctrl.Result{}, errors.New("the Shard does not reference a (valid) RootShard")
101101
}
102102
var rootShard operatorv1alpha1.RootShard
103-
if err := r.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: req.Namespace}, &rootShard); err != nil {
103+
if err := r.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: req.Namespace}, &rootShard); err != nil {
104104
return ctrl.Result{}, fmt.Errorf("failed to get RootShard: %w", err)
105105
}
106106

@@ -112,7 +112,7 @@ func (r *KubeconfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
112112

113113
case kc.Spec.Target.FrontProxyRef != nil:
114114
var frontProxy operatorv1alpha1.FrontProxy
115-
if err := r.Client.Get(ctx, types.NamespacedName{Name: kc.Spec.Target.FrontProxyRef.Name, Namespace: req.Namespace}, &frontProxy); err != nil {
115+
if err := r.Get(ctx, types.NamespacedName{Name: kc.Spec.Target.FrontProxyRef.Name, Namespace: req.Namespace}, &frontProxy); err != nil {
116116
return ctrl.Result{}, fmt.Errorf("referenced FrontProxy '%s' does not exist", kc.Spec.Target.FrontProxyRef.Name)
117117
}
118118

@@ -121,7 +121,7 @@ func (r *KubeconfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
121121
return ctrl.Result{}, errors.New("the FrontProxy does not reference a (valid) RootShard")
122122
}
123123
var rootShard operatorv1alpha1.RootShard
124-
if err := r.Client.Get(ctx, types.NamespacedName{Name: frontProxy.Spec.RootShard.Reference.Name, Namespace: req.Namespace}, &rootShard); err != nil {
124+
if err := r.Get(ctx, types.NamespacedName{Name: frontProxy.Spec.RootShard.Reference.Name, Namespace: req.Namespace}, &rootShard); err != nil {
125125
return ctrl.Result{}, fmt.Errorf("failed to get RootShard: %w", err)
126126
}
127127

@@ -174,7 +174,7 @@ func (r *KubeconfigReconciler) getCertificateSecret(ctx context.Context, name, n
174174
logger := log.FromContext(ctx).WithValues("certificate", name)
175175

176176
certificate := &certmanagerv1.Certificate{}
177-
if err := r.Client.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, certificate); err != nil {
177+
if err := r.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, certificate); err != nil {
178178
// Because of how the reconciling framework works, this should never happen.
179179
logger.V(6).Info("Certificate does not exist yet, trying later ...")
180180
return nil, nil
@@ -194,7 +194,7 @@ func (r *KubeconfigReconciler) getCertificateSecret(ctx context.Context, name, n
194194
}
195195

196196
secret := &corev1.Secret{}
197-
if err := r.Client.Get(ctx, types.NamespacedName{Name: certificate.Spec.SecretName, Namespace: certificate.Namespace}, secret); err != nil {
197+
if err := r.Get(ctx, types.NamespacedName{Name: certificate.Spec.SecretName, Namespace: certificate.Namespace}, secret); err != nil {
198198
return nil, err
199199
}
200200

internal/controller/rootshard_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (r *RootShardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
8181
logger.V(4).Info("Reconciling")
8282

8383
var rootShard operatorv1alpha1.RootShard
84-
if err := r.Client.Get(ctx, req.NamespacedName, &rootShard); err != nil {
84+
if err := r.Get(ctx, req.NamespacedName, &rootShard); err != nil {
8585
if ctrlruntimeclient.IgnoreNotFound(err) != nil {
8686
return ctrl.Result{}, fmt.Errorf("failed to find %s/%s: %w", req.Namespace, req.Name, err)
8787
}
@@ -199,7 +199,7 @@ func (r *RootShardReconciler) reconcileStatus(ctx context.Context, oldRootShard
199199

200200
// only patch the status if there are actual changes.
201201
if !equality.Semantic.DeepEqual(oldRootShard.Status, rootShard.Status) {
202-
if err := r.Client.Status().Patch(ctx, rootShard, ctrlruntimeclient.MergeFrom(oldRootShard)); err != nil {
202+
if err := r.Status().Patch(ctx, rootShard, ctrlruntimeclient.MergeFrom(oldRootShard)); err != nil {
203203
errs = append(errs, err)
204204
}
205205
}

internal/controller/shard_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (r *ShardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
9393
logger.V(4).Info("Reconciling Shard object")
9494

9595
var s operatorv1alpha1.Shard
96-
if err := r.Client.Get(ctx, req.NamespacedName, &s); err != nil {
96+
if err := r.Get(ctx, req.NamespacedName, &s); err != nil {
9797
if ctrlruntimeclient.IgnoreNotFound(err) != nil {
9898
return ctrl.Result{}, fmt.Errorf("failed to get shard: %w", err)
9999
}

internal/resources/frontproxy/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func DeploymentReconciler(frontProxy *operatorv1alpha1.FrontProxy, rootShard *op
3939
dep.Spec.Selector = &metav1.LabelSelector{
4040
MatchLabels: resources.GetFrontProxyResourceLabels(frontProxy),
4141
}
42-
dep.Spec.Template.ObjectMeta.SetLabels(resources.GetFrontProxyResourceLabels(frontProxy))
42+
dep.Spec.Template.SetLabels(resources.GetFrontProxyResourceLabels(frontProxy))
4343

4444
image, _ := resources.GetImageSettings(frontProxy.Spec.Image)
4545
args := getArgs(&frontProxy.Spec)

internal/resources/rootshard/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func DeploymentReconciler(rootShard *operatorv1alpha1.RootShard) reconciling.Nam
7070
dep.Spec.Selector = &metav1.LabelSelector{
7171
MatchLabels: labels,
7272
}
73-
dep.Spec.Template.ObjectMeta.SetLabels(labels)
73+
dep.Spec.Template.SetLabels(labels)
7474

7575
secretMounts := []utils.SecretMount{{
7676
VolumeName: "kcp-ca",

internal/resources/shard/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func DeploymentReconciler(shard *operatorv1alpha1.Shard, rootShard *operatorv1al
6969
dep.Spec.Selector = &metav1.LabelSelector{
7070
MatchLabels: labels,
7171
}
72-
dep.Spec.Template.ObjectMeta.SetLabels(labels)
72+
dep.Spec.Template.SetLabels(labels)
7373

7474
secretMounts := []utils.SecretMount{{
7575
VolumeName: "kcp-ca",

internal/resources/utils/shard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
func ApplyCommonShardConfig(deployment *appsv1.Deployment, spec *operatorv1alpha1.CommonShardSpec) (*appsv1.Deployment, error) {
3333
if len(deployment.Spec.Template.Spec.Containers) == 0 {
34+
//nolint:staticcheck // allow capital letter in error message
3435
return deployment, errors.New("Deployment does not contain any containers")
3536
}
3637

0 commit comments

Comments
 (0)