Skip to content

Commit d7b2929

Browse files
committed
remove options.AndFrom deprecation
Signed-off-by: Troy Connor <[email protected]>
1 parent 8f8247f commit d7b2929

File tree

3 files changed

+0
-317
lines changed

3 files changed

+0
-317
lines changed

pkg/manager/manager.go

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ import (
2222
"fmt"
2323
"net"
2424
"net/http"
25-
"reflect"
2625
"time"
2726

2827
"github.com/go-logr/logr"
2928
coordinationv1 "k8s.io/api/coordination/v1"
3029
corev1 "k8s.io/api/core/v1"
3130
"k8s.io/apimachinery/pkg/api/meta"
32-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3331
"k8s.io/apimachinery/pkg/runtime"
3432
"k8s.io/client-go/rest"
3533
"k8s.io/client-go/tools/leaderelection/resourcelock"
@@ -41,7 +39,6 @@ import (
4139
"sigs.k8s.io/controller-runtime/pkg/client"
4240
"sigs.k8s.io/controller-runtime/pkg/cluster"
4341
"sigs.k8s.io/controller-runtime/pkg/config"
44-
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
4542
"sigs.k8s.io/controller-runtime/pkg/healthz"
4643
intrec "sigs.k8s.io/controller-runtime/pkg/internal/recorder"
4744
"sigs.k8s.io/controller-runtime/pkg/leaderelection"
@@ -438,126 +435,6 @@ func New(config *rest.Config, options Options) (Manager, error) {
438435
}, nil
439436
}
440437

441-
// AndFrom will use a supplied type and convert to Options
442-
// any options already set on Options will be ignored, this is used to allow
443-
// cli flags to override anything specified in the config file.
444-
//
445-
// Deprecated: This function has been deprecated and will be removed in a future release,
446-
// The Component Configuration package has been unmaintained for over a year and is no longer
447-
// actively developed. Users should migrate to their own configuration format
448-
// and configure Manager.Options directly.
449-
// See https://github.com/kubernetes-sigs/controller-runtime/issues/895
450-
// for more information, feedback, and comments.
451-
func (o Options) AndFrom(loader config.ControllerManagerConfiguration) (Options, error) {
452-
newObj, err := loader.Complete()
453-
if err != nil {
454-
return o, err
455-
}
456-
457-
o = o.setLeaderElectionConfig(newObj)
458-
459-
if o.Cache.SyncPeriod == nil && newObj.SyncPeriod != nil {
460-
o.Cache.SyncPeriod = &newObj.SyncPeriod.Duration
461-
}
462-
463-
if len(o.Cache.DefaultNamespaces) == 0 && newObj.CacheNamespace != "" {
464-
o.Cache.DefaultNamespaces = map[string]cache.Config{newObj.CacheNamespace: {}}
465-
}
466-
467-
if o.Metrics.BindAddress == "" && newObj.Metrics.BindAddress != "" {
468-
o.Metrics.BindAddress = newObj.Metrics.BindAddress
469-
}
470-
471-
if o.HealthProbeBindAddress == "" && newObj.Health.HealthProbeBindAddress != "" {
472-
o.HealthProbeBindAddress = newObj.Health.HealthProbeBindAddress
473-
}
474-
475-
if o.ReadinessEndpointName == "" && newObj.Health.ReadinessEndpointName != "" {
476-
o.ReadinessEndpointName = newObj.Health.ReadinessEndpointName
477-
}
478-
479-
if o.LivenessEndpointName == "" && newObj.Health.LivenessEndpointName != "" {
480-
o.LivenessEndpointName = newObj.Health.LivenessEndpointName
481-
}
482-
483-
if o.WebhookServer == nil {
484-
port := 0
485-
if newObj.Webhook.Port != nil {
486-
port = *newObj.Webhook.Port
487-
}
488-
o.WebhookServer = webhook.NewServer(webhook.Options{
489-
Port: port,
490-
Host: newObj.Webhook.Host,
491-
CertDir: newObj.Webhook.CertDir,
492-
})
493-
}
494-
495-
if newObj.Controller != nil {
496-
if o.Controller.CacheSyncTimeout == 0 && newObj.Controller.CacheSyncTimeout != nil {
497-
o.Controller.CacheSyncTimeout = *newObj.Controller.CacheSyncTimeout
498-
}
499-
500-
if len(o.Controller.GroupKindConcurrency) == 0 && len(newObj.Controller.GroupKindConcurrency) > 0 {
501-
o.Controller.GroupKindConcurrency = newObj.Controller.GroupKindConcurrency
502-
}
503-
}
504-
505-
return o, nil
506-
}
507-
508-
// AndFromOrDie will use options.AndFrom() and will panic if there are errors.
509-
//
510-
// Deprecated: This function has been deprecated and will be removed in a future release,
511-
// The Component Configuration package has been unmaintained for over a year and is no longer
512-
// actively developed. Users should migrate to their own configuration format
513-
// and configure Manager.Options directly.
514-
// See https://github.com/kubernetes-sigs/controller-runtime/issues/895
515-
// for more information, feedback, and comments.
516-
func (o Options) AndFromOrDie(loader config.ControllerManagerConfiguration) Options {
517-
o, err := o.AndFrom(loader)
518-
if err != nil {
519-
panic(fmt.Sprintf("could not parse config file: %v", err))
520-
}
521-
return o
522-
}
523-
524-
func (o Options) setLeaderElectionConfig(obj v1alpha1.ControllerManagerConfigurationSpec) Options {
525-
if obj.LeaderElection == nil {
526-
// The source does not have any configuration; noop
527-
return o
528-
}
529-
530-
if !o.LeaderElection && obj.LeaderElection.LeaderElect != nil {
531-
o.LeaderElection = *obj.LeaderElection.LeaderElect
532-
}
533-
534-
if o.LeaderElectionResourceLock == "" && obj.LeaderElection.ResourceLock != "" {
535-
o.LeaderElectionResourceLock = obj.LeaderElection.ResourceLock
536-
}
537-
538-
if o.LeaderElectionNamespace == "" && obj.LeaderElection.ResourceNamespace != "" {
539-
o.LeaderElectionNamespace = obj.LeaderElection.ResourceNamespace
540-
}
541-
542-
if o.LeaderElectionID == "" && obj.LeaderElection.ResourceName != "" {
543-
o.LeaderElectionID = obj.LeaderElection.ResourceName
544-
}
545-
546-
if o.LeaseDuration == nil && !reflect.DeepEqual(obj.LeaderElection.LeaseDuration, metav1.Duration{}) {
547-
o.LeaseDuration = &obj.LeaderElection.LeaseDuration.Duration
548-
}
549-
550-
if o.RenewDeadline == nil && !reflect.DeepEqual(obj.LeaderElection.RenewDeadline, metav1.Duration{}) {
551-
o.RenewDeadline = &obj.LeaderElection.RenewDeadline.Duration
552-
}
553-
554-
if o.RetryPeriod == nil && !reflect.DeepEqual(obj.LeaderElection.RetryPeriod, metav1.Duration{}) {
555-
o.RetryPeriod = &obj.LeaderElection.RetryPeriod.Duration
556-
}
557-
558-
return o
559-
}
560-
561438
// defaultHealthProbeListener creates the default health probes listener bound to the given address.
562439
func defaultHealthProbeListener(addr string) (net.Listener, error) {
563440
if addr == "" || addr == "0" {

pkg/manager/manager_options_test.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

pkg/manager/manager_test.go

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package manager
1818

1919
import (
2020
"context"
21-
"crypto/tls"
2221
"errors"
2322
"fmt"
2423
"io"
@@ -37,12 +36,10 @@ import (
3736
coordinationv1 "k8s.io/api/coordination/v1"
3837
corev1 "k8s.io/api/core/v1"
3938
"k8s.io/apimachinery/pkg/api/meta"
40-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4139
"k8s.io/apimachinery/pkg/runtime"
4240
"k8s.io/apimachinery/pkg/runtime/schema"
4341
"k8s.io/client-go/rest"
4442
"k8s.io/client-go/tools/leaderelection/resourcelock"
45-
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
4643
"sigs.k8s.io/controller-runtime/pkg/cache"
4744
"sigs.k8s.io/controller-runtime/pkg/cache/informertest"
4845
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -120,143 +117,6 @@ var _ = Describe("manger.Manager", func() {
120117
Expect(err.Error()).To(ContainSubstring("expected error"))
121118
})
122119

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-
260120
It("should lazily initialize a webhook server if needed", func() {
261121
By("creating a manager with options")
262122
m, err := New(cfg, Options{WebhookServer: webhook.NewServer(webhook.Options{Port: 9440, Host: "foo.com"})})

0 commit comments

Comments
 (0)