Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / sigs.k8s.io / controller-runtime / pkg / runtime / inject / inject.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 inject
18
19 import (
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"
25 )
26
27 // Cache is used by the ControllerManager to inject Cache into Sources, EventHandlers, Predicates, and
28 // Reconciles
29 type Cache interface {
30         InjectCache(cache cache.Cache) error
31 }
32
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)
38         }
39         return false, nil
40 }
41
42 // Config is used by the ControllerManager to inject Config into Sources, EventHandlers, Predicates, and
43 // Reconciles
44 type Config interface {
45         InjectConfig(*rest.Config) error
46 }
47
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)
53         }
54         return false, nil
55 }
56
57 // Client is used by the ControllerManager to inject client into Sources, EventHandlers, Predicates, and
58 // Reconciles
59 type Client interface {
60         InjectClient(client.Client) error
61 }
62
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)
68         }
69         return false, nil
70 }
71
72 // Decoder is used by the ControllerManager to inject decoder into webhook handlers.
73 type Decoder interface {
74         InjectDecoder(types.Decoder) error
75 }
76
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)
82         }
83         return false, nil
84 }
85
86 // Scheme is used by the ControllerManager to inject Scheme into Sources, EventHandlers, Predicates, and
87 // Reconciles
88 type Scheme interface {
89         InjectScheme(scheme *runtime.Scheme) error
90 }
91
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)
97         }
98         return false, nil
99 }
100
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
105 }
106
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)
112         }
113         return false, nil
114 }
115
116 // Func injects dependencies into i.
117 type Func func(i interface{}) error
118
119 // Injector is used by the ControllerManager to inject Func into Controllers
120 type Injector interface {
121         InjectFunc(f Func) error
122 }
123
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)
129         }
130         return false, nil
131 }