Skip to content

Commit 0e3754a

Browse files
committed
Merge remote-tracking branch 'upstream/master' into kube-aware-logr-logger
2 parents 705bd0c + f40b846 commit 0e3754a

File tree

197 files changed

+3176
-1410
lines changed

Some content is hidden

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

197 files changed

+3176
-1410
lines changed

.github/dependabot.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
9+
# Maintain dependencies for GitHub Actions
10+
- package-ecosystem: "github-actions"
11+
# Workflow files stored in the
12+
# default location of `.github/workflows`
13+
directory: "/"
14+
schedule:
15+
interval: "weekly"
16+
commit-message:
17+
prefix: ":seedling:"
18+
labels:
19+
- "ok-to-test"
20+
21+
# Maintain dependencies for go
22+
- package-ecosystem: "gomod"
23+
directory: "/"
24+
schedule:
25+
interval: "weekly"
26+
commit-message:
27+
prefix: ":seedling:"
28+
# Ignore K8 packages as these are done manually
29+
ignore:
30+
- dependency-name: "k8s.io/api"
31+
- dependency-name: "k8s.io/apiextensions-apiserver"
32+
- dependency-name: "k8s.io/apimachinery"
33+
- dependency-name: "k8s.io/client-go"
34+
- dependency-name: "k8s.io/component-base"
35+
labels:
36+
- "ok-to-test"

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
- ""
1616
- tools/setup-envtest
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1919
- name: golangci-lint
20-
uses: golangci/golangci-lint-action@v2
20+
uses: golangci/golangci-lint-action@v3
2121
with:
22-
version: v1.45.2
22+
version: v1.49.0
2323
working-directory: ${{matrix.working-directory}}

.github/workflows/verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
steps:
1010
- name: Verifier action
1111
id: verifier
12-
uses: kubernetes-sigs/kubebuilder-release-tools@v0.1
12+
uses: kubernetes-sigs/kubebuilder-release-tools@v0.2.0
1313
with:
1414
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222

2323
# Tools binaries.
2424
hack/tools/bin
25+
26+
junit-report.xml
27+
/artifacts

.golangci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ linters:
1212
- goconst
1313
- gocritic
1414
- gocyclo
15-
- godot
1615
- gofmt
1716
- goimports
1817
- goprintffuncname
@@ -61,9 +60,9 @@ linters-settings:
6160
- pkg: sigs.k8s.io/controller-runtime
6261
alias: ctrl
6362
staticcheck:
64-
go: "1.18"
63+
go: "1.19"
6564
stylecheck:
66-
go: "1.18"
65+
go: "1.19"
6766
depguard:
6867
include-go-root: true
6968
packages:
@@ -132,6 +131,9 @@ issues:
132131
- linters:
133132
- gosec
134133
text: "G304: Potential file inclusion via variable"
134+
- linters:
135+
- revive
136+
text: "package-comments: should have a package comment"
135137

136138
run:
137139
timeout: 10m

OWNERS_ALIASES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ aliases:
2828
- alexeldeib
2929
- varshaprasad96
3030
- fillzpp
31+
- sbueringer
3132

3233
# folks to can approve things in the directly-ported
3334
# testing_frameworks portions of the codebase

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ in sig apimachinery.
5353

5454
You can reach the maintainers of this project at:
5555

56-
- Slack channel: [#kubebuilder](http://slack.k8s.io/#kubebuilder)
56+
- Slack channel: [#controller-runtime](https://kubernetes.slack.com/archives/C02MRBMN00Z)
5757
- Google Group: [[email protected]](https://groups.google.com/forum/#!forum/kubebuilder)
5858

5959
## Contributing

TMP-LOGGING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ log.Printf("starting reconciliation for pod %s/%s", podNamespace, podName)
2121
In controller-runtime, we'd instead write:
2222

2323
```go
24-
logger.Info("starting reconciliation", "pod", req.NamespacedNamed)
24+
logger.Info("starting reconciliation", "pod", req.NamespacedName)
2525
```
2626

2727
or even write
@@ -51,7 +51,7 @@ You can configure the logging implementation using
5151
`"sigs.k8s.io/controller-runtime/pkg/log".SetLogger`. That
5252
package also contains the convenience functions for setting up Zap.
5353

54-
You can get a handle to the the "root" logger using
54+
You can get a handle to the "root" logger using
5555
`"sigs.k8s.io/controller-runtime/pkg/log".Log`, and can then call
5656
`WithName` to create individual named loggers. You can call `WithName`
5757
repeatedly to chain names together:

alias.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ type TypeMeta = metav1.TypeMeta
7070
type ObjectMeta = metav1.ObjectMeta
7171

7272
var (
73+
// RegisterFlags registers flag variables to the given FlagSet if not already registered.
74+
// It uses the default command line FlagSet, if none is provided. Currently, it only registers the kubeconfig flag.
75+
RegisterFlags = config.RegisterFlags
76+
7377
// GetConfigOrDie creates a *rest.Config for talking to a Kubernetes apiserver.
7478
// If --kubeconfig is set, will use the kubeconfig file at that location. Otherwise will assume running
7579
// in cluster and use the cluster provided kubeconfig.

doc.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ limitations under the License.
2323
// and uncommon cases should be possible. In general, controller-runtime tries
2424
// to guide users towards Kubernetes controller best-practices.
2525
//
26-
// Getting Started
26+
// # Getting Started
2727
//
2828
// The main entrypoint for controller-runtime is this root package, which
2929
// contains all of the common types needed to get started building controllers:
30-
// import (
31-
// ctrl "sigs.k8s.io/controller-runtime"
32-
// )
30+
//
31+
// import (
32+
// ctrl "sigs.k8s.io/controller-runtime"
33+
// )
3334
//
3435
// The examples in this package walk through a basic controller setup. The
3536
// kubebuilder book (https://book.kubebuilder.io) has some more in-depth
@@ -38,7 +39,7 @@ limitations under the License.
3839
// controller-runtime favors structs with sane defaults over constructors, so
3940
// it's fairly common to see structs being used directly in controller-runtime.
4041
//
41-
// Organization
42+
// # Organization
4243
//
4344
// A brief-ish walkthrough of the layout of this library can be found below. Each
4445
// package contains more information about how to use it.
@@ -47,7 +48,7 @@ limitations under the License.
4748
// controllers can be found at
4849
// https://github.com/kubernetes-sigs/controller-runtime/blob/master/FAQ.md.
4950
//
50-
// Managers
51+
// # Managers
5152
//
5253
// Every controller and webhook is ultimately run by a Manager (pkg/manager). A
5354
// manager is responsible for running controllers and webhooks, and setting up
@@ -56,7 +57,7 @@ limitations under the License.
5657
// generally configured to gracefully shut down controllers on pod termination
5758
// by wiring up a signal handler (pkg/manager/signals).
5859
//
59-
// Controllers
60+
// # Controllers
6061
//
6162
// Controllers (pkg/controller) use events (pkg/event) to eventually trigger
6263
// reconcile requests. They may be constructed manually, but are often
@@ -67,15 +68,15 @@ limitations under the License.
6768
// trigger reconciles. There are pre-written utilities for the common cases, and
6869
// interfaces and helpers for advanced cases.
6970
//
70-
// Reconcilers
71+
// # Reconcilers
7172
//
7273
// Controller logic is implemented in terms of Reconcilers (pkg/reconcile). A
7374
// Reconciler implements a function which takes a reconcile Request containing
7475
// the name and namespace of the object to reconcile, reconciles the object,
7576
// and returns a Response or an error indicating whether to requeue for a
7677
// second round of processing.
7778
//
78-
// Clients and Caches
79+
// # Clients and Caches
7980
//
8081
// Reconcilers use Clients (pkg/client) to access API objects. The default
8182
// client provided by the manager reads from a local shared cache (pkg/cache)
@@ -91,19 +92,19 @@ limitations under the License.
9192
// may retrieve event recorders (pkg/recorder) to emit events using the
9293
// manager.
9394
//
94-
// Schemes
95+
// # Schemes
9596
//
9697
// Clients, Caches, and many other things in Kubernetes use Schemes
9798
// (pkg/scheme) to associate Go types to Kubernetes API Kinds
9899
// (Group-Version-Kinds, to be specific).
99100
//
100-
// Webhooks
101+
// # Webhooks
101102
//
102103
// Similarly, webhooks (pkg/webhook/admission) may be implemented directly, but
103104
// are often constructed using a builder (pkg/webhook/admission/builder). They
104105
// are run via a server (pkg/webhook) which is managed by a Manager.
105106
//
106-
// Logging and Metrics
107+
// # Logging and Metrics
107108
//
108109
// Logging (pkg/log) in controller-runtime is done via structured logs, using a
109110
// log set of interfaces called logr
@@ -117,7 +118,7 @@ limitations under the License.
117118
// serve these by an HTTP endpoint, and additional metrics may be registered to
118119
// this Registry as normal.
119120
//
120-
// Testing
121+
// # Testing
121122
//
122123
// You can easily build integration and unit tests for your controllers and
123124
// webhooks using the test Environment (pkg/envtest). This will automatically

example_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import (
2626
corev1 "k8s.io/api/core/v1"
2727
ctrl "sigs.k8s.io/controller-runtime"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
29+
30+
// since we invoke tests with -ginkgo.junit-report we need to import ginkgo.
31+
_ "github.com/onsi/ginkgo/v2"
2932
)
3033

3134
// This example creates a simple application Controller that is configured for ReplicaSets and Pods.
@@ -64,9 +67,9 @@ func Example() {
6467
// This application controller will be running leader election with the provided configuration in the manager options.
6568
// If leader election configuration is not provided, controller runs leader election with default values.
6669
// Default values taken from: https://github.com/kubernetes/component-base/blob/master/config/v1alpha1/defaults.go
67-
// defaultLeaseDuration = 15 * time.Second
68-
// defaultRenewDeadline = 10 * time.Second
69-
// defaultRetryPeriod = 2 * time.Second
70+
// * defaultLeaseDuration = 15 * time.Second
71+
// * defaultRenewDeadline = 10 * time.Second
72+
// * defaultRetryPeriod = 2 * time.Second
7073
//
7174
// * Create a new application for ReplicaSets that manages Pods owned by the ReplicaSet and calls into
7275
// ReplicaSetReconciler.

examples/scratch-env/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import (
2121
"os"
2222

2323
flag "github.com/spf13/pflag"
24+
"go.uber.org/zap"
2425

2526
ctrl "sigs.k8s.io/controller-runtime"
2627
"sigs.k8s.io/controller-runtime/pkg/envtest"
27-
"sigs.k8s.io/controller-runtime/pkg/log/zap"
28+
logzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
2829
)
2930

3031
var (
@@ -35,16 +36,18 @@ var (
3536

3637
// have a separate function so we can return an exit code w/o skipping defers
3738
func runMain() int {
38-
loggerOpts := &zap.Options{
39+
loggerOpts := &logzap.Options{
3940
Development: true, // a sane default
41+
ZapOpts: []zap.Option{zap.AddCaller()},
4042
}
4143
{
4244
var goFlagSet goflag.FlagSet
4345
loggerOpts.BindFlags(&goFlagSet)
4446
flag.CommandLine.AddGoFlagSet(&goFlagSet)
4547
}
4648
flag.Parse()
47-
ctrl.SetLogger(zap.New(zap.UseFlagOptions(loggerOpts)))
49+
ctrl.SetLogger(logzap.New(logzap.UseFlagOptions(loggerOpts)))
50+
ctrl.Log.Info("Starting...")
4851

4952
log := ctrl.Log.WithName("main")
5053

go.mod

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,41 @@
11
module sigs.k8s.io/controller-runtime
22

3-
go 1.17
3+
go 1.19
44

55
require (
66
github.com/evanphx/json-patch/v5 v5.6.0
7-
github.com/fsnotify/fsnotify v1.5.4
7+
github.com/fsnotify/fsnotify v1.6.0
88
github.com/go-logr/logr v1.2.3
99
github.com/go-logr/zapr v1.2.3
10-
github.com/google/go-cmp v0.5.8
11-
github.com/onsi/ginkgo v1.16.5
12-
github.com/onsi/gomega v1.19.0
13-
github.com/prometheus/client_golang v1.12.2
14-
github.com/prometheus/client_model v0.2.0
10+
github.com/google/go-cmp v0.5.9
11+
github.com/onsi/ginkgo/v2 v2.5.1
12+
github.com/onsi/gomega v1.24.1
13+
github.com/prometheus/client_golang v1.14.0
14+
github.com/prometheus/client_model v0.3.0
1515
go.uber.org/atomic v1.7.0
16-
go.uber.org/goleak v1.1.12
17-
go.uber.org/zap v1.21.0
18-
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c
16+
go.uber.org/goleak v1.2.0
17+
go.uber.org/zap v1.24.0
18+
golang.org/x/sys v0.3.0
1919
golang.org/x/time v0.0.0-20220609170525-579cf78fd858
2020
gomodules.xyz/jsonpatch/v2 v2.2.0
21-
k8s.io/api v0.24.2
22-
k8s.io/apiextensions-apiserver v0.24.2
23-
k8s.io/apimachinery v0.24.2
24-
k8s.io/client-go v0.24.2
25-
k8s.io/component-base v0.24.2
26-
k8s.io/klog/v2 v2.60.1
27-
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
21+
k8s.io/api v0.26.0-alpha.3
22+
k8s.io/apiextensions-apiserver v0.26.0-alpha.3
23+
k8s.io/apimachinery v0.26.0-alpha.3
24+
k8s.io/client-go v0.26.0-alpha.3
25+
k8s.io/component-base v0.26.0-alpha.3
26+
k8s.io/klog/v2 v2.80.1
27+
k8s.io/utils v0.0.0-20220922133306-665eaaec4324
2828
sigs.k8s.io/yaml v1.3.0
2929
)
3030

3131
require (
32-
cloud.google.com/go v0.81.0 // indirect
33-
github.com/PuerkitoBio/purell v1.1.1 // indirect
34-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
3532
github.com/beorn7/perks v1.0.1 // indirect
3633
github.com/cespare/xxhash/v2 v2.1.2 // indirect
3734
github.com/davecgh/go-spew v1.1.1 // indirect
38-
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
35+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
3936
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
4037
github.com/go-openapi/jsonpointer v0.19.5 // indirect
41-
github.com/go-openapi/jsonreference v0.19.5 // indirect
38+
github.com/go-openapi/jsonreference v0.20.0 // indirect
4239
github.com/go-openapi/swag v0.19.14 // indirect
4340
github.com/gogo/protobuf v1.3.2 // indirect
4441
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
@@ -50,27 +47,26 @@ require (
5047
github.com/josharian/intern v1.0.0 // indirect
5148
github.com/json-iterator/go v1.1.12 // indirect
5249
github.com/mailru/easyjson v0.7.6 // indirect
53-
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
50+
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
5451
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5552
github.com/modern-go/reflect2 v1.0.2 // indirect
5653
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
57-
github.com/nxadm/tail v1.4.8 // indirect
5854
github.com/pkg/errors v0.9.1 // indirect
59-
github.com/prometheus/common v0.32.1 // indirect
60-
github.com/prometheus/procfs v0.7.3 // indirect
55+
github.com/prometheus/common v0.37.0 // indirect
56+
github.com/prometheus/procfs v0.8.0 // indirect
6157
github.com/spf13/pflag v1.0.5 // indirect
6258
go.uber.org/multierr v1.6.0 // indirect
63-
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
64-
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
65-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
66-
golang.org/x/text v0.3.7 // indirect
59+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
60+
golang.org/x/net v0.2.0 // indirect
61+
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
62+
golang.org/x/term v0.2.0 // indirect
63+
golang.org/x/text v0.4.0 // indirect
6764
google.golang.org/appengine v1.6.7 // indirect
68-
google.golang.org/protobuf v1.27.1 // indirect
65+
google.golang.org/protobuf v1.28.1 // indirect
6966
gopkg.in/inf.v0 v0.9.1 // indirect
70-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
7167
gopkg.in/yaml.v2 v2.4.0 // indirect
72-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
73-
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
74-
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
75-
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
68+
gopkg.in/yaml.v3 v3.0.1 // indirect
69+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
70+
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
71+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
7672
)

0 commit comments

Comments
 (0)