Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / sigs.k8s.io / controller-runtime / pkg / reconcile / reconcile.go
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 reconcile
18
19 import (
20         "time"
21
22         "k8s.io/apimachinery/pkg/types"
23 )
24
25 // Result contains the result of a Reconciler invocation.
26 type Result struct {
27         // Requeue tells the Controller to requeue the reconcile key.  Defaults to false.
28         Requeue bool
29
30         // RequeueAfter if greater than 0, tells the Controller to requeue the reconcile key after the Duration.
31         RequeueAfter time.Duration
32 }
33
34 // Request contains the information necessary to reconcile a Kubernetes object.  This includes the
35 // information to uniquely identify the object - its Name and Namespace.  It does NOT contain information about
36 // any specific Event or the object contents itself.
37 type Request struct {
38         // NamespacedName is the name and namespace of the object to reconcile.
39         types.NamespacedName
40 }
41
42 /*
43 Reconciler implements a Kubernetes API for a specific Resource by Creating, Updating or Deleting Kubernetes
44 objects, or by making changes to systems external to the cluster (e.g. cloudproviders, github, etc).
45
46 reconcile implementations compare the state specified in an object by a user against the actual cluster state,
47 and then perform operations to make the actual cluster state reflect the state specified by the user.
48
49 Typically, reconcile is triggered by a Controller in response to cluster Events (e.g. Creating, Updating,
50 Deleting Kubernetes objects) or external Events (GitHub Webhooks, polling external sources, etc).
51
52 Example reconcile Logic:
53
54         * Reader an object and all the Pods it owns.
55         * Observe that the object spec specifies 5 replicas but actual cluster contains only 1 Pod replica.
56         * Create 4 Pods and set their OwnerReferences to the object.
57
58 reconcile may be implemented as either a type:
59
60         type reconcile struct {}
61
62         func (reconcile) reconcile(controller.Request) (controller.Result, error) {
63                 // Implement business logic of reading and writing objects here
64                 return controller.Result{}, nil
65         }
66
67 Or as a function:
68
69         controller.Func(func(o controller.Request) (controller.Result, error) {
70                 // Implement business logic of reading and writing objects here
71                 return controller.Result{}, nil
72         })
73
74 Reconciliation is level-based, meaning action isn't driven off changes in individual Events, but instead is
75 driven by actual cluster state read from the apiserver or a local cache.
76 For example if responding to a Pod Delete Event, the Request won't contain that a Pod was deleted,
77 instead the reconcile function observes this when reading the cluster state and seeing the Pod as missing.
78 */
79 type Reconciler interface {
80         // Reconciler performs a full reconciliation for the object referred to by the Request.
81         // The Controller will requeue the Request to be processed again if an error is non-nil or
82         // Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
83         Reconcile(Request) (Result, error)
84 }
85
86 // Func is a function that implements the reconcile interface.
87 type Func func(Request) (Result, error)
88
89 var _ Reconciler = Func(nil)
90
91 // Reconcile implements Reconciler.
92 func (r Func) Reconcile(o Request) (Result, error) { return r(o) }