controller-runtime is a subproject of kubebuilder which provides a lot of useful tools that help develop Kubernetes Operator.
Version: v0.13.0
- Create a Manager.
- Cluster, which has
Cache
,Client
,Scheme
, etc, is created internally. Read cluster for more details.
- Cluster, which has
- Create one or multiple Reconcilers. For more details, read reconciler.
- Build the
Reconciler
(s) with theManager
usingBuilder
.- Internally,
builder.doWatch
andbuilder.doController
are called. - bldr.doController calls newController to create a new Controller and add it to
manager.runnables.Others
byManager.Add(Runnable)
. (controller)- Inject dependencies to Reconciler and Controller. e.g. Cache.
- bldr.doWatch creates Kind (Source) and call controller.Watch for
For
,Owns
, andWatches
.- controller.Watch calls
source.Start()
, which gets informer from the injected cache and add the event handler.
- controller.Watch calls
- Internally,
- Start the
Manager
, which trigger to start all themgr.runnables
(Caches
,Webhooks
,Others
) in theManager
.Informer.Run
is called incm.runnables.Caches.Start(cm.internalCtx)
For more details, you can check the architecture in book.kubebuilder.io:
List of components:
- Manager: Package manager is required to create Controllers and provides shared dependencies such as clients, caches, schemes, etc.
- Controller: Package controller provides types and functions for building Controllers. The Controller MUST be started by calling Manager.Start.
- Event
- Builder
- Source
- Handler
- Predicate
- Client: Package client contains functionality for interacting with Kubernetes API servers.
- delegatingClient: The default client type whose Get and List get object from cache.CacheReader, which reduces the API requests to API server.
- Cache
- client.Reader: Cache acts as a client to objects stored in the cache.
- Informers: Cache loads informers and adds field indices.
- Scheme: Wraps apimachinery/Scheme.
- Webhook
- Envtest
- example-controller
- envtest
-
v0.11.0: Allow Specification of the Log Timestamp Format. -> Default EpochTimeEncoder
-
-
⚠️ Refactor source/handler/predicate packages to remove dep injection #2120- kindWithCacheMysqlUser := source.NewKindWithCache(mysqluser, cache) - kindWithCacheMysql := source.NewKindWithCache(mysql, cache) - kindWithCachesecret := source.NewKindWithCache(secret, cache) + kindWithCacheMysqlUser := source.Kind(cache, mysqluser) + kindWithCacheMysql := source.Kind(cache, mysql) + kindWithCachesecret := source.Kind(cache, secret)
-
Example PR: nakamasato/secret-mirror-operator#28
-
-
-
⚠ Introduce Metrics Options struct & secure metrics serving #2407
import ( + metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" ) - MetricsBindAddress: metricsAddr + Metrics: metricsserver.Options{BindAddress: metricsAddr},
-
⚠ Remove deprecated manager, webhook and cluster options #2422
-
Example PR: nakamasato/secret-mirror-operator#28
-