2 Copyright 2018 The Kubernetes Authors.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
20 "k8s.io/apimachinery/pkg/runtime"
21 "k8s.io/client-go/rest"
22 "sigs.k8s.io/controller-runtime/pkg/cache"
23 "sigs.k8s.io/controller-runtime/pkg/client"
24 "sigs.k8s.io/controller-runtime/pkg/webhook/admission/types"
27 // Cache is used by the ControllerManager to inject Cache into Sources, EventHandlers, Predicates, and
29 type Cache interface {
30 InjectCache(cache cache.Cache) error
33 // CacheInto will set informers on i and return the result if it implements Cache. Returns
34 //// false if i does not implement Cache.
35 func CacheInto(c cache.Cache, i interface{}) (bool, error) {
36 if s, ok := i.(Cache); ok {
37 return true, s.InjectCache(c)
42 // Config is used by the ControllerManager to inject Config into Sources, EventHandlers, Predicates, and
44 type Config interface {
45 InjectConfig(*rest.Config) error
48 // ConfigInto will set config on i and return the result if it implements Config. Returns
49 //// false if i does not implement Config.
50 func ConfigInto(config *rest.Config, i interface{}) (bool, error) {
51 if s, ok := i.(Config); ok {
52 return true, s.InjectConfig(config)
57 // Client is used by the ControllerManager to inject client into Sources, EventHandlers, Predicates, and
59 type Client interface {
60 InjectClient(client.Client) error
63 // ClientInto will set client on i and return the result if it implements Client. Returns
64 // false if i does not implement Client.
65 func ClientInto(client client.Client, i interface{}) (bool, error) {
66 if s, ok := i.(Client); ok {
67 return true, s.InjectClient(client)
72 // Decoder is used by the ControllerManager to inject decoder into webhook handlers.
73 type Decoder interface {
74 InjectDecoder(types.Decoder) error
77 // DecoderInto will set decoder on i and return the result if it implements Decoder. Returns
78 // false if i does not implement Decoder.
79 func DecoderInto(decoder types.Decoder, i interface{}) (bool, error) {
80 if s, ok := i.(Decoder); ok {
81 return true, s.InjectDecoder(decoder)
86 // Scheme is used by the ControllerManager to inject Scheme into Sources, EventHandlers, Predicates, and
88 type Scheme interface {
89 InjectScheme(scheme *runtime.Scheme) error
92 // SchemeInto will set scheme and return the result on i if it implements Scheme. Returns
93 // false if i does not implement Scheme.
94 func SchemeInto(scheme *runtime.Scheme, i interface{}) (bool, error) {
95 if is, ok := i.(Scheme); ok {
96 return true, is.InjectScheme(scheme)
101 // Stoppable is used by the ControllerManager to inject stop channel into Sources,
102 // EventHandlers, Predicates, and Reconciles.
103 type Stoppable interface {
104 InjectStopChannel(<-chan struct{}) error
107 // StopChannelInto will set stop channel on i and return the result if it implements Stoppable.
108 // Returns false if i does not implement Stoppable.
109 func StopChannelInto(stop <-chan struct{}, i interface{}) (bool, error) {
110 if s, ok := i.(Stoppable); ok {
111 return true, s.InjectStopChannel(stop)
116 // Func injects dependencies into i.
117 type Func func(i interface{}) error
119 // Injector is used by the ControllerManager to inject Func into Controllers
120 type Injector interface {
121 InjectFunc(f Func) error
124 // InjectorInto will set f and return the result on i if it implements Injector. Returns
125 // false if i does not implement Injector.
126 func InjectorInto(f Func, i interface{}) (bool, error) {
127 if ii, ok := i.(Injector); ok {
128 return true, ii.InjectFunc(f)