@@ -18,7 +18,6 @@ package manager
18
18
19
19
import (
20
20
"context"
21
- "crypto/tls"
22
21
"errors"
23
22
"fmt"
24
23
"io"
@@ -37,12 +36,10 @@ import (
37
36
coordinationv1 "k8s.io/api/coordination/v1"
38
37
corev1 "k8s.io/api/core/v1"
39
38
"k8s.io/apimachinery/pkg/api/meta"
40
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
41
39
"k8s.io/apimachinery/pkg/runtime"
42
40
"k8s.io/apimachinery/pkg/runtime/schema"
43
41
"k8s.io/client-go/rest"
44
42
"k8s.io/client-go/tools/leaderelection/resourcelock"
45
- configv1alpha1 "k8s.io/component-base/config/v1alpha1"
46
43
"sigs.k8s.io/controller-runtime/pkg/cache"
47
44
"sigs.k8s.io/controller-runtime/pkg/cache/informertest"
48
45
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -120,143 +117,6 @@ var _ = Describe("manger.Manager", func() {
120
117
Expect (err .Error ()).To (ContainSubstring ("expected error" ))
121
118
})
122
119
123
- It ("should be able to load Options from cfg.ControllerManagerConfiguration type" , func () {
124
- duration := metav1.Duration {Duration : 48 * time .Hour }
125
- port := int (6090 )
126
- leaderElect := false
127
-
128
- ccfg := & v1alpha1.ControllerManagerConfiguration {
129
- ControllerManagerConfigurationSpec : v1alpha1.ControllerManagerConfigurationSpec {
130
- SyncPeriod : & duration ,
131
- LeaderElection : & configv1alpha1.LeaderElectionConfiguration {
132
- LeaderElect : & leaderElect ,
133
- ResourceLock : "leases" ,
134
- ResourceNamespace : "default" ,
135
- ResourceName : "ctrl-lease" ,
136
- LeaseDuration : duration ,
137
- RenewDeadline : duration ,
138
- RetryPeriod : duration ,
139
- },
140
- CacheNamespace : "default" ,
141
- Metrics : v1alpha1.ControllerMetrics {
142
- BindAddress : ":6000" ,
143
- },
144
- Health : v1alpha1.ControllerHealth {
145
- HealthProbeBindAddress : "6060" ,
146
- ReadinessEndpointName : "/readyz" ,
147
- LivenessEndpointName : "/livez" ,
148
- },
149
- Webhook : v1alpha1.ControllerWebhook {
150
- Port : & port ,
151
- Host : "localhost" ,
152
- CertDir : "/certs" ,
153
- },
154
- },
155
- }
156
-
157
- m , err := Options {}.AndFrom (& fakeDeferredLoader {ccfg })
158
- Expect (err ).ToNot (HaveOccurred ())
159
-
160
- Expect (* m .Cache .SyncPeriod ).To (Equal (duration .Duration ))
161
- Expect (m .LeaderElection ).To (Equal (leaderElect ))
162
- Expect (m .LeaderElectionResourceLock ).To (Equal ("leases" ))
163
- Expect (m .LeaderElectionNamespace ).To (Equal ("default" ))
164
- Expect (m .LeaderElectionID ).To (Equal ("ctrl-lease" ))
165
- Expect (m .LeaseDuration .String ()).To (Equal (duration .Duration .String ()))
166
- Expect (m .RenewDeadline .String ()).To (Equal (duration .Duration .String ()))
167
- Expect (m .RetryPeriod .String ()).To (Equal (duration .Duration .String ()))
168
- Expect (m .Cache .DefaultNamespaces ).To (Equal (map [string ]cache.Config {"default" : {}}))
169
- Expect (m .Metrics .BindAddress ).To (Equal (":6000" ))
170
- Expect (m .HealthProbeBindAddress ).To (Equal ("6060" ))
171
- Expect (m .ReadinessEndpointName ).To (Equal ("/readyz" ))
172
- Expect (m .LivenessEndpointName ).To (Equal ("/livez" ))
173
- Expect (m .WebhookServer .(* webhook.DefaultServer ).Options .Port ).To (Equal (port ))
174
- Expect (m .WebhookServer .(* webhook.DefaultServer ).Options .Host ).To (Equal ("localhost" ))
175
- Expect (m .WebhookServer .(* webhook.DefaultServer ).Options .CertDir ).To (Equal ("/certs" ))
176
- })
177
-
178
- It ("should be able to keep Options when cfg.ControllerManagerConfiguration set" , func () {
179
- optDuration := time .Duration (2 )
180
- duration := metav1.Duration {Duration : 48 * time .Hour }
181
- port := int (6090 )
182
- leaderElect := false
183
-
184
- ccfg := & v1alpha1.ControllerManagerConfiguration {
185
- ControllerManagerConfigurationSpec : v1alpha1.ControllerManagerConfigurationSpec {
186
- SyncPeriod : & duration ,
187
- LeaderElection : & configv1alpha1.LeaderElectionConfiguration {
188
- LeaderElect : & leaderElect ,
189
- ResourceLock : "leases" ,
190
- ResourceNamespace : "default" ,
191
- ResourceName : "ctrl-lease" ,
192
- LeaseDuration : duration ,
193
- RenewDeadline : duration ,
194
- RetryPeriod : duration ,
195
- },
196
- CacheNamespace : "default" ,
197
- Metrics : v1alpha1.ControllerMetrics {
198
- BindAddress : ":6000" ,
199
- },
200
- Health : v1alpha1.ControllerHealth {
201
- HealthProbeBindAddress : "6060" ,
202
- ReadinessEndpointName : "/readyz" ,
203
- LivenessEndpointName : "/livez" ,
204
- },
205
- Webhook : v1alpha1.ControllerWebhook {
206
- Port : & port ,
207
- Host : "localhost" ,
208
- CertDir : "/certs" ,
209
- },
210
- },
211
- }
212
-
213
- optionsTlSOptsFuncs := []func (* tls.Config ){
214
- func (config * tls.Config ) {},
215
- }
216
- m , err := Options {
217
- Cache : cache.Options {
218
- SyncPeriod : & optDuration ,
219
- DefaultNamespaces : map [string ]cache.Config {"ctrl" : {}},
220
- },
221
- LeaderElection : true ,
222
- LeaderElectionResourceLock : "configmaps" ,
223
- LeaderElectionNamespace : "ctrl" ,
224
- LeaderElectionID : "ctrl-configmap" ,
225
- LeaseDuration : & optDuration ,
226
- RenewDeadline : & optDuration ,
227
- RetryPeriod : & optDuration ,
228
- Metrics : metricsserver.Options {BindAddress : ":7000" },
229
- HealthProbeBindAddress : "5000" ,
230
- ReadinessEndpointName : "/readiness" ,
231
- LivenessEndpointName : "/liveness" ,
232
- WebhookServer : webhook .NewServer (webhook.Options {
233
- Port : 8080 ,
234
- Host : "example.com" ,
235
- CertDir : "/pki" ,
236
- TLSOpts : optionsTlSOptsFuncs ,
237
- }),
238
- }.AndFrom (& fakeDeferredLoader {ccfg })
239
- Expect (err ).ToNot (HaveOccurred ())
240
-
241
- Expect (m .Cache .SyncPeriod .String ()).To (Equal (optDuration .String ()))
242
- Expect (m .LeaderElection ).To (BeTrue ())
243
- Expect (m .LeaderElectionResourceLock ).To (Equal ("configmaps" ))
244
- Expect (m .LeaderElectionNamespace ).To (Equal ("ctrl" ))
245
- Expect (m .LeaderElectionID ).To (Equal ("ctrl-configmap" ))
246
- Expect (m .LeaseDuration .String ()).To (Equal (optDuration .String ()))
247
- Expect (m .RenewDeadline .String ()).To (Equal (optDuration .String ()))
248
- Expect (m .RetryPeriod .String ()).To (Equal (optDuration .String ()))
249
- Expect (m .Cache .DefaultNamespaces ).To (Equal (map [string ]cache.Config {"ctrl" : {}}))
250
- Expect (m .Metrics .BindAddress ).To (Equal (":7000" ))
251
- Expect (m .HealthProbeBindAddress ).To (Equal ("5000" ))
252
- Expect (m .ReadinessEndpointName ).To (Equal ("/readiness" ))
253
- Expect (m .LivenessEndpointName ).To (Equal ("/liveness" ))
254
- Expect (m .WebhookServer .(* webhook.DefaultServer ).Options .Port ).To (Equal (8080 ))
255
- Expect (m .WebhookServer .(* webhook.DefaultServer ).Options .Host ).To (Equal ("example.com" ))
256
- Expect (m .WebhookServer .(* webhook.DefaultServer ).Options .CertDir ).To (Equal ("/pki" ))
257
- Expect (m .WebhookServer .(* webhook.DefaultServer ).Options .TLSOpts ).To (Equal (optionsTlSOptsFuncs ))
258
- })
259
-
260
120
It ("should lazily initialize a webhook server if needed" , func () {
261
121
By ("creating a manager with options" )
262
122
m , err := New (cfg , Options {WebhookServer : webhook .NewServer (webhook.Options {Port : 9440 , Host : "foo.com" })})
0 commit comments