|
| 1 | +/* |
| 2 | +Copyright 2018 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +// Package controllerruntime provides tools to construct Kubernetes-style |
| 18 | +// controllers that manipulate both Kubernetes CRDs and aggregated/built-in |
| 19 | +// Kubernetes APIs. |
| 20 | +// |
| 21 | +// It defines easy helpers for the common use cases when building CRDs, built |
| 22 | +// on top of customizable layers of abstraction. Common cases should be easy, |
| 23 | +// and uncommon cases should be possible. In general, controller-runtime tries |
| 24 | +// to guide users towards Kubernetes controller best-practices. |
| 25 | +// |
| 26 | +// Overview |
| 27 | +// |
| 28 | +// The main entrypoint for controller-runtime is this root package, which |
| 29 | +// contains all of the common types needed to get started building controllers: |
| 30 | +// import ( |
| 31 | +// controllers "sigs.k8s.io/controller-runtime" |
| 32 | +// ) |
| 33 | +// |
| 34 | +// The examples in this package walk through a basic controller setup. The |
| 35 | +// kubebuilder book (https://book.kubebuilder.io) has some more in-depth |
| 36 | +// walkthroughs. |
| 37 | +// |
| 38 | +// controller-runtime favors structs with sane defaults over constructors, so |
| 39 | +// it's fairly common to see structs being used directly in controller-runtime. |
| 40 | +// |
| 41 | +// Organization |
| 42 | +// |
| 43 | +// A brief walkthrough of the layout of this library can be found below. Each |
| 44 | +// package contains more information about how to use it. |
| 45 | +// |
| 46 | +// Frequently asked questions about using controller-runtime and designing |
| 47 | +// controllers can be found at |
| 48 | +// https://github.com/kubernetes-sigs/controller-runtime/blob/master/FAQ. |
| 49 | +// |
| 50 | +// Managers |
| 51 | +// |
| 52 | +// Every controller and webhook is ultimately run by a Manager (pkg/manager). A |
| 53 | +// manager is responsible for running controllers and webhooks, and setting up |
| 54 | +// common dependencies (pkg/runtime/inject), like shared caches and clients, as |
| 55 | +// well as managing leader election (pkg/leaderelection). Managers are |
| 56 | +// generally configured to gracefully shut down controllers on pod termination |
| 57 | +// by wiring up a signal handler (pkg/runtime/signals). |
| 58 | +// |
| 59 | +// Controllers |
| 60 | +// |
| 61 | +// Controllers (pkg/controller) handle using events (pkg/events) to eventually |
| 62 | +// trigger reconcile requests. They may be constructed manually, but are often |
| 63 | +// constructed with a Builder (pkg/builder), which eases the wiring of event |
| 64 | +// sources (pkg/source), like Kubernetes API object changes, to event handlers |
| 65 | +// (pkg/handler), like "enqueue a reconcile request for the object owner". |
| 66 | +// Predicates (pkg/predicate) can be used to filter which events actually |
| 67 | +// trigger reconciles. There are pre-written utilies for the common cases, and |
| 68 | +// interfaces and helpers for advanced cases. |
| 69 | +// |
| 70 | +// Reconcilers |
| 71 | +// |
| 72 | +// Controller logic is implemented in terms of Reconcilers (pkg/reconcile). A |
| 73 | +// Reconciler implements a function which takes a reconcile Request containing |
| 74 | +// the name and namespace of the object to reconcile, reconciles the object, |
| 75 | +// and returns a Response or an error indicating whether to requeue for a |
| 76 | +// second round of processing. |
| 77 | +// |
| 78 | +// Clients (and Caches) |
| 79 | +// |
| 80 | +// Reconcilers use Clients (pkg/client) to access API objects. The default |
| 81 | +// client provided by the manager reads from a local shared cache (pkg/cache) |
| 82 | +// and writes directly to the API server, but clients can be constructed that |
| 83 | +// only talk to the API server, without a cache. The Cache will auto-populate |
| 84 | +// with watched objects, as well as when other structured objects are |
| 85 | +// requested. Caches may also have indexes, which can be created via a |
| 86 | +// FieldIndexer (pkg/client) obtained from the manager. Indexes can used to |
| 87 | +// quickly and easily look up all objects with certain fields set. Reconcilers |
| 88 | +// may retrieve event recorders (pkg/recorder) to emit events using the |
| 89 | +// manager. |
| 90 | +// |
| 91 | +// Webhooks |
| 92 | +// |
| 93 | +// Similarly, webhooks (pkg/webhook/admission) may be implemented directly, but |
| 94 | +// are often constructed using a builder (pkg/webhook/admission/builder). They |
| 95 | +// are run via a server (pkg/webhook) which is managed by a Manager. |
| 96 | +// |
| 97 | +// Logging and Metrics |
| 98 | +// |
| 99 | +// Logging (pkg/log) in controller-runtime is done via structured logs, using a |
| 100 | +// log interface set called logr (https://godoc.org/github.com/go-logr/logr). |
| 101 | +// While controller-runtime provides easy setup for using Zap |
| 102 | +// (https://go.uber.org/zap, pkg/log/zap), you can provide any implementation |
| 103 | +// of logr as the base logger for controller-runtime. |
| 104 | +// |
| 105 | +// Metrics (pkg/metrics) provided by controller-runtime are registered into a |
| 106 | +// controller-runtime-specific Prometheus metrics registery. The manager will |
| 107 | +// serve these by default at an HTTP endpoint, and additional metrics may be |
| 108 | +// registered to this Registry as normal. |
| 109 | +// |
| 110 | +// Testing |
| 111 | +// |
| 112 | +// You can easily build integration and unit tests for your controllers and |
| 113 | +// webhooks using the test Environment (pkg/envtest). This will automatically |
| 114 | +// stand up a copy of etcd and kube-apiserver, and provide the correct options |
| 115 | +// to connect to the API server. It's designed to work well with the Ginkgo |
| 116 | +// testing framework, but should work with any testing setup. |
| 117 | +package controllerruntime |
0 commit comments