Skip to content

Commit

Permalink
Revert "🌱 [0.14] Deprecate component configuration package"
Browse files Browse the repository at this point in the history
  • Loading branch information
vincepri authored Feb 13, 2023
1 parent b9940ed commit 5d27848
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 85 deletions.
5 changes: 2 additions & 3 deletions alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client/config"
cfg "sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
cfg "sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -99,8 +99,7 @@ var (
// ConfigFile returns the cfg.File function for deferred config file loading,
// this is passed into Options{}.From() to populate the Options fields for
// the manager.
// Deprecated: This is deprecated in favor of using Options directly.
ConfigFile = cfg.File //nolint:staticcheck
ConfigFile = cfg.File

// NewControllerManagedBy returns a new controller builder that will be started by the provided Manager.
NewControllerManagedBy = builder.ControllerManagedBy
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (blder *Builder) getControllerName(gvk schema.GroupVersionKind, hasGVK bool
}

func (blder *Builder) doController(r reconcile.Reconciler) error {
globalOpts := blder.mgr.GetControllerOptions() //nolint:staticcheck
globalOpts := blder.mgr.GetControllerOptions()

ctrlOptions := blder.ctrlOptions
if ctrlOptions.Reconciler == nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down Expand Up @@ -235,7 +235,7 @@ var _ = Describe("application", func() {

By("creating a controller manager")
m, err := manager.New(cfg, manager.Options{
Controller: v1alpha1.ControllerConfigurationSpec{ //nolint:staticcheck
Controller: v1alpha1.ControllerConfigurationSpec{
GroupKindConcurrency: map[string]int{
"ReplicaSet.apps": maxConcurrentReconciles,
},
Expand Down
22 changes: 3 additions & 19 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,20 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
)

// ControllerManagerConfiguration defines the functions necessary to parse a config file
// and to configure the Options struct for the ctrl.Manager.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
type ControllerManagerConfiguration interface {
runtime.Object

// Complete returns the versioned configuration
Complete() (v1alpha1.ControllerManagerConfigurationSpec, error) //nolint:staticcheck
Complete() (v1alpha1.ControllerManagerConfigurationSpec, error)
}

// DeferredFileLoader is used to configure the decoder for loading controller
// runtime component config types.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
type DeferredFileLoader struct {
ControllerManagerConfiguration
path string
Expand All @@ -56,8 +52,6 @@ type DeferredFileLoader struct {
// Defaults:
// * Path: "./config.yaml"
// * Kind: GenericControllerManagerConfiguration
//
// Deprecated: This package has been deprecated and will be removed in a future release.
func File() *DeferredFileLoader {
scheme := runtime.NewScheme()
utilruntime.Must(v1alpha1.AddToScheme(scheme))
Expand All @@ -69,8 +63,6 @@ func File() *DeferredFileLoader {
}

// Complete will use sync.Once to set the scheme.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
func (d *DeferredFileLoader) Complete() (v1alpha1.ControllerManagerConfigurationSpec, error) {
d.once.Do(d.loadFile)
if d.err != nil {
Expand All @@ -79,33 +71,25 @@ func (d *DeferredFileLoader) Complete() (v1alpha1.ControllerManagerConfiguration
return d.ControllerManagerConfiguration.Complete()
}

// AtPath will set the path to load the file for the decoder
//
// Deprecated: This package has been deprecated and will be removed in a future release.
// AtPath will set the path to load the file for the decoder.
func (d *DeferredFileLoader) AtPath(path string) *DeferredFileLoader {
d.path = path
return d
}

// OfKind will set the type to be used for decoding the file into.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
func (d *DeferredFileLoader) OfKind(obj ControllerManagerConfiguration) *DeferredFileLoader {
d.ControllerManagerConfiguration = obj
return d
}

// InjectScheme will configure the scheme to be used for decoding the file.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
func (d *DeferredFileLoader) InjectScheme(scheme *runtime.Scheme) error {
d.scheme = scheme
return nil
}

// loadFile is used from the mutex.Once to load the file.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
func (d *DeferredFileLoader) loadFile() {
if d.scheme == nil {
d.err = fmt.Errorf("scheme not supplied to controller configuration loader")
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package config_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
)

var _ = Describe("config", func() {
Expand All @@ -33,7 +33,7 @@ var _ = Describe("config", func() {
})

It("should load a config from file", func() {
conf := v1alpha1.ControllerManagerConfiguration{} //nolint:staticcheck
conf := v1alpha1.ControllerManagerConfiguration{}
loader := config.File().AtPath("./testdata/config.yaml").OfKind(&conf)
Expect(conf.CacheNamespace).To(Equal(""))

Expand Down
2 changes: 0 additions & 2 deletions pkg/config/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ limitations under the License.
// This uses a deferred file decoding allowing you to chain your configuration
// setup. You can pass this into manager.Options#File and it will load your
// config.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
package config
3 changes: 2 additions & 1 deletion pkg/config/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (
"os"

"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/config"

"sigs.k8s.io/controller-runtime/examples/configfile/custom/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
)

var scheme = runtime.NewScheme()
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ limitations under the License.
// Package v1alpha1 provides the ControllerManagerConfiguration used for
// configuring ctrl.Manager
// +kubebuilder:object:generate=true
//
// Deprecated: This package has been deprecated and will be removed in a future release.
package v1alpha1
6 changes: 0 additions & 6 deletions pkg/config/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ import (

var (
// GroupVersion is group version used to register these objects.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
GroupVersion = schema.GroupVersion{Group: "controller-runtime.sigs.k8s.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
AddToScheme = SchemeBuilder.AddToScheme
)

Expand Down
10 changes: 0 additions & 10 deletions pkg/config/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
)

// ControllerManagerConfigurationSpec defines the desired state of GenericControllerManagerConfiguration.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
type ControllerManagerConfigurationSpec struct {
// SyncPeriod determines the minimum frequency at which watched resources are
// reconciled. A lower period will correct entropy more quickly, but reduce
Expand Down Expand Up @@ -77,8 +75,6 @@ type ControllerManagerConfigurationSpec struct {

// ControllerConfigurationSpec defines the global configuration for
// controllers registered with the manager.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
type ControllerConfigurationSpec struct {
// GroupKindConcurrency is a map from a Kind to the number of concurrent reconciliation
// allowed for that controller.
Expand Down Expand Up @@ -153,20 +149,14 @@ type ControllerWebhook struct {
// +kubebuilder:object:root=true

// ControllerManagerConfiguration is the Schema for the GenericControllerManagerConfigurations API.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
type ControllerManagerConfiguration struct {
metav1.TypeMeta `json:",inline"`

// ControllerManagerConfiguration returns the contfigurations for controllers
//
// Deprecated: This package has been deprecated and will be removed in a future release.
ControllerManagerConfigurationSpec `json:",inline"`
}

// Complete returns the configuration for controller-runtime.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
func (c *ControllerManagerConfigurationSpec) Complete() (ControllerManagerConfigurationSpec, error) {
return *c, nil
}
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller
}

if options.RecoverPanic == nil {
options.RecoverPanic = mgr.GetControllerOptions().RecoverPanic //nolint:staticcheck
options.RecoverPanic = mgr.GetControllerOptions().RecoverPanic
}

// Create controller with dependencies set
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"k8s.io/utils/pointer"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down Expand Up @@ -147,7 +147,7 @@ var _ = Describe("controller.Controller", func() {
})

It("should default RecoverPanic from the manager", func() {
m, err := manager.New(cfg, manager.Options{Controller: v1alpha1.ControllerConfigurationSpec{RecoverPanic: pointer.Bool(true)}}) //nolint:staticcheck
m, err := manager.New(cfg, manager.Options{Controller: v1alpha1.ControllerConfigurationSpec{RecoverPanic: pointer.Bool(true)}})
Expect(err).NotTo(HaveOccurred())

c, err := controller.New("new-controller", m, controller.Options{
Expand All @@ -163,7 +163,7 @@ var _ = Describe("controller.Controller", func() {
})

It("should not override RecoverPanic on the controller", func() {
m, err := manager.New(cfg, manager.Options{Controller: v1alpha1.ControllerConfigurationSpec{RecoverPanic: pointer.Bool(true)}}) //nolint:staticcheck
m, err := manager.New(cfg, manager.Options{Controller: v1alpha1.ControllerConfigurationSpec{RecoverPanic: pointer.Bool(true)}})
Expect(err).NotTo(HaveOccurred())

c, err := controller.New("new-controller", m, controller.Options{
Expand Down
6 changes: 3 additions & 3 deletions pkg/manager/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client/config"
conf "sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
conf "sigs.k8s.io/controller-runtime/pkg/config"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
Expand Down Expand Up @@ -92,7 +92,7 @@ func ExampleManager_start() {
// using defaults.
func ExampleOptions_andFrom() {
opts := manager.Options{}
if _, err := opts.AndFrom(conf.File()); err != nil { //nolint:staticcheck
if _, err := opts.AndFrom(conf.File()); err != nil {
log.Error(err, "unable to load config")
os.Exit(1)
}
Expand Down Expand Up @@ -120,7 +120,7 @@ func ExampleOptions_andFromOrDie() {
os.Exit(1)
}

mgr, err := manager.New(cfg, manager.Options{}.AndFromOrDie(conf.File())) //nolint:staticcheck
mgr, err := manager.New(cfg, manager.Options{}.AndFromOrDie(conf.File()))
if err != nil {
log.Error(err, "unable to set up manager")
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions pkg/manager/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/internal/httpserver"
intrec "sigs.k8s.io/controller-runtime/pkg/internal/recorder"
Expand Down Expand Up @@ -108,7 +108,7 @@ type controllerManager struct {
healthzHandler *healthz.Handler

// controllerOptions are the global controller options.
controllerOptions v1alpha1.ControllerConfigurationSpec //nolint:staticcheck
controllerOptions v1alpha1.ControllerConfigurationSpec

// Logger is the logger that should be used by this manager.
// If none is set, it defaults to log.Log global logger.
Expand Down Expand Up @@ -325,7 +325,7 @@ func (cm *controllerManager) GetLogger() logr.Logger {
return cm.logger
}

func (cm *controllerManager) GetControllerOptions() v1alpha1.ControllerConfigurationSpec { //nolint:staticcheck
func (cm *controllerManager) GetControllerOptions() v1alpha1.ControllerConfigurationSpec {
return cm.controllerOptions
}

Expand Down
22 changes: 5 additions & 17 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/healthz"
intrec "sigs.k8s.io/controller-runtime/pkg/internal/recorder"
"sigs.k8s.io/controller-runtime/pkg/leaderelection"
Expand Down Expand Up @@ -94,11 +94,7 @@ type Manager interface {
GetLogger() logr.Logger

// GetControllerOptions returns controller global configuration options.
//
// Deprecated: In a future version, the returned value is going to be replaced with a
// different type that doesn't rely on component configuration types.
// This is a temporary warning, and no action is needed as of today.
GetControllerOptions() v1alpha1.ControllerConfigurationSpec //nolint:staticcheck
GetControllerOptions() v1alpha1.ControllerConfigurationSpec
}

// Options are the arguments for creating a new Manager.
Expand Down Expand Up @@ -301,11 +297,7 @@ type Options struct {
// Controller contains global configuration options for controllers
// registered within this manager.
// +optional
//
// Deprecated: In a future version, the type of this field is going to be replaced with a
// different struct that doesn't rely on component configuration types.
// This is a temporary warning, and no action is needed as of today.
Controller v1alpha1.ControllerConfigurationSpec //nolint:staticcheck
Controller v1alpha1.ControllerConfigurationSpec

// makeBroadcaster allows deferring the creation of the broadcaster to
// avoid leaking goroutines if we never call Start on this manager. It also
Expand Down Expand Up @@ -464,8 +456,6 @@ func New(config *rest.Config, options Options) (Manager, error) {
// AndFrom will use a supplied type and convert to Options
// any options already set on Options will be ignored, this is used to allow
// cli flags to override anything specified in the config file.
//
// Deprecated: This method will be removed in a future release.
func (o Options) AndFrom(loader config.ControllerManagerConfiguration) (Options, error) {
if inj, wantsScheme := loader.(inject.Scheme); wantsScheme {
err := inj.InjectScheme(o.Scheme)
Expand Down Expand Up @@ -531,8 +521,6 @@ func (o Options) AndFrom(loader config.ControllerManagerConfiguration) (Options,
}

// AndFromOrDie will use options.AndFrom() and will panic if there are errors.
//
// Deprecated: This method will be removed in a future release.
func (o Options) AndFromOrDie(loader config.ControllerManagerConfiguration) Options {
o, err := o.AndFrom(loader)
if err != nil {
Expand All @@ -541,7 +529,7 @@ func (o Options) AndFromOrDie(loader config.ControllerManagerConfiguration) Opti
return o
}

func (o Options) setLeaderElectionConfig(obj v1alpha1.ControllerManagerConfigurationSpec) Options { //nolint:staticcheck
func (o Options) setLeaderElectionConfig(obj v1alpha1.ControllerManagerConfigurationSpec) Options {
if obj.LeaderElection == nil {
// The source does not have any configuration; noop
return o
Expand Down
Loading

0 comments on commit 5d27848

Please sign in to comment.