Skip to content

Commit c83e05e

Browse files
authored
Merge pull request #2003 from kube-logging/chore/migrate-to-v2-golangci
chore: migrate to v2 golangci-lint
2 parents 1a256b6 + d483f54 commit c83e05e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+158
-154
lines changed

.golangci.yml

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
1-
linters-settings:
2-
revive:
3-
min-confidence: 0.9
4-
gocyclo:
5-
min-complexity: 15
1+
version: "2"
2+
run:
3+
timeout: 10m
4+
allow-parallel-runners: true
65

6+
formatters:
7+
settings:
8+
gci:
9+
sections:
10+
- standard
11+
- default
12+
- prefix(github.com/kube-logging/logging-operator)
13+
goimports:
14+
local-prefixes:
15+
- github.com/kube-logging/logging-operator
16+
gofmt:
17+
simplify: true
18+
gofumpt:
19+
extra-rules: false
720

8-
issues:
9-
exclude-dirs:
10-
- .gen
11-
- client
12-
exclude:
13-
- if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
14-
- "`if` block ends with a `return` statement, so drop this `else` and outdent its block"
15-
- "missing the call to method parallel"
21+
linters:
22+
settings:
23+
misspell:
24+
locale: US
25+
revive:
26+
confidence: 0.9
27+
gocyclo:
28+
min-complexity: 15
29+
enable:
30+
- bodyclose
31+
- errcheck
32+
- ineffassign
33+
- misspell
34+
- nolintlint
35+
- revive
36+
- unconvert
37+
- unparam
38+
- unused
39+
- whitespace

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
CONTROLLER_GEN_VERSION := 0.17.2
99

1010
# renovate: datasource=github-releases depName=golangci/golangci-lint versioning=semver
11-
GOLANGCI_LINT_VERSION := 1.64.8
11+
GOLANGCI_LINT_VERSION := 2.0.2
1212

1313
# renovate: datasource=go depName=github.com/vladopajic/go-test-coverage/v2 versioning=semver
1414
GO_TEST_COVERAGE_VERSION := 2.13.0
@@ -284,7 +284,7 @@ ${ENVTEST_BINARY_ASSETS}_${ENVTEST_K8S_VERSION}: | ${SETUP_ENVTEST} ${ENVTEST_BI
284284
${GOLANGCI_LINT}: ${GOLANGCI_LINT}_${GOLANGCI_LINT_VERSION}_${GOVERSION} | ${BIN}
285285
ln -sf $(notdir $<) $@
286286

287-
${GOLANGCI_LINT}_${GOLANGCI_LINT_VERSION}_${GOVERSION}: IMPORT_PATH := github.com/golangci/golangci-lint/cmd/golangci-lint
287+
${GOLANGCI_LINT}_${GOLANGCI_LINT_VERSION}_${GOVERSION}: IMPORT_PATH := github.com/golangci/golangci-lint/v2/cmd/golangci-lint
288288
${GOLANGCI_LINT}_${GOLANGCI_LINT_VERSION}_${GOVERSION}: VERSION := v${GOLANGCI_LINT_VERSION}
289289
${GOLANGCI_LINT}_${GOLANGCI_LINT_VERSION}_${GOVERSION}: | ${BIN}
290290
${go_install_binary}

controllers/extensions/eventtailer_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (r *EventTailerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
5656

5757
eventTailer := loggingextensionsv1alpha1.EventTailer{}
5858

59-
if err := r.Client.Get(ctx, req.NamespacedName, &eventTailer); err != nil {
59+
if err := r.Get(ctx, req.NamespacedName, &eventTailer); err != nil {
6060
if apierrors.IsNotFound(err) {
6161
return reconcile.Result{}, nil
6262
}

controllers/extensions/hosttailer_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (r *HostTailerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
5454

5555
hosttailer := loggingextensionsv1alpha1.HostTailer{}
5656

57-
if err := r.Client.Get(ctx, req.NamespacedName, &hosttailer); err != nil {
57+
if err := r.Get(ctx, req.NamespacedName, &hosttailer); err != nil {
5858
if apierrors.IsNotFound(err) {
5959
return reconcile.Result{}, nil
6060
}

controllers/logging/logging_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
111111
log.V(1).Info("reconciling")
112112

113113
var logging loggingv1beta1.Logging
114-
if err := r.Client.Get(ctx, req.NamespacedName, &logging); err != nil {
114+
if err := r.Get(ctx, req.NamespacedName, &logging); err != nil {
115115
// If object is not found, return without error.
116116
// Created objects are automatically garbage collected.
117117
// For additional cleanup logic use finalizers.
@@ -120,14 +120,14 @@ func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
120120

121121
var missingCRDs []string
122122

123-
if err := r.Client.List(ctx, &v1.ServiceMonitorList{}); err == nil {
123+
if err := r.List(ctx, &v1.ServiceMonitorList{}); err == nil {
124124
//nolint:staticcheck
125125
ctx = context.WithValue(ctx, resources.ServiceMonitorKey, true)
126126
} else {
127127
missingCRDs = append(missingCRDs, "ServiceMonitor")
128128
}
129129

130-
if err := r.Client.List(ctx, &v1.PrometheusRuleList{}); err == nil {
130+
if err := r.List(ctx, &v1.PrometheusRuleList{}); err == nil {
131131
//nolint:staticcheck
132132
ctx = context.WithValue(ctx, resources.PrometheusRuleKey, true)
133133
} else {
@@ -384,7 +384,7 @@ func (r *LoggingReconciler) syslogNGConfigFinalizer(ctx context.Context, logging
384384

385385
func (r *LoggingReconciler) dynamicDefaults(ctx context.Context, log logr.Logger, syslogNGSpec *loggingv1beta1.SyslogNGSpec) {
386386
nodes := corev1.NodeList{}
387-
if err := r.Client.List(ctx, &nodes); err != nil {
387+
if err := r.List(ctx, &nodes); err != nil {
388388
log.Error(err, "listing nodes")
389389
}
390390
if syslogNGSpec != nil && syslogNGSpec.MaxConnections == 0 {

controllers/logging/loggingroute_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type LoggingRouteReconciler struct {
4949
// Reconcile routes between logging domains
5050
func (r *LoggingRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
5151
var loggingRoute loggingv1beta1.LoggingRoute
52-
if err := r.Client.Get(ctx, req.NamespacedName, &loggingRoute); err != nil {
52+
if err := r.Get(ctx, req.NamespacedName, &loggingRoute); err != nil {
5353
return reconcile.Result{}, client.IgnoreNotFound(err)
5454
}
5555

controllers/logging/telemetry_controller_controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (r *TelemetryControllerReconciler) Reconcile(ctx context.Context, req ctrl.
5353
log := r.Log.WithValues("telemetry-controller", req.Name)
5454

5555
var logging loggingv1beta1.Logging
56-
if err := r.Client.Get(ctx, req.NamespacedName, &logging); err != nil {
56+
if err := r.Get(ctx, req.NamespacedName, &logging); err != nil {
5757
return reconcile.Result{}, client.IgnoreNotFound(err)
5858
}
5959

@@ -100,11 +100,11 @@ func (r *TelemetryControllerReconciler) createTelemetryControllerResources(logge
100100
func (r *TelemetryControllerReconciler) finalizeLoggingForTelemetryController(ctx context.Context, logger logr.Logger, logging *loggingv1beta1.Logging, objectsToCreate *[]client.Object) error {
101101
logger.Info("Finalizing Telemetry controller resources")
102102

103-
if logging.ObjectMeta.DeletionTimestamp.IsZero() {
103+
if logging.DeletionTimestamp.IsZero() {
104104
if !controllerutil.ContainsFinalizer(logging, TelemetryControllerFinalizer) {
105105
r.Log.Info("adding telemetrycontroller finalizer")
106106
controllerutil.AddFinalizer(logging, TelemetryControllerFinalizer)
107-
if err := r.Client.Update(ctx, logging); err != nil {
107+
if err := r.Update(ctx, logging); err != nil {
108108
return err
109109
}
110110
}
@@ -117,7 +117,7 @@ func (r *TelemetryControllerReconciler) finalizeLoggingForTelemetryController(ct
117117

118118
r.Log.Info("removing telemetrycontroller finalizer")
119119
controllerutil.RemoveFinalizer(logging, TelemetryControllerFinalizer)
120-
if err := r.Client.Update(ctx, logging); err != nil {
120+
if err := r.Update(ctx, logging); err != nil {
121121
return err
122122
}
123123
}
@@ -130,11 +130,11 @@ func (r *TelemetryControllerReconciler) deployTelemetryControllerResources(ctx c
130130
logger.Info("Deploying Telemetry controller resources")
131131

132132
for _, objectToCreate := range *objectsToCreate {
133-
if err := r.Client.Get(ctx, client.ObjectKeyFromObject(objectToCreate), objectToCreate); err != nil {
133+
if err := r.Get(ctx, client.ObjectKeyFromObject(objectToCreate), objectToCreate); err != nil {
134134
if !apierrors.IsNotFound(err) {
135135
return err
136136
}
137-
if err := r.Client.Create(ctx, objectToCreate); err != nil {
137+
if err := r.Create(ctx, objectToCreate); err != nil {
138138
return err
139139
}
140140
logger.Info("Created object", "object", objectToCreate.GetName())
@@ -150,7 +150,7 @@ func (r *TelemetryControllerReconciler) deleteTelemetryControllerResources(ctx c
150150
logger.Info("Logging resource is being deleted, deleting Telemetry controller resources")
151151

152152
for _, obj := range *objectsToCreate {
153-
if err := r.Client.Delete(ctx, obj); err != nil {
153+
if err := r.Delete(ctx, obj); err != nil {
154154
return client.IgnoreNotFound(err)
155155
}
156156
logger.Info("Deleted object", "object", obj.GetName())
@@ -164,7 +164,7 @@ func (r *TelemetryControllerReconciler) isAggregatorReady(ctx context.Context, l
164164

165165
podName := fmt.Sprintf("%s-fluentd-0", logging.Name)
166166
pod := &corev1.Pod{}
167-
err := r.Client.Get(ctx, client.ObjectKey{Name: podName, Namespace: logging.Spec.ControlNamespace}, pod)
167+
err := r.Get(ctx, client.ObjectKey{Name: podName, Namespace: logging.Spec.ControlNamespace}, pod)
168168
if err != nil {
169169
if apierrors.IsNotFound(err) {
170170
return fmt.Errorf("aggregator pod: %s not found", podName)

docs/configuration/crds/v1beta1/fluentd_types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ ExtraVolume defines the fluentd extra volumes
228228

229229
## FluentdScaling
230230

231-
FluentdScaling enables configuring the scaling behaviour of the fluentd statefulset
231+
FluentdScaling enables configuring the scaling behavior of the fluentd statefulset
232232

233233
### drain (FluentdDrainConfig, optional) {#fluentdscaling-drain}
234234

docs/configuration/plugins/filters/elasticsearch_genid.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ You can specify keys which are record in events for hash generation seed. This p
6464

6565
### separator (string, optional) {#elasticsearchgenid-separator}
6666

67-
You can specify separator charactor to creating seed for hash generation.
67+
You can specify separator character to creating seed for hash generation.
6868

6969

7070
### use_entire_record (bool, optional) {#elasticsearchgenid-use_entire_record}

docs/configuration/plugins/filters/parser.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ If true, keep time field in the record.
127127

128128
### keys (string, optional) {#parse section-keys}
129129

130-
Names for fields on each line. (seperated by coma)
130+
Names for fields on each line. (separated by coma)
131131

132132

133133
### label_delimiter (string, optional) {#parse section-label_delimiter}

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ func main() {
257257
setupLog.Error(err, "problem running manager")
258258
os.Exit(1)
259259
}
260-
261260
}
262261

263262
// Extends sigs.k8s.io/[email protected]/pkg/manager/signals/signal.go with

pkg/resources/configcheck/configcheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func WithHashLabel(accessor v1.Object, hash string) {
3434
accessor.SetLabels(l)
3535
}
3636

37-
func hasHashLabel(accessor v1.Object, hash string) (has bool, match bool) {
37+
func hasHashLabel(accessor v1.Object, hash string) (has bool, match bool) { //nolint: unparam
3838
l := accessor.GetLabels()
3939
var val string
4040
val, has = l[HashLabel]

pkg/resources/eventtailer/clusterrolebinding.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@ package eventtailer
1717
import (
1818
"github.com/cisco-open/operator-tools/pkg/reconciler"
1919
rbacv1 "k8s.io/api/rbac/v1"
20-
v1 "k8s.io/api/rbac/v1"
2120
"k8s.io/apimachinery/pkg/runtime"
2221
)
2322

2423
// ClusterRoleBinding resource for reconciler
2524
func (e *EventTailer) ClusterRoleBinding() (runtime.Object, reconciler.DesiredState, error) {
26-
clusterRoleBinding := v1.ClusterRoleBinding{
25+
clusterRoleBinding := rbacv1.ClusterRoleBinding{
2726
ObjectMeta: e.clusterObjectMeta(),
28-
Subjects: []v1.Subject{
27+
Subjects: []rbacv1.Subject{
2928
{
3029
Kind: rbacv1.ServiceAccountKind,
3130
Name: e.Name(),
3231
Namespace: e.customResource.Spec.ControlNamespace,
3332
},
3433
},
35-
RoleRef: v1.RoleRef{
34+
RoleRef: rbacv1.RoleRef{
3635
APIGroup: rbacv1.GroupName,
3736
Kind: "ClusterRole",
3837
Name: e.Name(),

pkg/resources/eventtailer/helpers.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ import (
2020
"github.com/cisco-open/operator-tools/pkg/types"
2121
"github.com/cisco-open/operator-tools/pkg/utils"
2222
config "github.com/kube-logging/logging-operator/pkg/sdk/extensions/extensionsconfig"
23-
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
)
2525

2626
// Name .
2727
func (e *EventTailer) Name() string {
28-
return fmt.Sprintf("%v-%v", e.customResource.ObjectMeta.Name, config.EventTailer.TailerAffix)
28+
return fmt.Sprintf("%v-%v", e.customResource.Name, config.EventTailer.TailerAffix)
2929
}
3030

31-
func (e *EventTailer) objectMeta() v1.ObjectMeta {
32-
meta := v1.ObjectMeta{
31+
func (e *EventTailer) objectMeta() metav1.ObjectMeta {
32+
meta := metav1.ObjectMeta{
3333
Name: e.Name(),
3434
Namespace: e.customResource.Spec.ControlNamespace,
3535
Labels: e.selectorLabels(),
@@ -38,22 +38,22 @@ func (e *EventTailer) objectMeta() v1.ObjectMeta {
3838
return meta
3939
}
4040

41-
func (e *EventTailer) clusterObjectMeta() v1.ObjectMeta {
42-
meta := v1.ObjectMeta{
41+
func (e *EventTailer) clusterObjectMeta() metav1.ObjectMeta {
42+
meta := metav1.ObjectMeta{
4343
Name: e.Name(),
4444
Labels: e.selectorLabels(),
4545
OwnerReferences: e.ownerReferences(),
4646
}
4747
return meta
4848
}
4949

50-
func (e *EventTailer) ownerReferences() []v1.OwnerReference {
51-
ownerReferences := []v1.OwnerReference{
50+
func (e *EventTailer) ownerReferences() []metav1.OwnerReference {
51+
ownerReferences := []metav1.OwnerReference{
5252
{
53-
APIVersion: e.customResource.TypeMeta.APIVersion,
54-
Kind: e.customResource.TypeMeta.Kind,
55-
Name: e.customResource.ObjectMeta.Name,
56-
UID: e.customResource.ObjectMeta.UID,
53+
APIVersion: e.customResource.APIVersion,
54+
Kind: e.customResource.Kind,
55+
Name: e.customResource.Name,
56+
UID: e.customResource.UID,
5757
Controller: utils.BoolPointer(true),
5858
},
5959
}

pkg/resources/eventtailer/statefulset.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func (e *EventTailer) StatefulSet() (runtime.Object, reconciler.DesiredState, er
4747
}
4848

4949
func (e *EventTailer) statefulSetSpec() *appsv1.StatefulSetSpec {
50-
5150
if e.customResource.Spec.Image != nil {
5251
if repositoryWithTag := e.customResource.Spec.Image.RepositoryWithTag(); repositoryWithTag != "" {
5352
if e.customResource.Spec.ContainerBase == nil {
@@ -60,7 +59,7 @@ func (e *EventTailer) statefulSetSpec() *appsv1.StatefulSetSpec {
6059
if e.customResource.Spec.ContainerBase == nil {
6160
e.customResource.Spec.ContainerBase = &types.ContainerBase{}
6261
}
63-
e.customResource.Spec.ContainerBase.PullPolicy = corev1.PullPolicy(e.customResource.Spec.ContainerBase.PullPolicy)
62+
e.customResource.Spec.ContainerBase.PullPolicy = corev1.PullPolicy(e.customResource.Spec.ContainerBase.PullPolicy) //nolint: unconvert
6463
}
6564

6665
var imagePullSecrets []corev1.LocalObjectReference

pkg/resources/fluentbit/configsecret.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ func (r *Reconciler) configSecret() (runtime.Object, reconciler.DesiredState, er
306306
inputTail.DockerMode = ""
307307
inputTail.DockerModeFlush = ""
308308
inputTail.DockerModeParser = ""
309-
310309
} else if len(inputTail.ParserN) > 0 {
311310
input.Input.ParserN = inputTail.ParserN
312311
inputTail.ParserN = nil

pkg/resources/fluentbit/daemonset.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const (
3838
)
3939

4040
func (r *Reconciler) daemonSet() (runtime.Object, reconciler.DesiredState, error) {
41-
4241
labels := util.MergeLabels(r.fluentbitSpec.Labels, r.getFluentBitLabels())
4342
meta := r.FluentbitObjectMeta(fluentbitDaemonSetName)
4443
meta.Annotations = util.MergeLabels(meta.Annotations, r.fluentbitSpec.DaemonSetAnnotations)

pkg/resources/fluentbit/tenants.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ func (r *Reconciler) configureOutputsForTenants(ctx context.Context, tenants []v
124124
return errs
125125
}
126126

127-
func (r *Reconciler) configureInputsForTenants(tenants []v1beta1.Tenant, input *fluentBitConfig) error {
128-
var errs error
127+
func (r *Reconciler) configureInputsForTenants(tenants []v1beta1.Tenant, input *fluentBitConfig) error { //nolint: unparam
129128
for _, t := range tenants {
130129
allNamespaces := len(t.Namespaces) == 0
131130
tenantValues := maps.Clone(input.Input.Values)
@@ -150,7 +149,7 @@ func (r *Reconciler) configureInputsForTenants(tenants []v1beta1.Tenant, input *
150149
}
151150
// the regex will work only if we cut the prefix off. fluentbit doesn't care about the content, just the length
152151
input.KubernetesFilter["Kube_Tag_Prefix"] = `kubernetes.0000000000.var.log.containers.`
153-
return errs
152+
return nil
154153
}
155154

156155
func hashFromTenantName(input string) string {

0 commit comments

Comments
 (0)