Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kubernetes-sigs/controller-runtime
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.15.2
Choose a base ref
...
head repository: kubernetes-sigs/controller-runtime
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.16.0
Choose a head ref
Loading
Showing with 5,933 additions and 1,702 deletions.
  1. +1 −1 .github/workflows/golangci-lint.yml
  2. +35 −0 .github/workflows/pr-dependabot.yaml
  3. +1 −5 .golangci.yml
  4. +4 −1 Makefile
  5. +4 −4 VERSIONING.md
  6. +3 −0 alias.go
  7. +226 −0 designs/cache_options.md
  8. +0 −1 examples/configfile/custom/v1alpha1/zz_generated.deepcopy.go
  9. +1 −0 examples/scratch-env/go.mod
  10. +1,539 −286 examples/scratch-env/go.sum
  11. +65 −27 go.mod
  12. +446 −58 go.sum
  13. +14 −14 hack/tools/go.mod
  14. +33 −33 hack/tools/go.sum
  15. +3 −3 pkg/builder/builder_suite_test.go
  16. +28 −26 pkg/builder/controller.go
  17. +6 −6 pkg/builder/controller_test.go
  18. +5 −5 pkg/builder/options.go
  19. +19 −18 pkg/builder/webhook.go
  20. +252 −86 pkg/cache/cache.go
  21. +505 −107 pkg/cache/cache_test.go
  22. +290 −0 pkg/cache/defaulting_test.go
  23. +127 −0 pkg/cache/delegating_by_gvk_cache.go
  24. +56 −18 pkg/cache/informer_cache.go
  25. +1 −1 pkg/cache/informer_cache_unit_test.go
  26. +6 −20 pkg/cache/informertest/fake_cache.go
  27. +11 −7 pkg/cache/internal/cache_reader.go
  28. +52 −70 pkg/cache/internal/informers.go
  29. +0 −55 pkg/cache/internal/transformers.go
  30. +79 −81 pkg/cache/multi_namespace_cache.go
  31. +5 −5 pkg/certwatcher/certwatcher_test.go
  32. +6 −0 pkg/client/apiutil/restmapper.go
  33. +31 −3 pkg/client/apiutil/restmapper_test.go
  34. +13 −3 pkg/client/client.go
  35. +28 −1 pkg/client/client_test.go
  36. +5 −17 pkg/client/fake/client.go
  37. +123 −123 pkg/client/fake/client_test.go
  38. +1 −1 pkg/client/fake/doc.go
  39. +2 −2 pkg/client/namespaced_client_test.go
  40. +15 −5 pkg/client/options.go
  41. +48 −3 pkg/client/options_test.go
  42. +4 −4 pkg/client/unstructured_client.go
  43. +12 −39 pkg/cluster/cluster.go
  44. +3 −3 pkg/config/config_test.go
  45. +0 −1 pkg/config/v1alpha1/zz_generated.deepcopy.go
  46. +3 −1 pkg/controller/controller.go
  47. +4 −4 pkg/controller/controller_suite_test.go
  48. +10 −12 pkg/controller/controllerutil/controllerutil.go
  49. +2 −2 pkg/controller/controllerutil/controllerutil_test.go
  50. +4 −18 pkg/envtest/server.go
  51. +11 −10 pkg/envtest/webhook_test.go
  52. +29 −29 pkg/finalizer/finalizer_test.go
  53. +8 −0 pkg/internal/controller/controller.go
  54. +4 −4 pkg/internal/controller/controller_test.go
  55. +1 −1 pkg/internal/recorder/recorder_test.go
  56. +3 −3 pkg/internal/testing/process/bin_path_finder_test.go
  57. +3 −0 pkg/log/deleg.go
  58. +10 −1 pkg/log/log.go
  59. +8 −0 pkg/log/log_test.go
  60. +1 −9 pkg/log/zap/zap.go
  61. +4 −1 pkg/manager/example_test.go
  62. +32 −94 pkg/manager/internal.go
  63. +93 −0 pkg/manager/internal/integration/api/v1/driver_types.go
  64. +34 −0 pkg/manager/internal/integration/api/v1/groupversion_info.go
  65. +111 −0 pkg/manager/internal/integration/api/v2/driver_types.go
  66. +34 −0 pkg/manager/internal/integration/api/v2/groupversion_info.go
  67. +29 −0 pkg/manager/internal/integration/manager_suite_test.go
  68. +295 −0 pkg/manager/internal/integration/manager_test.go
  69. +40 −131 pkg/manager/manager.go
  70. +3 −3 pkg/manager/manager_suite_test.go
  71. +490 −111 pkg/manager/manager_test.go
  72. +4 −0 pkg/manager/runnable_group.go
  73. +7 −0 pkg/manager/runnable_group_test.go
  74. +107 −0 pkg/metrics/filters/filters.go
  75. +0 −52 pkg/metrics/listener.go
  76. +26 −0 pkg/metrics/server/doc.go
  77. +312 −0 pkg/metrics/server/server.go
  78. +14 −2 pkg/reconcile/reconcile.go
  79. +5 −0 pkg/reconcile/reconcile_test.go
  80. +5 −4 pkg/source/source_test.go
  81. +1 −0 pkg/webhook/admission/decode.go
  82. +33 −0 pkg/webhook/admission/decode_test.go
  83. +3 −3 pkg/webhook/admission/http.go
  84. +2 −2 pkg/webhook/authentication/http.go
  85. +4 −3 pkg/webhook/conversion/testdata/main.go
  86. +8 −39 pkg/webhook/server.go
  87. +10 −8 pkg/webhook/server_test.go
  88. +15 −9 pkg/webhook/webhook_integration_test.go
  89. +3 −3 tools/setup-envtest/workflows/workflows_testutils_test.go
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -22,5 +22,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.1
version: v1.53.3
working-directory: ${{matrix.working-directory}}
35 changes: 35 additions & 0 deletions .github/workflows/pr-dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PR dependabot go modules fix

# This action runs on PRs opened by dependabot and updates modules.
on:
pull_request:
branches:
- dependabot/**
push:
branches:
- dependabot/**
workflow_dispatch:

permissions:
contents: write # Allow to update the PR.

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # tag=v3.5.3
- name: Set up Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # tag=v4.0.1
with:
go-version: '1.20'
- name: Update all modules
run: make modules
- uses: EndBug/add-and-commit@1bad3abcf0d6ec49a5857d124b0bfb52dc7bb081 # tag=v9.1.3
name: Commit changes
with:
author_name: dependabot[bot]
author_email: 49699333+dependabot[bot]@users.noreply.github.com
default_author: github_actor
message: 'Update generated code'
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@ linters:
- asciicheck
- bidichk
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- errchkjson
- errorlint
- exhaustive
- exportloopref
- ginkgolinter
- goconst
- gocritic
- gocyclo
@@ -62,10 +62,6 @@ linters-settings:
go: "1.20"
stylecheck:
go: "1.20"
depguard:
include-go-root: true
packages:
- io/ioutil # https://go.dev/doc/go1.16#ioutil
revive:
rules:
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint)
GO_APIDIFF := $(TOOLS_BIN_DIR)/go-apidiff
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
ENVTEST_DIR := $(abspath tools/setup-envtest)
SCRATCH_ENV_DIR := $(abspath examples/scratch-env)

# The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
# The awk commands is responsible to read the entire set of makefiles included in this invocation, looking for lines of the file as xyz: ## something, and then pretty-format the target and help. Then, if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -99,6 +100,7 @@ modules: ## Runs go mod to ensure modules are up to date.
go mod tidy
cd $(TOOLS_DIR); go mod tidy
cd $(ENVTEST_DIR); go mod tidy
cd $(SCRATCH_ENV_DIR); go mod tidy

.PHONY: generate
generate: $(CONTROLLER_GEN) ## Runs controller-gen for internal types for config file
@@ -110,6 +112,7 @@ generate: $(CONTROLLER_GEN) ## Runs controller-gen for internal types for config

.PHONY: clean
clean: ## Cleanup.
$(GOLANGCI_LINT) cache clean
$(MAKE) clean-bin

.PHONY: clean-bin
@@ -118,7 +121,7 @@ clean-bin: ## Remove all generated binaries.

.PHONY: verify-modules
verify-modules: modules ## Verify go modules are up to date
@if !(git diff --quiet HEAD -- go.sum go.mod $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/go.sum $(ENVTEST_DIR)/go.mod $(ENVTEST_DIR)/go.sum); then \
@if !(git diff --quiet HEAD -- go.sum go.mod $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/go.sum $(ENVTEST_DIR)/go.mod $(ENVTEST_DIR)/go.sum $(SCRATCH_ENV_DIR)/go.sum); then \
git diff; \
echo "go module files are out of date, please run 'make modules'"; exit 1; \
fi
8 changes: 4 additions & 4 deletions VERSIONING.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ exactly.

[guidelines]: https://sigs.k8s.io/kubebuilder-release-tools/VERSIONING.md

## Compatiblity and Release Support
## Compatibility and Release Support

For release branches, we generally tend to support backporting one (1)
major release (`release-{X-1}` or `release-0.{Y-1}`), but may go back
@@ -19,12 +19,12 @@ further if the need arises and is very pressing (e.g. security updates).

Note the [guidelines on dependency versions][dep-versions]. Particularly:

- We **DO** guarantee Kubernetes REST API compability -- if a given
- We **DO** guarantee Kubernetes REST API compatibility -- if a given
version of controller-runtime stops working with what should be
a supported version of Kubernetes, this is almost certainly a bug.

- We **DO NOT** guarantee any particular compability matrix between
- We **DO NOT** guarantee any particular compatibility matrix between
kubernetes library dependencies (client-go, apimachinery, etc); Such
compability is infeasible due to the way those libraries are versioned.
compatibility is infeasible due to the way those libraries are versioned.

[dep-versions]: https://sigs.k8s.io/kubebuilder-release-tools/VERSIONING.md#kubernetes-version-compatibility
3 changes: 3 additions & 0 deletions alias.go
Original file line number Diff line number Diff line change
@@ -110,6 +110,9 @@ var (
NewWebhookManagedBy = builder.WebhookManagedBy

// NewManager returns a new Manager for creating Controllers.
// Note that if ContentType in the given config is not set, "application/vnd.kubernetes.protobuf"
// will be used for all built-in resources of Kubernetes, and "application/json" is for other types
// including all CRD resources.
NewManager = manager.New

// CreateOrUpdate creates or updates the given object obj in the Kubernetes
226 changes: 226 additions & 0 deletions designs/cache_options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
Cache Options
===================

This document describes how we imagine the cache options to look in
the future.

## Goals

* Align everyone on what settings on the cache we want to support and
their configuration surface
* Ensure that we support both complicated cache setups and provide an
intuitive configuration UX

## Non-Goals

* Describe the design and implementation of the cache itself.
The assumption is that the most granular level we will end up with is
"per-object multiple namespaces with distinct selectors" and that this
can be implemented using a "meta cache" that delegates per object and by
extending the current multi-namespace cache
* Outline any kind of timeline for when these settings will be implemented.
Implementation will happen gradually over time whenever someone steps up
to do the actual work

## Proposal


```
const (
AllNamespaces = corev1.NamespaceAll
)
type Config struct {
// LabelSelector specifies a label selector. A nil value allows to
// default this.
LabelSelector labels.Selector
// FieldSelector specifics a field selector. A nil value allows to
// default this.
FieldSelector fields.Selector
// Transform specifies a transform func. A nil value allows to default
// this.
Transform toolscache.TransformFunc
// UnsafeDisableDeepCopy specifies if List and Get requests against the
// cache should not DeepCopy. A nil value allows to default this.
UnsafeDisableDeepCopy *bool
}
type ByObject struct {
// Namespaces maps a namespace name to cache setting. If set, only the
// namespaces in this map will be cached.
//
// Settings in the map value that are unset because either the value as a
// whole is nil or because the specific setting is nil will be defaulted.
// Use an empty value for the specific setting to prevent that.
//
// It is possible to have specific Config for just some namespaces
// but cache all namespaces by using the AllNamespaces const as the map key.
// This wil then include all namespaces that do not have a more specific
// setting.
//
// A nil map allows to default this to the cache's DefaultNamespaces setting.
// An empty map prevents this.
//
// This must be unset for cluster-scoped objects.
Namespaces map[string]*Config
// Config will be used for cluster-scoped objects and to default
// Config in the Namespaces field.
//
// It gets defaulted from the cache'sDefaultLabelSelector, DefaultFieldSelector,
// DefaultUnsafeDisableDeepCopy and DefaultTransform.
Config *Config
}
type Options struct {
// ByObject specifies per-object cache settings. If unset for a given
// object, this will fall through to Default* settings.
ByObject map[client.Object]*ByObject
// DefaultNamespaces maps namespace names to cache settings. If set, it
// will be used for all objects that have a nil Namespaces setting.
//
// It is possible to have a specific Config for just some namespaces
// but cache all namespaces by using the `AllNamespaces` const as the map
// key. This wil then include all namespaces that do not have a more
// specific setting.
//
// The options in the Config that are nil will be defaulted from
// the respective Default* settings.
DefaultNamespaces map[string]*Config
// DefaultLabelSelector is the label selector that will be used as
// the default field label selector for everything that doesn't
// have one configured.
DefaultLabelSelector labels.Selector
// DefaultFieldSelector is the field selector that will be used as
// the default field selector for everything that doesn't have
// one configured.
DefaultFieldSelector fields.Selector
// DefaultUnsafeDisableDeepCopy is the default for UnsafeDisableDeepCopy
// for everything that doesn't specify this.
DefaultUnsafeDisableDeepCopy *bool
// DefaultTransform will be used as transform for all object types
// unless they have a more specific transform set in ByObject.
DefaultTransform toolscache.TransformFunc
// HTTPClient is the http client to use for the REST client
HTTPClient *http.Client
// Scheme is the scheme to use for mapping objects to GroupVersionKinds
Scheme *runtime.Scheme
// Mapper is the RESTMapper to use for mapping GroupVersionKinds to Resources
Mapper meta.RESTMapper
// SyncPeriod determines the minimum frequency at which watched resources are
// reconciled. A lower period will correct entropy more quickly, but reduce
// responsiveness to change if there are many watched resources. Change this
// value only if you know what you are doing. Defaults to 10 hours if unset.
// there will a 10 percent jitter between the SyncPeriod of all controllers
// so that all controllers will not send list requests simultaneously.
//
// This applies to all controllers.
//
// A period sync happens for two reasons:
// 1. To insure against a bug in the controller that causes an object to not
// be requeued, when it otherwise should be requeued.
// 2. To insure against an unknown bug in controller-runtime, or its dependencies,
// that causes an object to not be requeued, when it otherwise should be
// requeued, or to be removed from the queue, when it otherwise should not
// be removed.
//
// If you want
// 1. to insure against missed watch events, or
// 2. to poll services that cannot be watched,
// then we recommend that, instead of changing the default period, the
// controller requeue, with a constant duration `t`, whenever the controller
// is "done" with an object, and would otherwise not requeue it, i.e., we
// recommend the `Reconcile` function return `reconcile.Result{RequeueAfter: t}`,
// instead of `reconcile.Result{}`.
SyncPeriod *time.Duration
}
```


## Example usages

### Cache ConfigMaps in the `public` and `kube-system` namespaces and Secrets in the `operator` Namespace


```
cache.Options{
ByObject: map[client.Object]*cache.ByObject{
&corev1.ConfigMap{}: {
Namespaces: map[string]*cache.Config{
"public": {},
"kube-system": {},
},
},
&corev1.Secret{}: {Namespaces: map[string]*Config{
"operator": {},
}},
},
}
```

### Cache ConfigMaps in all namespaces without selector, but have a selector for the `operator` Namespace

```
cache.Options{
ByObject: map[client.Object]*cache.ByObject{
&corev1.ConfigMap{}: {
Namespaces: map[string]*cache.Config{
cache.AllNamespaces: nil, // No selector for all namespaces...
"operator": {LabelSelector: labelSelector}, // except for the operator namespace
},
},
},
}
```


### Only cache the `operator` namespace for namespaced objects and all namespaces for Deployments

```
cache.Options{
ByObject: map[client.Object]*cache.ByObject{
&appsv1.Deployment: {Namespaces: map[string]*cache.Config{
cache.AllNamespaces: nil,
}},
},
DefaultNamespaces: map[string]*cache.Config{
"operator": nil,
},
}
```

### Use a LabelSelector for everything except Nodes

```
cache.Options{
ByObject: map[client.Object]*cache.ByObject{
&corev1.Node: {LabelSelector: labels.Everything()},
},
DefaultLabelSelector: myLabelSelector,
}
```

### Only cache namespaced objects in the `foo` and `bar` namespace

```
cache.Options{
DefaultNamespaces: map[string]*cache.Config{
"foo": nil,
"bar": nil,
}
}
```

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/scratch-env/go.mod
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ go 1.15

require (
github.com/spf13/pflag v1.0.5
go.uber.org/zap v1.25.0
sigs.k8s.io/controller-runtime v0.0.0-00010101000000-000000000000
)

Loading