From 980a33719a10024f45e44320316c5bd35cef18d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Th=C3=B6mmes?= Date: Wed, 26 May 2021 10:10:28 +0200 Subject: [PATCH] Fix revive related linting issues (#2131) --- apis/condition_set.go | 2 +- apis/condition_types.go | 2 +- apis/deprecated.go | 2 +- apis/duck/register.go | 1 + apis/duck/v1/register.go | 4 +++- apis/duck/v1alpha1/register.go | 4 +++- apis/duck/v1beta1/register.go | 4 +++- apis/test/example/register.go | 1 + apis/test/example/v1alpha1/register.go | 4 +++- apis/test/pub/register.go | 1 + apis/test/pub/v1alpha1/register.go | 4 +++- configmap/manual_watcher.go | 2 +- controller/controller.go | 3 ++- controller/stats_reporter.go | 4 +++- depcheck/heavy.go | 2 ++ metrics/metricstest/metricstest.go | 2 +- reconciler/events.go | 2 +- reconciler/reconcile_common.go | 10 ++++++--- system/env.go | 5 ++++- test/e2e_flags.go | 1 + test/gcs/mock/mock.go | 31 +++++++++++++++++--------- test/gcs/mock/mock_storage.go | 2 +- test/ha/ha.go | 3 ++- test/interactive/docker.go | 2 +- test/kube_checks.go | 2 +- test/tinterface.go | 2 ++ testing/duck/register.go | 4 +++- testing/inner_default_resource.go | 2 +- testing/register.go | 4 +++- tracing/testing/zipkin.go | 2 +- tracing/zipkin.go | 1 + webhook/admission.go | 1 + webhook/psbinding/psbinding.go | 2 +- 33 files changed, 82 insertions(+), 36 deletions(-) diff --git a/apis/condition_set.go b/apis/condition_set.go index 1d81355b3..1b110475f 100644 --- a/apis/condition_set.go +++ b/apis/condition_set.go @@ -27,7 +27,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// Conditions is the interface for a Resource that implements the getter and +// ConditionsAccessor is the interface for a Resource that implements the getter and // setter for accessing a Condition collection. // +k8s:deepcopy-gen=true type ConditionsAccessor interface { diff --git a/apis/condition_types.go b/apis/condition_types.go index 5b4288689..f0517527d 100644 --- a/apis/condition_types.go +++ b/apis/condition_types.go @@ -52,7 +52,7 @@ const ( ConditionSeverityInfo ConditionSeverity = "Info" ) -// Conditions defines a readiness condition for a Knative resource. +// Condition defines a readiness condition for a Knative resource. // See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties // +k8s:deepcopy-gen=true type Condition struct { diff --git a/apis/deprecated.go b/apis/deprecated.go index fc9bca5f1..fb73306fa 100644 --- a/apis/deprecated.go +++ b/apis/deprecated.go @@ -33,7 +33,7 @@ func CheckDeprecated(ctx context.Context, obj interface{}) *FieldError { return CheckDeprecatedUpdate(ctx, obj, nil) } -// CheckDeprecated checks whether the provided named deprecated fields +// CheckDeprecatedUpdate checks whether the provided named deprecated fields // are set in a context where deprecation is disallowed. // This is a json shallow check. We will recursively check inlined structs. func CheckDeprecatedUpdate(ctx context.Context, obj, original interface{}) *FieldError { diff --git a/apis/duck/register.go b/apis/duck/register.go index 93cf55d7f..34f13d6a2 100644 --- a/apis/duck/register.go +++ b/apis/duck/register.go @@ -21,6 +21,7 @@ import ( ) const ( + // GroupName is the name of the API group. GroupName = ducktypes.GroupName // AddressableDuckVersionLabel is the label we use to declare diff --git a/apis/duck/v1/register.go b/apis/duck/v1/register.go index 67418b3e9..fb4348a05 100644 --- a/apis/duck/v1/register.go +++ b/apis/duck/v1/register.go @@ -38,8 +38,10 @@ func Resource(resource string) schema.GroupResource { } var ( + // SchemeBuilder builds a scheme with the types known to the package. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme adds the types known to this package to an existing schema. + AddToScheme = SchemeBuilder.AddToScheme ) // Adds the list of known types to Scheme. diff --git a/apis/duck/v1alpha1/register.go b/apis/duck/v1alpha1/register.go index 6ae381400..333bae39d 100644 --- a/apis/duck/v1alpha1/register.go +++ b/apis/duck/v1alpha1/register.go @@ -37,8 +37,10 @@ func Resource(resource string) schema.GroupResource { } var ( + // SchemeBuilder builds a scheme with the types known to the package. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme adds the types known to this package to an existing schema. + AddToScheme = SchemeBuilder.AddToScheme ) // Adds the list of known types to Scheme. diff --git a/apis/duck/v1beta1/register.go b/apis/duck/v1beta1/register.go index 160eff56b..9ac1f16d6 100644 --- a/apis/duck/v1beta1/register.go +++ b/apis/duck/v1beta1/register.go @@ -38,8 +38,10 @@ func Resource(resource string) schema.GroupResource { } var ( + // SchemeBuilder builds a scheme with the types known to the package. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme adds the types known to this package to an existing schema. + AddToScheme = SchemeBuilder.AddToScheme ) // Adds the list of known types to Scheme. diff --git a/apis/test/example/register.go b/apis/test/example/register.go index aafd960c9..dd49bb6a8 100644 --- a/apis/test/example/register.go +++ b/apis/test/example/register.go @@ -17,5 +17,6 @@ limitations under the License. package example const ( + // GroupName is the name of the API group. GroupName = "example.knative.dev" ) diff --git a/apis/test/example/v1alpha1/register.go b/apis/test/example/v1alpha1/register.go index 7eb98a52c..8559279d5 100644 --- a/apis/test/example/v1alpha1/register.go +++ b/apis/test/example/v1alpha1/register.go @@ -37,8 +37,10 @@ func Resource(resource string) schema.GroupResource { } var ( + // SchemeBuilder builds a scheme with the types known to the package. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme adds the types known to this package to an existing schema. + AddToScheme = SchemeBuilder.AddToScheme ) // Adds the list of known types to Scheme. diff --git a/apis/test/pub/register.go b/apis/test/pub/register.go index aafd960c9..dd49bb6a8 100644 --- a/apis/test/pub/register.go +++ b/apis/test/pub/register.go @@ -17,5 +17,6 @@ limitations under the License. package example const ( + // GroupName is the name of the API group. GroupName = "example.knative.dev" ) diff --git a/apis/test/pub/v1alpha1/register.go b/apis/test/pub/v1alpha1/register.go index c5abe49ae..3e560e880 100644 --- a/apis/test/pub/v1alpha1/register.go +++ b/apis/test/pub/v1alpha1/register.go @@ -37,8 +37,10 @@ func Resource(resource string) schema.GroupResource { } var ( + // SchemeBuilder builds a scheme with the types known to the package. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme adds the types known to this package to an existing schema. + AddToScheme = SchemeBuilder.AddToScheme ) // Adds the list of known types to Scheme. diff --git a/configmap/manual_watcher.go b/configmap/manual_watcher.go index bd28e7c23..a2760b447 100644 --- a/configmap/manual_watcher.go +++ b/configmap/manual_watcher.go @@ -44,7 +44,7 @@ func (w *ManualWatcher) Watch(name string, o ...Observer) { w.observers[name] = append(w.observers[name], o...) } -// Watch implements Watcher +// ForEach implements Watcher func (w *ManualWatcher) ForEach(f func(string, []Observer) error) error { for k, v := range w.observers { if err := f(k, v); err != nil { diff --git a/controller/controller.go b/controller/controller.go index 747cf58ef..9593eef28 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -477,7 +477,8 @@ func (c *Impl) RunContext(ctx context.Context, threadiness int) error { return nil } -// DEPRECATED use RunContext instead. +// Run runs the controller. +// DEPRECATED: Use RunContext instead. func (c *Impl) Run(threadiness int, stopCh <-chan struct{}) error { // Create a context that is cancelled when the stopCh is called. ctx, cancel := context.WithCancel(context.Background()) diff --git a/controller/stats_reporter.go b/controller/stats_reporter.go index 474bab3fc..6735285db 100644 --- a/controller/stats_reporter.go +++ b/controller/stats_reporter.go @@ -48,7 +48,9 @@ var ( // - characters are printable US-ASCII reconcilerTagKey = tag.MustNewKey("reconciler") successTagKey = tag.MustNewKey("success") - NamespaceTagKey = tag.MustNewKey(metricskey.LabelNamespaceName) + + // NamespaceTagKey marks metrics with a namespace. + NamespaceTagKey = tag.MustNewKey(metricskey.LabelNamespaceName) ) func init() { diff --git a/depcheck/heavy.go b/depcheck/heavy.go index de5e81178..d984ed998 100644 --- a/depcheck/heavy.go +++ b/depcheck/heavy.go @@ -17,6 +17,8 @@ limitations under the License. package depcheck var ( + // KnownHeavyDependencies is a list of dependencies that are known to increase the + // binary's size by a lot. KnownHeavyDependencies = []string{ "k8s.io/apimachinery/pkg/api/apitesting/fuzzer", diff --git a/metrics/metricstest/metricstest.go b/metrics/metricstest/metricstest.go index 6a9d9d76a..3d054a183 100644 --- a/metrics/metricstest/metricstest.go +++ b/metrics/metricstest/metricstest.go @@ -103,7 +103,7 @@ func CheckDistributionData(t ti, name string, wantTags map[string]string, expect } } -// CheckDistributionRange checks the view with a name matching string name to verify that the DistributionData stats reported +// CheckDistributionCount checks the view with a name matching string name to verify that the DistributionData stats reported // are tagged with the tags in wantTags and that expectedCount number of records were reported. func CheckDistributionCount(t ti, name string, wantTags map[string]string, expectedCount int64) { t.Helper() diff --git a/reconciler/events.go b/reconciler/events.go index 4c85c884b..df4c366cc 100644 --- a/reconciler/events.go +++ b/reconciler/events.go @@ -62,7 +62,7 @@ func NewEvent(eventtype, reason, messageFmt string, args ...interface{}) Event { // ReconcilerEvent wraps the fields required for recorders to create a // kubernetes recorder Event. -type ReconcilerEvent struct { //nolint:golint // for backcompat. +type ReconcilerEvent struct { //nolint:revive // for backcompat. EventType string Reason string Format string diff --git a/reconciler/reconcile_common.go b/reconciler/reconcile_common.go index f7408fb47..114d53b03 100644 --- a/reconciler/reconcile_common.go +++ b/reconciler/reconcile_common.go @@ -31,9 +31,13 @@ import ( const failedGenerationBump = "NewObservedGenFailure" const ( - DoReconcileKind = "ReconcileKind" - DoFinalizeKind = "FinalizeKind" - DoObserveKind = "ObserveKind" + // DoReconcileKind is the function name for reconciling the resource (as a leader). + DoReconcileKind = "ReconcileKind" + // DoFinalizeKind is the function name for finalizing the resource (as a leader). + DoFinalizeKind = "FinalizeKind" + // DoObserveKind is the function name for observing the resource (as a non leader). + DoObserveKind = "ObserveKind" + // DoObserveFinalizeKind is the function name for observing finalization of the resource (as a non leader). DoObserveFinalizeKind = "ObserveFinalizeKind" ) diff --git a/system/env.go b/system/env.go index d9ec3ddac..ea1db0f0b 100644 --- a/system/env.go +++ b/system/env.go @@ -22,7 +22,10 @@ import ( ) const ( - NamespaceEnvKey = "SYSTEM_NAMESPACE" + // NamespaceEnvKey is the environment variable that specifies the system namespace. + NamespaceEnvKey = "SYSTEM_NAMESPACE" + // ResourceLabelEnvKey is the environment variable that specifies the system resource + // label. ResourceLabelEnvKey = "SYSTEM_RESOURCE_LABEL" ) diff --git a/test/e2e_flags.go b/test/e2e_flags.go index 55a59582b..d7233255a 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -65,6 +65,7 @@ func initializeFlags() *EnvironmentFlags { return f } +// SetupLoggingFlags initializes a logger for tests. // TODO(coryrc): Remove once other repos are moved to call logging.InitializeLogger() directly func SetupLoggingFlags() { logging.InitializeLogger() diff --git a/test/gcs/mock/mock.go b/test/gcs/mock/mock.go index ce6c1b80f..3113f026d 100644 --- a/test/gcs/mock/mock.go +++ b/test/gcs/mock/mock.go @@ -37,17 +37,28 @@ import ( // easy to replicate. var ( - MethodNewStorageBucket = Method("NewStorageBucket") + // MethodNewStorageBucket mocks MethodNewStorageBucket. + MethodNewStorageBucket = Method("NewStorageBucket") + // MethodDeleteStorageBucket mocks NewDeleteStorageBucket. MethodDeleteStorageBucket = Method("NewDeleteStorageBucket") - MethodListChildrenFiles = Method("ListChildrenFiles") - MethodListDirectChildren = Method("ListDirectChildren") - MethodAttrObject = Method("AttrObject") - MethodCopyObject = Method("CopyObject") - MethodReadObject = Method("ReadObject") - MethodWriteObject = Method("WriteObject") - MethodDeleteObject = Method("DeleteObject") - MethodDownload = Method("Download") - MethodUpload = Method("Upload") + // MethodListChildrenFiles mocks ListChildrenFiles. + MethodListChildrenFiles = Method("ListChildrenFiles") + // MethodListDirectChildren mocks ListDirectChildren. + MethodListDirectChildren = Method("ListDirectChildren") + // MethodAttrObject mocks AttrObject. + MethodAttrObject = Method("AttrObject") + // MethodCopyObject mocks CopyObject. + MethodCopyObject = Method("CopyObject") + // MethodReadObject mocks ReadObject. + MethodReadObject = Method("ReadObject") + // MethodWriteObject mocks WriteObject. + MethodWriteObject = Method("WriteObject") + // MethodDeleteObject mocks DeleteObject. + MethodDeleteObject = Method("DeleteObject") + // MethodDownload mocks Download. + MethodDownload = Method("Download") + // MethodUpload mocks Upload. + MethodUpload = Method("Upload") ) // mock GCS Client diff --git a/test/gcs/mock/mock_storage.go b/test/gcs/mock/mock_storage.go index a0d9ad508..7036945cd 100644 --- a/test/gcs/mock/mock_storage.go +++ b/test/gcs/mock/mock_storage.go @@ -64,7 +64,7 @@ type buckets struct { bkt map[bucket]*objects } -// Error map to return custom errors for specific methods +// ReturnError is a custom error for specific methods type ReturnError struct { NumCall uint8 Err error diff --git a/test/ha/ha.go b/test/ha/ha.go index 4007085ef..6f2ec9624 100644 --- a/test/ha/ha.go +++ b/test/ha/ha.go @@ -98,7 +98,8 @@ func WaitForNewLeaders(ctx context.Context, t *testing.T, client *test.KubeClien return leaders, err } -// DEPRECATED WaitForNewLeader waits until the holder of the given lease is different from the previousLeader. +// WaitForNewLeader waits until the holder of the given lease is different from the previousLeader. +// DEPRECATED: Use WaitForNewLeaders. func WaitForNewLeader(ctx context.Context, client *test.KubeClient, lease, namespace, previousLeader string) (string, error) { span := logging.GetEmitableSpan(ctx, "WaitForNewLeader/"+lease) defer span.End() diff --git a/test/interactive/docker.go b/test/interactive/docker.go index 6c24cbc41..3b295921f 100644 --- a/test/interactive/docker.go +++ b/test/interactive/docker.go @@ -55,7 +55,7 @@ func (e Env) PromoteFromEnv(envVars ...string) error { return err } -// Creates an Docker with default Docker command arguments for running interactively +// NewDocker creates a Docker instance with default Docker command arguments for running interactively. func NewDocker() Docker { return Docker{NewCommand(defaultDockerCommands...)} } diff --git a/test/kube_checks.go b/test/kube_checks.go index 3dc8a3dc0..156a85968 100644 --- a/test/kube_checks.go +++ b/test/kube_checks.go @@ -130,7 +130,7 @@ func WaitForPodDeleted(ctx context.Context, client kubernetes.Interface, name, n return nil } -// WaitForServiceHasAtLeastOneEndpoint polls the status of the specified Service +// WaitForServiceEndpoints polls the status of the specified Service // from client every interval until number of service endpoints = numOfEndpoints func WaitForServiceEndpoints(ctx context.Context, client kubernetes.Interface, svcName string, svcNamespace string, numOfEndpoints int) error { endpointsService := client.CoreV1().Endpoints(svcNamespace) diff --git a/test/tinterface.go b/test/tinterface.go index 4cda2c90a..530ff0a2e 100644 --- a/test/tinterface.go +++ b/test/tinterface.go @@ -20,6 +20,7 @@ limitations under the License. package test +// T is an interface mimicking *testing.T. // Deprecated: Do not use this. Define your own interface. type T interface { Name() string @@ -30,6 +31,7 @@ type T interface { Error(args ...interface{}) } +// TLegacy is an interface mimicking *testing.T. // Deprecated: Do not use this. Define your own interface. type TLegacy interface { T diff --git a/testing/duck/register.go b/testing/duck/register.go index f21a721e5..e8e9d24e5 100644 --- a/testing/duck/register.go +++ b/testing/duck/register.go @@ -26,8 +26,10 @@ import ( var SchemeGroupVersion = schema.GroupVersion{Group: "duck.knative.dev", Version: "v3"} var ( + // SchemeBuilder builds a scheme with the types known to the package. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme adds the types known to this package to an existing schema. + AddToScheme = SchemeBuilder.AddToScheme ) // Adds the list of known types to Scheme. diff --git a/testing/inner_default_resource.go b/testing/inner_default_resource.go index 78196f579..4f9299c86 100644 --- a/testing/inner_default_resource.go +++ b/testing/inner_default_resource.go @@ -85,7 +85,7 @@ type InnerDefaultSubSpec struct { DeprecatedNotJSON string } -// Adding complication helper. +// InnerDefaultStruct is a helper to test defaulting of an inner struct. type InnerDefaultStruct struct { FieldAsString string `json:"fieldAsString,omitempty"` diff --git a/testing/register.go b/testing/register.go index 911c90fbd..aa70e6ccb 100644 --- a/testing/register.go +++ b/testing/register.go @@ -26,8 +26,10 @@ import ( var SchemeGroupVersion = schema.GroupVersion{Group: "pkg.knative.dev", Version: "v2"} var ( + // SchemeBuilder builds a scheme with the types known to the package. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme adds the types known to this package to an existing schema. + AddToScheme = SchemeBuilder.AddToScheme ) // Adds the list of known types to Scheme. diff --git a/tracing/testing/zipkin.go b/tracing/testing/zipkin.go index ebb70df13..921c8527f 100644 --- a/tracing/testing/zipkin.go +++ b/tracing/testing/zipkin.go @@ -24,7 +24,7 @@ import ( "knative.dev/pkg/tracing/config" ) -// FakeZipkineExporter is intended to capture the testing boilerplate of building +// FakeZipkinExporter is intended to capture the testing boilerplate of building // up the ConfigOption to pass NewOpenCensusTracer and expose a mechanism for examining // the traces it would have reported. To set it up, use something like: // reporter, co := FakeZipkinExporter() diff --git a/tracing/zipkin.go b/tracing/zipkin.go index 4faa7a12c..1c5be0845 100644 --- a/tracing/zipkin.go +++ b/tracing/zipkin.go @@ -28,6 +28,7 @@ import ( // ZipkinReporterFactory is a factory function which creates a reporter given a config type ZipkinReporterFactory func(*config.Config) (zipkinreporter.Reporter, error) +// WithZipkinExporter returns a config with zipkin enabled. // DEPRECATED: This function is the legacy entrypoint and should be replaced with one of: // - WithExporter() in production code // - testing/FakeZipkinExporter() in test code. diff --git a/webhook/admission.go b/webhook/admission.go index 4c799f246..4d00c746b 100644 --- a/webhook/admission.go +++ b/webhook/admission.go @@ -143,6 +143,7 @@ func admissionHandler(rootLogger *zap.SugaredLogger, stats StatsReporter, c Admi } } +// StatelessAdmissionImpl marks a reconciler as stateless. // Inline this type to implement StatelessAdmissionController. type StatelessAdmissionImpl struct{} diff --git a/webhook/psbinding/psbinding.go b/webhook/psbinding/psbinding.go index f1f7984f9..ef16a9d83 100644 --- a/webhook/psbinding/psbinding.go +++ b/webhook/psbinding/psbinding.go @@ -47,7 +47,7 @@ import ( certresources "knative.dev/pkg/webhook/certificates/resources" ) -// ReconcilerOptions is a function to modify the Reconciler. +// ReconcilerOption is a function to modify the Reconciler. type ReconcilerOption func(*Reconciler) // WithSelector specifies the selector for the webhook.