Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Bump golangci lint to v1.49.0 #1988

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Expand Up @@ -19,5 +19,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.47.3
version: v1.49.0
working-directory: ${{matrix.working-directory}}
8 changes: 5 additions & 3 deletions .golangci.yml
Expand Up @@ -12,7 +12,6 @@ linters:
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- goimports
- goprintffuncname
Expand Down Expand Up @@ -61,9 +60,9 @@ linters-settings:
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
staticcheck:
go: "1.18"
go: "1.19"
stylecheck:
go: "1.18"
go: "1.19"
depguard:
include-go-root: true
packages:
Expand Down Expand Up @@ -132,6 +131,9 @@ issues:
- linters:
- gosec
text: "G304: Potential file inclusion via variable"
- linters:
- revive
text: "package-comments: should have a package comment"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to add package comments everywhere I would suggest to do that in follow-up PRs (I can open an issue for it).

There are a lot of packages with missing package comments


run:
timeout: 10m
Expand Down
27 changes: 14 additions & 13 deletions doc.go
Expand Up @@ -23,13 +23,14 @@ limitations under the License.
// and uncommon cases should be possible. In general, controller-runtime tries
// to guide users towards Kubernetes controller best-practices.
//
// Getting Started
// # Getting Started
//
// The main entrypoint for controller-runtime is this root package, which
// contains all of the common types needed to get started building controllers:
// import (
// ctrl "sigs.k8s.io/controller-runtime"
// )
//
// import (
// ctrl "sigs.k8s.io/controller-runtime"
// )
//
// The examples in this package walk through a basic controller setup. The
// kubebuilder book (https://book.kubebuilder.io) has some more in-depth
Expand All @@ -38,7 +39,7 @@ limitations under the License.
// controller-runtime favors structs with sane defaults over constructors, so
// it's fairly common to see structs being used directly in controller-runtime.
//
// Organization
// # Organization
//
// A brief-ish walkthrough of the layout of this library can be found below. Each
// package contains more information about how to use it.
Expand All @@ -47,7 +48,7 @@ limitations under the License.
// controllers can be found at
// https://github.com/kubernetes-sigs/controller-runtime/blob/master/FAQ.md.
//
// Managers
// # Managers
//
// Every controller and webhook is ultimately run by a Manager (pkg/manager). A
// manager is responsible for running controllers and webhooks, and setting up
Expand All @@ -56,7 +57,7 @@ limitations under the License.
// generally configured to gracefully shut down controllers on pod termination
// by wiring up a signal handler (pkg/manager/signals).
//
// Controllers
// # Controllers
//
// Controllers (pkg/controller) use events (pkg/event) to eventually trigger
// reconcile requests. They may be constructed manually, but are often
Expand All @@ -67,15 +68,15 @@ limitations under the License.
// trigger reconciles. There are pre-written utilities for the common cases, and
// interfaces and helpers for advanced cases.
//
// Reconcilers
// # Reconcilers
//
// Controller logic is implemented in terms of Reconcilers (pkg/reconcile). A
// Reconciler implements a function which takes a reconcile Request containing
// the name and namespace of the object to reconcile, reconciles the object,
// and returns a Response or an error indicating whether to requeue for a
// second round of processing.
//
// Clients and Caches
// # Clients and Caches
//
// Reconcilers use Clients (pkg/client) to access API objects. The default
// client provided by the manager reads from a local shared cache (pkg/cache)
Expand All @@ -91,19 +92,19 @@ limitations under the License.
// may retrieve event recorders (pkg/recorder) to emit events using the
// manager.
//
// Schemes
// # Schemes
//
// Clients, Caches, and many other things in Kubernetes use Schemes
// (pkg/scheme) to associate Go types to Kubernetes API Kinds
// (Group-Version-Kinds, to be specific).
//
// Webhooks
// # Webhooks
//
// Similarly, webhooks (pkg/webhook/admission) may be implemented directly, but
// are often constructed using a builder (pkg/webhook/admission/builder). They
// are run via a server (pkg/webhook) which is managed by a Manager.
//
// Logging and Metrics
// # Logging and Metrics
//
// Logging (pkg/log) in controller-runtime is done via structured logs, using a
// log set of interfaces called logr
Expand All @@ -117,7 +118,7 @@ limitations under the License.
// serve these by an HTTP endpoint, and additional metrics may be registered to
// this Registry as normal.
//
// Testing
// # Testing
//
// You can easily build integration and unit tests for your controllers and
// webhooks using the test Environment (pkg/envtest). This will automatically
Expand Down
6 changes: 3 additions & 3 deletions example_test.go
Expand Up @@ -64,9 +64,9 @@ func Example() {
// This application controller will be running leader election with the provided configuration in the manager options.
// If leader election configuration is not provided, controller runs leader election with default values.
// Default values taken from: https://github.com/kubernetes/component-base/blob/master/config/v1alpha1/defaults.go
// defaultLeaseDuration = 15 * time.Second
// defaultRenewDeadline = 10 * time.Second
// defaultRetryPeriod = 2 * time.Second
// * defaultLeaseDuration = 15 * time.Second
// * defaultRenewDeadline = 10 * time.Second
// * defaultRetryPeriod = 2 * time.Second
//
// * Create a new application for ReplicaSets that manages Pods owned by the ReplicaSet and calls into
// ReplicaSetReconciler.
Expand Down
8 changes: 4 additions & 4 deletions pkg/cache/cache.go
Expand Up @@ -170,10 +170,10 @@ func New(config *rest.Config, opts Options) (Cache, error) {
// BuilderWithOptions returns a Cache constructor that will build the a cache
// honoring the options argument, this is useful to specify options like
// SelectorsByObject
// WARNING: if SelectorsByObject is specified. filtered out resources are not
// returned.
// WARNING: if UnsafeDisableDeepCopy is enabled, you must DeepCopy any object
// returned from cache get/list before mutating it.
// WARNING: If SelectorsByObject is specified, filtered out resources are not
// returned.
// WARNING: If UnsafeDisableDeepCopy is enabled, you must DeepCopy any object
// returned from cache get/list before mutating it.
func BuilderWithOptions(options Options) NewCacheFunc {
return func(config *rest.Config, opts Options) (Cache, error) {
if options.Scheme == nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/config/config.go
Expand Up @@ -47,7 +47,7 @@ func init() {
// It also applies saner defaults for QPS and burst based on the Kubernetes
// controller manager defaults (20 QPS, 30 burst)
//
// Config precedence
// Config precedence:
//
// * --kubeconfig flag pointing at a file
//
Expand All @@ -67,7 +67,7 @@ func GetConfig() (*rest.Config, error) {
// It also applies saner defaults for QPS and burst based on the Kubernetes
// controller manager defaults (20 QPS, 30 burst)
//
// Config precedence
// Config precedence:
//
// * --kubeconfig flag pointing at a file
//
Expand Down
9 changes: 5 additions & 4 deletions pkg/client/doc.go
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
// Package client contains functionality for interacting with Kubernetes API
// servers.
//
// Clients
// # Clients
//
// Clients are split into two interfaces -- Readers and Writers. Readers
// get and list, while writers create, update, and delete.
Expand All @@ -29,14 +29,15 @@ limitations under the License.
// server. This pattern is covered by the DelegatingClient type, which can
// be used to have a client whose Reader is different from the Writer.
//
// Options
// # Options
//
// Many client operations in Kubernetes support options. These options are
// represented as variadic arguments at the end of a given method call.
// For instance, to use a label selector on list, you can call
// err := someReader.List(context.Background(), &podList, client.MatchingLabels{"somelabel": "someval"})
//
// Indexing
// err := someReader.List(context.Background(), &podList, client.MatchingLabels{"somelabel": "someval"})
//
// # Indexing
//
// Indexes may be added to caches using a FieldIndexer. This allows you to easily
// and efficiently look up objects with certain properties. You can then make
Expand Down
13 changes: 6 additions & 7 deletions pkg/client/fake/doc.go
Expand Up @@ -28,12 +28,11 @@ When in doubt, it's almost always better not to use this package and instead use
envtest.Environment with a real client and API server.

WARNING: ⚠️ Current Limitations / Known Issues with the fake Client ⚠️
- This client does not have a way to inject specific errors to test handled vs. unhandled errors.
- There is some support for sub resources which can cause issues with tests if you're trying to update
e.g. metadata and status in the same reconcile.
- No OpenAPI validation is performed when creating or updating objects.
- ObjectMeta's `Generation` and `ResourceVersion` don't behave properly, Patch or Update
operations that rely on these fields will fail, or give false positives.

- This client does not have a way to inject specific errors to test handled vs. unhandled errors.
- There is some support for sub resources which can cause issues with tests if you're trying to update
e.g. metadata and status in the same reconcile.
- No OpenAPI validation is performed when creating or updating objects.
- ObjectMeta's `Generation` and `ResourceVersion` don't behave properly, Patch or Update
operations that rely on these fields will fail, or give false positives.
*/
package fake
4 changes: 2 additions & 2 deletions pkg/config/config.go
Expand Up @@ -50,8 +50,8 @@ type DeferredFileLoader struct {
// this will also configure the defaults for the loader if nothing is
//
// Defaults:
// Path: "./config.yaml"
// Kind: GenericControllerManagerConfiguration
// * Path: "./config.yaml"
// * Kind: GenericControllerManagerConfiguration
func File() *DeferredFileLoader {
scheme := runtime.NewScheme()
utilruntime.Must(v1alpha1.AddToScheme(scheme))
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/doc.go
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
// Package config contains functionality for interacting with ComponentConfig
// files
//
// DeferredFileLoader
// # DeferredFileLoader
//
// This uses a deferred file decoding allowing you to chain your configuration
// setup. You can pass this into manager.Options#File and it will load your
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/doc.go
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
/*
Package controller provides types and functions for building Controllers. Controllers implement Kubernetes APIs.

Creation
# Creation

To create a new Controller, first create a manager.Manager and pass it to the controller.New function.
The Controller MUST be started by calling Manager.Start.
Expand Down
28 changes: 14 additions & 14 deletions pkg/doc.go
Expand Up @@ -18,21 +18,21 @@ limitations under the License.
Package pkg provides libraries for building Controllers. Controllers implement Kubernetes APIs
and are foundational to building Operators, Workload APIs, Configuration APIs, Autoscalers, and more.

Client
# Client

Client provides a Read + Write client for reading and writing Kubernetes objects.

Cache
# Cache

Cache provides a Read client for reading objects from a local cache.
A cache may register handlers to respond to events that update the cache.

Manager
# Manager

Manager is required for creating a Controller and provides the Controller shared dependencies such as
clients, caches, schemes, etc. Controllers should be Started through the Manager by calling Manager.Start.

Controller
# Controller

Controller implements a Kubernetes API by responding to events (object Create, Update, Delete) and ensuring that
the state specified in the Spec of the object matches the state of the system. This is called a reconcile.
Expand All @@ -49,7 +49,7 @@ system must be read for each reconcile.

* Controllers require Watches to be configured to enqueue reconcile.Requests in response to events.

Webhook
# Webhook

Admission Webhooks are a mechanism for extending kubernetes APIs. Webhooks can be configured with target
event type (object Create, Update, Delete), the API server will send AdmissionRequests to them
Expand All @@ -62,7 +62,7 @@ Validating webhook is used to validate if an object meets certain requirements.

* Admission Webhooks require Handler(s) to be provided to process the received AdmissionReview requests.

Reconciler
# Reconciler

Reconciler is a function provided to a Controller that may be called at anytime with the Name and Namespace of an object.
When called, the Reconciler will ensure that the state of the system matches what is specified in the object at the
Expand All @@ -84,7 +84,7 @@ a mapping (e.g. owner references) that maps the object that triggers the reconci
- e.g. it doesn't matter whether a ReplicaSet was created or updated, Reconciler will always compare the number of
Pods in the system against what is specified in the object at the time it is called.

Source
# Source

resource.Source is an argument to Controller.Watch that provides a stream of events.
Events typically come from watching Kubernetes APIs (e.g. Pod Create, Update, Delete).
Expand All @@ -97,7 +97,7 @@ through the Watch API.

* Users SHOULD only use the provided Source implementations instead of implementing their own for nearly all cases.

EventHandler
# EventHandler

handler.EventHandler is an argument to Controller.Watch that enqueues reconcile.Requests in response to events.

Expand All @@ -117,7 +117,7 @@ type - e.g. map a Node event to objects that respond to cluster resize events.
* Users SHOULD only use the provided EventHandler implementations instead of implementing their own for almost
all cases.

Predicate
# Predicate

predicate.Predicate is an optional argument to Controller.Watch that filters events. This allows common filters to be
reused and composed.
Expand All @@ -129,7 +129,7 @@ reused and composed.
* Users SHOULD use the provided Predicate implementations, but MAY implement additional
Predicates e.g. generation changed, label selectors changed etc.

PodController Diagram
# PodController Diagram

Source provides event:

Expand All @@ -143,14 +143,14 @@ Reconciler is called with the Request:

* Reconciler(reconcile.Request{types.NamespaceName{Name: "foo", Namespace: "bar"}})

Usage
# Usage

The following example shows creating a new Controller program which Reconciles ReplicaSet objects in response
to Pod or ReplicaSet events. The Reconciler function simply adds a label to the ReplicaSet.

See the examples/builtins/main.go for a usage example.

Controller Example
Controller Example:

1. Watch ReplicaSet and Pods Sources

Expand All @@ -167,7 +167,7 @@ Owning ReplicaSet Namespace and Name.

2.3 Reconciler triggered by deletion of Pods from some other actor -> Read ReplicaSet and Pods, create replacement Pods.

Watching and EventHandling
# Watching and EventHandling

Controllers may Watch multiple Kinds of objects (e.g. Pods, ReplicaSets and Deployments), but they reconcile
only a single Type. When one Type of object must be updated in response to changes in another Type of object,
Expand All @@ -185,7 +185,7 @@ Note: reconcile.Requests are deduplicated when they are enqueued. Many Pod Even
may trigger only 1 reconcile invocation as each Event results in the Handler trying to enqueue
the same reconcile.Request for the ReplicaSet.

Controller Writing Tips
# Controller Writing Tips

Reconciler Runtime Complexity:

Expand Down