Skip to content

Commit

Permalink
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 8, 2022
1 parent 6790057 commit 5bc0e95
Show file tree
Hide file tree
Showing 33 changed files with 81 additions and 64 deletions.
3 changes: 2 additions & 1 deletion src/go/k8s/.golangci.yml
Original file line number Diff line number Diff line change
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 src/go/k8s/apis/redpanda/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
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 @@ -908,12 +909,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 @@ -925,6 +928,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 src/go/k8s/apis/redpanda/v1alpha1/cluster_types_test.go
Original file line number Diff line number Diff line change
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
16 changes: 8 additions & 8 deletions src/go/k8s/apis/redpanda/v1alpha1/cluster_webhook_test.go
Original file line number Diff line number Diff line change
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 @@ -1233,7 +1233,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 @@ -1256,7 +1256,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 @@ -1279,7 +1279,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 @@ -1302,7 +1302,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
4 changes: 2 additions & 2 deletions src/go/k8s/apis/redpanda/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
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 src/go/k8s/apis/redpanda/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
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
7 changes: 4 additions & 3 deletions src/go/k8s/controllers/redpanda/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ type ClusterReconciler struct {
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/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 @@ -295,7 +296,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 @@ -380,7 +381,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 src/go/k8s/controllers/redpanda/console_controller.go
Original file line number Diff line number Diff line change
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),
}
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
6 changes: 3 additions & 3 deletions src/go/k8s/controllers/redpanda/suite_test.go
Original file line number Diff line number Diff line change
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 src/go/k8s/main.go
Original file line number Diff line number Diff line change
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 src/go/k8s/pkg/admin/admin.go
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions src/go/k8s/pkg/console/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ var (
// REF https://github.com/redpanda-data/console/blob/master/backend/pkg/schema/client.go#L60
DefaultCaFilePath = "/etc/ssl/certs/ca-certificates.crt"

SchemaRegistryTLSDir = "/redpanda/schema-registry" // nolint:revive // readable enough
SchemaRegistryTLSDir = "/redpanda/schema-registry"
SchemaRegistryTLSCaFilePath = fmt.Sprintf("%s/%s", SchemaRegistryTLSDir, "ca.crt")
SchemaRegistryTLSCertFilePath = fmt.Sprintf("%s/%s", SchemaRegistryTLSDir, "tls.crt")
SchemaRegistryTLSKeyFilePath = fmt.Sprintf("%s/%s", SchemaRegistryTLSDir, "tls.key")
Expand Down Expand Up @@ -350,7 +350,7 @@ func (cm *ConfigMap) delete(ctx context.Context, skip string) error {
if err := cm.List(ctx, cms, client.MatchingLabels(labels.ForConsole(cm.consoleobj)), client.InNamespace(cm.consoleobj.GetNamespace())); err != nil {
return err
}
for _, obj := range cms.Items { // nolint:gocritic // more readable, configmap list is few
for _, obj := range cms.Items { //nolint:gocritic // more readable, configmap list is few
if skip != "" && skip == obj.GetName() {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion src/go/k8s/pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
)

// ConsoleConfig is the config passed to the Redpanda Console app
type ConsoleConfig struct { // nolint:revive // more readable
type ConsoleConfig struct {
// Grabbed from https://github.com/redpanda-data/console/
// Copying the config types because they don't have Enterprise fields and not all fields are supported yet
MetricsNamespace string `json:"metricsNamespace" yaml:"metricsNamespace"`
Expand Down
4 changes: 2 additions & 2 deletions src/go/k8s/pkg/console/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (d *Deployment) ensureSyncedSecrets(ctx context.Context) (string, error) {
if d.clusterobj.IsSchemaRegistryMutualTLSEnabled() {
clientCert, exists := d.store.GetSchemaRegistryClientCert(d.clusterobj)
if !exists {
return "", fmt.Errorf("get schema registry client certificate: %s", "not found") // nolint:goerr113 // no need to declare new error type
return "", fmt.Errorf("get schema registry client certificate: %s", "not found") //nolint:goerr113 // no need to declare new error type
}
certfile := getOrEmpty("tls.crt", clientCert.Data)
keyfile := getOrEmpty("tls.key", clientCert.Data)
Expand All @@ -200,7 +200,7 @@ func (d *Deployment) ensureSyncedSecrets(ctx context.Context) (string, error) {
if ca.useCaCert() {
caCert, exists := d.store.GetSchemaRegistryNodeCert(d.clusterobj)
if !exists {
return "", fmt.Errorf("get schema registry node certificate: %s", "not found") // nolint:goerr113 // no need to declare new error type
return "", fmt.Errorf("get schema registry node certificate: %s", "not found") //nolint:goerr113 // no need to declare new error type
}
cafile := getOrEmpty("ca.crt", caCert.Data)
data["ca.crt"] = []byte(cafile)
Expand Down
2 changes: 1 addition & 1 deletion src/go/k8s/pkg/console/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewStore(cl client.Client) *Store {

// Sync synchronizes watched resources to the store
func (s *Store) Sync(cluster *redpandav1alpha1.Cluster) error {
if cluster.IsSchemaRegistryTLSEnabled() { // nolint:nestif // sync is complex
if cluster.IsSchemaRegistryTLSEnabled() { //nolint:nestif // sync is complex
if cluster.IsSchemaRegistryMutualTLSEnabled() {
schemaRegistryClientCert, err := syncSchemaRegistryCert(
s.context,
Expand Down
2 changes: 1 addition & 1 deletion src/go/k8s/pkg/networking/ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/stretchr/testify/assert"
)

// nolint:funlen // this is ok for a test
//nolint:funlen // this is ok for a test
func TestRedpandaPorts(t *testing.T) {
tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion src/go/k8s/pkg/resources/certmanager/type_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

// nolint:funlen // the subtests might causes linter to complain
//nolint:funlen // the subtests might causes linter to complain
func TestClusterCertificates(t *testing.T) {
secret := corev1.Secret{
ObjectMeta: v1.ObjectMeta{
Expand Down
3 changes: 2 additions & 1 deletion src/go/k8s/pkg/resources/cluster_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func NewClusterService(
}

// Ensure will manage kubernetes v1.Service for redpanda.vectorized.io custom resource
// nolint:dupl // TODO multiple services have the same Ensure function
//
//nolint:dupl // TODO multiple services have the same Ensure function
func (r *ClusterServiceResource) Ensure(ctx context.Context) error {
if len(r.svcPorts) == 0 {
return nil
Expand Down
Loading

0 comments on commit 5bc0e95

Please sign in to comment.