Skip to content

Commit 63e5fef

Browse files
committed
[0.14] Deprecate component configuration package
This provides an early warning for users on 0.14 that the pkg/config types are going to be removed in a future release and they should migrate off. Signed-off-by: Vince Prignano <[email protected]>
1 parent b718c5d commit 63e5fef

17 files changed

+85
-38
lines changed

alias.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"k8s.io/apimachinery/pkg/runtime/schema"
2222
"sigs.k8s.io/controller-runtime/pkg/builder"
2323
"sigs.k8s.io/controller-runtime/pkg/client/config"
24-
cfg "sigs.k8s.io/controller-runtime/pkg/config"
24+
cfg "sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
2525
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2626
"sigs.k8s.io/controller-runtime/pkg/log"
2727
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -99,7 +99,8 @@ var (
9999
// ConfigFile returns the cfg.File function for deferred config file loading,
100100
// this is passed into Options{}.From() to populate the Options fields for
101101
// the manager.
102-
ConfigFile = cfg.File
102+
// Deprecated: This is deprecated in favor of using Options directly.
103+
ConfigFile = cfg.File //nolint:staticcheck
103104

104105
// NewControllerManagedBy returns a new controller builder that will be started by the provided Manager.
105106
NewControllerManagedBy = builder.ControllerManagedBy

pkg/builder/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (blder *Builder) getControllerName(gvk schema.GroupVersionKind, hasGVK bool
285285
}
286286

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

290290
ctrlOptions := blder.ctrlOptions
291291
if ctrlOptions.Reconciler == nil {

pkg/builder/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
"sigs.k8s.io/controller-runtime/pkg/cache"
3838
"sigs.k8s.io/controller-runtime/pkg/client"
39-
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
39+
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
4040
"sigs.k8s.io/controller-runtime/pkg/controller"
4141
"sigs.k8s.io/controller-runtime/pkg/event"
4242
"sigs.k8s.io/controller-runtime/pkg/handler"
@@ -235,7 +235,7 @@ var _ = Describe("application", func() {
235235

236236
By("creating a controller manager")
237237
m, err := manager.New(cfg, manager.Options{
238-
Controller: v1alpha1.ControllerConfigurationSpec{
238+
Controller: v1alpha1.ControllerConfigurationSpec{ //nolint:staticcheck
239239
GroupKindConcurrency: map[string]int{
240240
"ReplicaSet.apps": maxConcurrentReconciles,
241241
},

pkg/config/config.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,24 @@ import (
2424
"k8s.io/apimachinery/pkg/runtime"
2525
"k8s.io/apimachinery/pkg/runtime/serializer"
2626
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
27-
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
27+
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
2828
)
2929

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

3537
// Complete returns the versioned configuration
36-
Complete() (v1alpha1.ControllerManagerConfigurationSpec, error)
38+
Complete() (v1alpha1.ControllerManagerConfigurationSpec, error) //nolint:staticcheck
3739
}
3840

3941
// DeferredFileLoader is used to configure the decoder for loading controller
4042
// runtime component config types.
43+
//
44+
// Deprecated: This package has been deprecated and will be removed in a future release.
4145
type DeferredFileLoader struct {
4246
ControllerManagerConfiguration
4347
path string
@@ -52,6 +56,8 @@ type DeferredFileLoader struct {
5256
// Defaults:
5357
// * Path: "./config.yaml"
5458
// * Kind: GenericControllerManagerConfiguration
59+
//
60+
// Deprecated: This package has been deprecated and will be removed in a future release.
5561
func File() *DeferredFileLoader {
5662
scheme := runtime.NewScheme()
5763
utilruntime.Must(v1alpha1.AddToScheme(scheme))
@@ -63,6 +69,8 @@ func File() *DeferredFileLoader {
6369
}
6470

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

74-
// AtPath will set the path to load the file for the decoder.
82+
// AtPath will set the path to load the file for the decoder
83+
//
84+
// Deprecated: This package has been deprecated and will be removed in a future release.
7585
func (d *DeferredFileLoader) AtPath(path string) *DeferredFileLoader {
7686
d.path = path
7787
return d
7888
}
7989

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

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

92106
// loadFile is used from the mutex.Once to load the file.
107+
//
108+
// Deprecated: This package has been deprecated and will be removed in a future release.
93109
func (d *DeferredFileLoader) loadFile() {
94110
if d.scheme == nil {
95111
d.err = fmt.Errorf("scheme not supplied to controller configuration loader")

pkg/config/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package config_test
1919
import (
2020
. "github.com/onsi/ginkgo/v2"
2121
. "github.com/onsi/gomega"
22-
"sigs.k8s.io/controller-runtime/pkg/config"
23-
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
22+
"sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
23+
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
2424
)
2525

2626
var _ = Describe("config", func() {
@@ -33,7 +33,7 @@ var _ = Describe("config", func() {
3333
})
3434

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

pkg/config/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ limitations under the License.
2222
// This uses a deferred file decoding allowing you to chain your configuration
2323
// setup. You can pass this into manager.Options#File and it will load your
2424
// config.
25+
//
26+
// Deprecated: This package has been deprecated and will be removed in a future release.
2527
package config

pkg/config/example_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import (
2121
"os"
2222

2323
"k8s.io/apimachinery/pkg/runtime"
24-
"sigs.k8s.io/controller-runtime/pkg/config"
25-
2624
"sigs.k8s.io/controller-runtime/examples/configfile/custom/v1alpha1"
25+
"sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
2726
)
2827

2928
var scheme = runtime.NewScheme()

pkg/config/v1alpha1/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ limitations under the License.
1717
// Package v1alpha1 provides the ControllerManagerConfiguration used for
1818
// configuring ctrl.Manager
1919
// +kubebuilder:object:generate=true
20+
//
21+
// Deprecated: This package has been deprecated and will be removed in a future release.
2022
package v1alpha1

pkg/config/v1alpha1/register.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ import (
2323

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

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

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

pkg/config/v1alpha1/types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
)
2626

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

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

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

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

159167
// Complete returns the configuration for controller-runtime.
168+
//
169+
// Deprecated: This package has been deprecated and will be removed in a future release.
160170
func (c *ControllerManagerConfigurationSpec) Complete() (ControllerManagerConfigurationSpec, error) {
161171
return *c, nil
162172
}

pkg/controller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller
141141
}
142142

143143
if options.RecoverPanic == nil {
144-
options.RecoverPanic = mgr.GetControllerOptions().RecoverPanic
144+
options.RecoverPanic = mgr.GetControllerOptions().RecoverPanic //nolint:staticcheck
145145
}
146146

147147
// Create controller with dependencies set

pkg/controller/controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"k8s.io/utils/pointer"
2929

3030
"sigs.k8s.io/controller-runtime/pkg/client"
31-
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
31+
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
3232
"sigs.k8s.io/controller-runtime/pkg/controller"
3333
"sigs.k8s.io/controller-runtime/pkg/event"
3434
"sigs.k8s.io/controller-runtime/pkg/handler"
@@ -147,7 +147,7 @@ var _ = Describe("controller.Controller", func() {
147147
})
148148

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

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

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

169169
c, err := controller.New("new-controller", m, controller.Options{

pkg/manager/example_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"sigs.k8s.io/controller-runtime/pkg/cache"
2424
"sigs.k8s.io/controller-runtime/pkg/client/config"
25-
conf "sigs.k8s.io/controller-runtime/pkg/config"
25+
conf "sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
2626
logf "sigs.k8s.io/controller-runtime/pkg/log"
2727
"sigs.k8s.io/controller-runtime/pkg/manager"
2828
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
@@ -92,7 +92,7 @@ func ExampleManager_start() {
9292
// using defaults.
9393
func ExampleOptions_andFrom() {
9494
opts := manager.Options{}
95-
if _, err := opts.AndFrom(conf.File()); err != nil {
95+
if _, err := opts.AndFrom(conf.File()); err != nil { //nolint:staticcheck
9696
log.Error(err, "unable to load config")
9797
os.Exit(1)
9898
}
@@ -120,7 +120,7 @@ func ExampleOptions_andFromOrDie() {
120120
os.Exit(1)
121121
}
122122

123-
mgr, err := manager.New(cfg, manager.Options{}.AndFromOrDie(conf.File()))
123+
mgr, err := manager.New(cfg, manager.Options{}.AndFromOrDie(conf.File())) //nolint:staticcheck
124124
if err != nil {
125125
log.Error(err, "unable to set up manager")
126126
os.Exit(1)

pkg/manager/internal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
"sigs.k8s.io/controller-runtime/pkg/cache"
4242
"sigs.k8s.io/controller-runtime/pkg/client"
4343
"sigs.k8s.io/controller-runtime/pkg/cluster"
44-
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
44+
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
4545
"sigs.k8s.io/controller-runtime/pkg/healthz"
4646
"sigs.k8s.io/controller-runtime/pkg/internal/httpserver"
4747
intrec "sigs.k8s.io/controller-runtime/pkg/internal/recorder"
@@ -108,7 +108,7 @@ type controllerManager struct {
108108
healthzHandler *healthz.Handler
109109

110110
// controllerOptions are the global controller options.
111-
controllerOptions v1alpha1.ControllerConfigurationSpec
111+
controllerOptions v1alpha1.ControllerConfigurationSpec //nolint:staticcheck
112112

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

328-
func (cm *controllerManager) GetControllerOptions() v1alpha1.ControllerConfigurationSpec {
328+
func (cm *controllerManager) GetControllerOptions() v1alpha1.ControllerConfigurationSpec { //nolint:staticcheck
329329
return cm.controllerOptions
330330
}
331331

pkg/manager/manager.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import (
3636
"sigs.k8s.io/controller-runtime/pkg/cache"
3737
"sigs.k8s.io/controller-runtime/pkg/client"
3838
"sigs.k8s.io/controller-runtime/pkg/cluster"
39-
"sigs.k8s.io/controller-runtime/pkg/config"
40-
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
39+
"sigs.k8s.io/controller-runtime/pkg/config" //nolint:staticcheck
40+
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
4141
"sigs.k8s.io/controller-runtime/pkg/healthz"
4242
intrec "sigs.k8s.io/controller-runtime/pkg/internal/recorder"
4343
"sigs.k8s.io/controller-runtime/pkg/leaderelection"
@@ -94,7 +94,11 @@ type Manager interface {
9494
GetLogger() logr.Logger
9595

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

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

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

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

532-
func (o Options) setLeaderElectionConfig(obj v1alpha1.ControllerManagerConfigurationSpec) Options {
544+
func (o Options) setLeaderElectionConfig(obj v1alpha1.ControllerManagerConfigurationSpec) Options { //nolint:staticcheck
533545
if obj.LeaderElection == nil {
534546
// The source does not have any configuration; noop
535547
return o

0 commit comments

Comments
 (0)