Skip to content

Commit d18328e

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

File tree

4 files changed

+0
-358
lines changed

4 files changed

+0
-358
lines changed

pkg/manager/example_test.go

-41
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"k8s.io/client-go/rest"
2424
"sigs.k8s.io/controller-runtime/pkg/cache"
2525
"sigs.k8s.io/controller-runtime/pkg/client/config"
26-
conf "sigs.k8s.io/controller-runtime/pkg/config"
2726
logf "sigs.k8s.io/controller-runtime/pkg/log"
2827
"sigs.k8s.io/controller-runtime/pkg/manager"
2928
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
@@ -94,43 +93,3 @@ func ExampleManager_start() {
9493
os.Exit(1)
9594
}
9695
}
97-
98-
// This example will populate Options from a custom config file
99-
// using defaults.
100-
func ExampleOptions_andFrom() {
101-
opts := manager.Options{}
102-
if _, err := opts.AndFrom(conf.File()); err != nil {
103-
log.Error(err, "unable to load config")
104-
os.Exit(1)
105-
}
106-
107-
cfg, err := config.GetConfig()
108-
if err != nil {
109-
log.Error(err, "unable to get kubeconfig")
110-
os.Exit(1)
111-
}
112-
113-
mgr, err := manager.New(cfg, opts)
114-
if err != nil {
115-
log.Error(err, "unable to set up manager")
116-
os.Exit(1)
117-
}
118-
log.Info("created manager", "manager", mgr)
119-
}
120-
121-
// This example will populate Options from a custom config file
122-
// using defaults and will panic if there are errors.
123-
func ExampleOptions_andFromOrDie() {
124-
cfg, err := config.GetConfig()
125-
if err != nil {
126-
log.Error(err, "unable to get kubeconfig")
127-
os.Exit(1)
128-
}
129-
130-
mgr, err := manager.New(cfg, manager.Options{}.AndFromOrDie(conf.File()))
131-
if err != nil {
132-
log.Error(err, "unable to set up manager")
133-
os.Exit(1)
134-
}
135-
log.Info("created manager", "manager", mgr)
136-
}

pkg/manager/manager.go

-123
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

-54
This file was deleted.

0 commit comments

Comments
 (0)