Skip to content

Commit

Permalink
operator: k8s: bump golangci-lint to latest version
Browse files Browse the repository at this point in the history
There was a change for nolint directives:
golangci/golangci-lint#3109 (comment)

And we are adding confidence of 0.8 in revive to
avoid false positives.
  • Loading branch information
r-vasquez committed Sep 13, 2022
1 parent b0c1cbf commit 1b5b6f6
Show file tree
Hide file tree
Showing 37 changed files with 92 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Expand Up @@ -26,10 +26,11 @@ linters-settings:
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
revive:
confidence: 0.8

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
Expand Down
14 changes: 9 additions & 5 deletions apis/redpanda/v1alpha1/cluster_types.go
Expand Up @@ -50,11 +50,12 @@ type RedpandaResourceRequirements struct {
// * Is limited by 2Gi per core if requests.memory is set.
//
// Example:
// in: minimum requirement per core, 2GB
// in: Requests.Memory, 16GB
// => maxAllowedCores = 8
// if requestedCores == 8, set smp = 8 (with 2GB per core)
// if requestedCores == 4, set smp = 4 (with 4GB per core)
//
// in: minimum requirement per core, 2GB
// in: Requests.Memory, 16GB
// => maxAllowedCores = 8
// if requestedCores == 8, set smp = 8 (with 2GB per core)
// if requestedCores == 4, set smp = 4 (with 4GB per core)
func (r *RedpandaResourceRequirements) RedpandaCPU() *resource.Quantity {
q := r.Redpanda.Cpu()
if q == nil || q.IsZero() {
Expand Down Expand Up @@ -924,12 +925,14 @@ type TLSConfig struct {
// Kafka API

// GetPort returns API port
//
//nolint:gocritic // TODO KafkaAPI is now 81 bytes, consider a pointer
func (k KafkaAPI) GetPort() int {
return k.Port
}

// GetTLS returns API TLSConfig
//
//nolint:gocritic // TODO KafkaAPI is now 81 bytes, consider a pointer
func (k KafkaAPI) GetTLS() *TLSConfig {
return &TLSConfig{
Expand All @@ -941,6 +944,7 @@ func (k KafkaAPI) GetTLS() *TLSConfig {
}

// GetExternal returns API's ExternalConnectivityConfig
//
//nolint:gocritic // TODO KafkaAPI is now 81 bytes, consider a pointer
func (k KafkaAPI) GetExternal() *ExternalConnectivityConfig {
return &k.External
Expand Down
2 changes: 1 addition & 1 deletion apis/redpanda/v1alpha1/cluster_types_test.go
Expand Up @@ -21,7 +21,7 @@ import (
"k8s.io/utils/pointer"
)

// nolint:funlen // this is ok for a test
//nolint:funlen // this is ok for a test
func TestRedpandaResourceRequirements(t *testing.T) {
type test struct {
name string
Expand Down
6 changes: 3 additions & 3 deletions apis/redpanda/v1alpha1/cluster_webhook.go
Expand Up @@ -366,7 +366,7 @@ func (r *Cluster) validateKafkaListeners() field.ErrorList {
r.Spec.Configuration.KafkaAPI,
"bootstrap port cannot be empty"))
}
// nolint:dupl // not identical
//nolint:dupl // not identical
if external != nil && external.External.EndpointTemplate != "" {
if external.External.Subdomain == "" {
allErrs = append(allErrs,
Expand Down Expand Up @@ -395,7 +395,7 @@ func checkValidEndpointTemplate(tmpl string) error {
return err
}

// nolint:funlen,gocyclo // it's a sequence of checks
//nolint:funlen,gocyclo // it's a sequence of checks
func (r *Cluster) validatePandaproxyListeners() field.ErrorList {
var allErrs field.ErrorList
var proxyExternal *PandaproxyAPI
Expand Down Expand Up @@ -447,7 +447,7 @@ func (r *Cluster) validatePandaproxyListeners() field.ErrorList {
r.Spec.Configuration.PandaproxyAPI[i],
"sudomain of external pandaproxy must be the same as kafka's"))
}
// nolint:dupl // not identical
//nolint:dupl // not identical
if kafkaExternal != nil && proxyExternal.External.EndpointTemplate != "" {
if proxyExternal.External.Subdomain == "" {
allErrs = append(allErrs,
Expand Down
22 changes: 11 additions & 11 deletions apis/redpanda/v1alpha1/cluster_webhook_test.go
Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/utils/pointer"
)

// nolint:funlen // this is ok for a test
//nolint:funlen // this is ok for a test
func TestDefault(t *testing.T) {
type test struct {
name string
Expand Down Expand Up @@ -780,7 +780,7 @@ func TestCreation(t *testing.T) {
assert.Error(t, err)
})

// nolint:dupl // the values are different
//nolint:dupl // the values are different
t.Run("incorrect redpanda memory (need <= limit)", func(t *testing.T) {
memory := redpandaCluster.DeepCopy()
memory.Spec.Resources = v1alpha1.RedpandaResourceRequirements{
Expand All @@ -804,7 +804,7 @@ func TestCreation(t *testing.T) {
assert.Error(t, err)
})

// nolint:dupl // the values are different
//nolint:dupl // the values are different
t.Run("correct redpanda memory", func(t *testing.T) {
memory := redpandaCluster.DeepCopy()
memory.Spec.Resources = v1alpha1.RedpandaResourceRequirements{
Expand All @@ -828,7 +828,7 @@ func TestCreation(t *testing.T) {
assert.NoError(t, err)
})

// nolint:dupl // the values are different
//nolint:dupl // the values are different
t.Run("correct redpanda memory (boundary check)", func(t *testing.T) {
memory := redpandaCluster.DeepCopy()
memory.Spec.Resources = v1alpha1.RedpandaResourceRequirements{
Expand Down Expand Up @@ -1038,7 +1038,7 @@ func TestCreation(t *testing.T) {
err := rp.ValidateCreate()
assert.Error(t, err)
})
// nolint:dupl // not really a duplicate
//nolint:dupl // not really a duplicate
t.Run("endpoint template not allowed for adminapi", func(t *testing.T) {
rp := redpandaCluster.DeepCopy()
const commonDomain = "company.org"
Expand Down Expand Up @@ -1100,7 +1100,7 @@ func TestCreation(t *testing.T) {
err := rp.ValidateCreate()
assert.NoError(t, err)
})
// nolint:dupl // not really a duplicate
//nolint:dupl // not really a duplicate
t.Run("invalid endpoint template in pandaproxy API", func(t *testing.T) {
rp := redpandaCluster.DeepCopy()

Expand All @@ -1117,7 +1117,7 @@ func TestCreation(t *testing.T) {
err := rp.ValidateCreate()
assert.Error(t, err)
})
// nolint:dupl // not really a duplicate
//nolint:dupl // not really a duplicate
t.Run("valid endpoint template in pandaproxy API", func(t *testing.T) {
rp := redpandaCluster.DeepCopy()

Expand Down Expand Up @@ -1345,7 +1345,7 @@ func TestExternalKafkaPortSpecified(t *testing.T) {
func TestKafkaTLSRules(t *testing.T) {
rpCluster := validRedpandaCluster()

// nolint:dupl // the tests are not duplicates
//nolint:dupl // the tests are not duplicates
t.Run("different issuer for two tls listeners", func(t *testing.T) {
newRp := rpCluster.DeepCopy()
newRp.Spec.Configuration.KafkaAPI[0].TLS = v1alpha1.KafkaAPITLS{
Expand All @@ -1368,7 +1368,7 @@ func TestKafkaTLSRules(t *testing.T) {
assert.Error(t, err)
})

// nolint:dupl // the tests are not duplicates
//nolint:dupl // the tests are not duplicates
t.Run("same issuer for two tls listeners is allowed", func(t *testing.T) {
newRp := rpCluster.DeepCopy()
newRp.Spec.Configuration.KafkaAPI[0].TLS = v1alpha1.KafkaAPITLS{
Expand All @@ -1391,7 +1391,7 @@ func TestKafkaTLSRules(t *testing.T) {
assert.NoError(t, err)
})

// nolint:dupl // the tests are not duplicates
//nolint:dupl // the tests are not duplicates
t.Run("different nodeSecretRef for two tls listeners", func(t *testing.T) {
newRp := rpCluster.DeepCopy()
newRp.Spec.Configuration.KafkaAPI[0].TLS = v1alpha1.KafkaAPITLS{
Expand All @@ -1414,7 +1414,7 @@ func TestKafkaTLSRules(t *testing.T) {
assert.Error(t, err)
})

// nolint:dupl // the tests are not duplicates
//nolint:dupl // the tests are not duplicates
t.Run("same nodesecretref for two tls listeners is allowed", func(t *testing.T) {
newRp := rpCluster.DeepCopy()
newRp.Spec.Configuration.KafkaAPI[0].TLS = v1alpha1.KafkaAPITLS{
Expand Down
2 changes: 1 addition & 1 deletion apis/redpanda/v1alpha1/common_types.go
Expand Up @@ -42,7 +42,7 @@ func (s *SecretKeyRef) GetValue(secret *corev1.Secret, defaultKey string) ([]byt

value, ok := secret.Data[key]
if !ok {
return nil, fmt.Errorf("getting value from Secret %s/%s: key %s not found", s.Namespace, s.Name, key) // nolint:goerr113 // no need to declare new error type
return nil, fmt.Errorf("getting value from Secret %s/%s: key %s not found", s.Namespace, s.Name, key) //nolint:goerr113 // no need to declare new error type
}
return value, nil
}
Expand Down
4 changes: 2 additions & 2 deletions apis/redpanda/v1alpha1/groupversion_info.go
Expand Up @@ -8,8 +8,8 @@
// by the Apache License, Version 2.0

// Package v1alpha1 contains API Schema definitions for the redpanda v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=redpanda.vectorized.io
// +kubebuilder:object:generate=true
// +groupName=redpanda.vectorized.io
package v1alpha1

import (
Expand Down
4 changes: 2 additions & 2 deletions apis/redpanda/v1alpha1/webhook_suite_test.go
Expand Up @@ -21,7 +21,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
redpandav1alpha1 "github.com/redpanda-data/redpanda/src/go/k8s/apis/redpanda/v1alpha1"
admissionv1beta1 "k8s.io/api/admission/v1beta1" // nolint:goimports // crlfmt
admissionv1beta1 "k8s.io/api/admission/v1beta1" //nolint:goimports // crlfmt
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -108,7 +108,7 @@ var _ = BeforeSuite(func() {
dialer := &net.Dialer{Timeout: time.Second}
addrPort := fmt.Sprintf("%s:%d", webhookInstallOptions.LocalServingHost, webhookInstallOptions.LocalServingPort)
Eventually(func() error {
// nolint:gosec // the tests can have insecure verify flag set to true
//nolint:gosec // the tests can have insecure verify flag set to true
conn, err := tls.DialWithDialer(dialer, "tcp", addrPort, &tls.Config{InsecureSkipVerify: true})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/configurator/main.go
Expand Up @@ -297,7 +297,7 @@ func getExternalIP(node *corev1.Node) string {
return ""
}

// nolint:funlen // envs are many
//nolint:funlen // envs are many
func checkEnvVars() (configuratorConfig, error) {
var result error
var extCon string
Expand Down
7 changes: 4 additions & 3 deletions controllers/redpanda/cluster_controller.go
Expand Up @@ -80,7 +80,8 @@ type ClusterReconciler struct {
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.7.0/pkg/reconcile
// nolint:funlen // todo break down
//
//nolint:funlen // todo break down
func (r *ClusterReconciler) Reconcile(
ctx context.Context, req ctrl.Request,
) (ctrl.Result, error) {
Expand Down Expand Up @@ -297,7 +298,7 @@ func (r *ClusterReconciler) reportStatus(
}

observedNodesInternal := make([]string, 0, len(observedPods.Items))
// nolint:gocritic // the copies are necessary for further redpandacluster updates
//nolint:gocritic // the copies are necessary for further redpandacluster updates
for _, item := range observedPods.Items {
observedNodesInternal = append(observedNodesInternal, fmt.Sprintf("%s.%s", item.Name, internalFQDN))
}
Expand Down Expand Up @@ -382,7 +383,7 @@ func (r *ClusterReconciler) WithClusterDomain(
return r
}

// nolint:funlen,gocyclo // External nodes list should be refactored
//nolint:funlen,gocyclo // External nodes list should be refactored
func (r *ClusterReconciler) createExternalNodesList(
ctx context.Context,
pods []corev1.Pod,
Expand Down
5 changes: 3 additions & 2 deletions controllers/redpanda/cluster_controller_configuration.go
Expand Up @@ -28,7 +28,8 @@ import (
)

// reconcileConfiguration ensures that the cluster configuration is synchronized with expected data
// nolint:funlen // splitting makes it difficult to follow
//
//nolint:funlen // splitting makes it difficult to follow
func (r *ClusterReconciler) reconcileConfiguration(
ctx context.Context,
redpandaCluster *redpandav1alpha1.Cluster,
Expand Down Expand Up @@ -345,7 +346,7 @@ func (r *ClusterReconciler) synchronizeStatusWithCluster(
return redpandaCluster.Status.GetCondition(conditionData.Type), nil
}

// nolint:gocritic // I like this if else chain
//nolint:gocritic // I like this if else chain
func mapStatusToCondition(
clusterStatus admin.ConfigStatusResponse,
) redpandav1alpha1.ClusterCondition {
Expand Down
Expand Up @@ -48,7 +48,8 @@ type ClusterConfigurationDriftReconciler struct {
}

// Reconcile detects drift in configuration for clusters and schedules a patch.
// nolint:funlen // May be broken down
//
//nolint:funlen // May be broken down
func (r *ClusterConfigurationDriftReconciler) Reconcile(
ctx context.Context, req ctrl.Request,
) (ctrl.Result, error) {
Expand Down
4 changes: 2 additions & 2 deletions controllers/redpanda/console_controller.go
Expand Up @@ -74,7 +74,7 @@ func (r *ConsoleReconciler) Reconcile(
}
// Checks if Console is valid to be created in specified namespace
if !console.IsAllowedNamespace() {
err := fmt.Errorf("invalid Console namespace") // nolint:goerr113 // no need to declare new error type
err := fmt.Errorf("invalid Console namespace") //nolint:goerr113 // no need to declare new error type
log.Error(err, "Console must be created in Redpanda namespace. Set --allow-console-any-ns=true to enable")
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func (r *Reconciling) Do(
resources.NewIngress(r.Client, console, r.Scheme, subdomain, console.GetName(), consolepkg.ServicePortName, log).WithTLS(resources.LEClusterIssuer, fmt.Sprintf("%s-redpanda", cluster.GetName())),
}
for _, each := range applyResources {
if err := each.Ensure(ctx); err != nil { // nolint:gocritic // more readable
if err := each.Ensure(ctx); err != nil { //nolint:gocritic // more readable
var ra *resources.RequeueAfterError
if errors.As(err, &ra) {
log.V(debugLogLevel).Info(fmt.Sprintf("Requeue ensuring resource after %d: %s", ra.RequeueAfter, ra.Msg))
Expand Down
2 changes: 1 addition & 1 deletion controllers/redpanda/console_controller_test.go
Expand Up @@ -268,7 +268,7 @@ var _ = Describe("Console controller", func() {

var (
googleName = fmt.Sprintf("%s-google", ConsoleName)
googleClientId = "123456654321-abcdefghi123456abcdefghi123456ab.apps.googleusercontent.com" // nolint:stylecheck,revive // Console uses clientId naming
googleClientId = "123456654321-abcdefghi123456abcdefghi123456ab.apps.googleusercontent.com" //nolint:stylecheck // Console uses clientId naming
googleClientSecret = "some-random-client-secret"
)

Expand Down
6 changes: 3 additions & 3 deletions controllers/redpanda/suite_test.go
Expand Up @@ -355,7 +355,7 @@ func (m *mockAdminAPI) GetFeatures(
}, nil
}

// nolint:gocritic // It's test API
//nolint:gocritic // It's test API
func (m *mockAdminAPI) RegisterPropertySchema(
name string, metadata admin.ConfigPropertyMetadata,
) {
Expand Down Expand Up @@ -422,7 +422,7 @@ func (m *mockAdminAPI) GetNodeConfig(
return admin.NodeConfig{}, nil
}

// nolint:goerr113 // test code
//nolint:goerr113 // test code
func (s *scopedMockAdminAPI) GetNodeConfig(
ctx context.Context,
) (admin.NodeConfig, error) {
Expand Down Expand Up @@ -508,7 +508,7 @@ func (m *mockAdminAPI) DisableMaintenanceMode(_ context.Context, _ int) error {
return nil
}

// nolint:goerr113 // test code
//nolint:goerr113 // test code
func (m *mockAdminAPI) SetBrokerStatus(
id int, status admin.MembershipStatus,
) error {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Expand Up @@ -40,15 +40,15 @@ var (
setupLog = ctrl.Log.WithName("setup")
)

// nolint:wsl // the init was generated by kubebuilder
//nolint:wsl // the init was generated by kubebuilder
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(redpandav1alpha1.AddToScheme(scheme))
utilruntime.Must(cmapiv1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

// nolint:funlen // length looks good
//nolint:funlen // length looks good
func main() {
var (
clusterDomain string
Expand Down
6 changes: 4 additions & 2 deletions pkg/admin/admin.go
Expand Up @@ -75,7 +75,8 @@ func NewInternalAdminAPI(
}

// AdminAPIClient is a sub interface of the admin API containing what we need in the operator
// nolint:revive // usually package is called adminutils
//

type AdminAPIClient interface {
Config(ctx context.Context) (admin.Config, error)
ClusterConfigStatus(ctx context.Context, sendToLeader bool) (admin.ConfigStatusResponse, error)
Expand All @@ -99,7 +100,8 @@ type AdminAPIClient interface {
var _ AdminAPIClient = &admin.AdminAPI{}

// AdminAPIClientFactory is an abstract constructor of admin API clients
// nolint:revive // usually package is called adminutils
//

type AdminAPIClientFactory func(
ctx context.Context,
k8sClient client.Reader,
Expand Down

0 comments on commit 1b5b6f6

Please sign in to comment.