Skip to content

Commit 375a05e

Browse files
authored
Merge pull request #2149 from vincepri/deprecate-config-v1alpha1
⚠️ Deprecate pkg/config/v1alpha1 types
2 parents f3f16a2 + cb5fcac commit 375a05e

20 files changed

+120
-428
lines changed

alias.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ 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+
//
103+
// Deprecated: This is deprecated in favor of using Options directly.
104+
ConfigFile = cfg.File //nolint:staticcheck
103105

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

pkg/builder/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ func (blder *Builder) doController(r reconcile.Reconciler) error {
370370
}
371371

372372
// Setup cache sync timeout.
373-
if ctrlOptions.CacheSyncTimeout == 0 && globalOpts.CacheSyncTimeout != nil {
374-
ctrlOptions.CacheSyncTimeout = *globalOpts.CacheSyncTimeout
373+
if ctrlOptions.CacheSyncTimeout == 0 && globalOpts.CacheSyncTimeout > 0 {
374+
ctrlOptions.CacheSyncTimeout = globalOpts.CacheSyncTimeout
375375
}
376376

377377
controllerName, err := blder.getControllerName(gvk, hasGVK)

pkg/builder/controller_test.go

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

3838
"sigs.k8s.io/controller-runtime/pkg/cache"
3939
"sigs.k8s.io/controller-runtime/pkg/client"
40-
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
40+
"sigs.k8s.io/controller-runtime/pkg/config"
4141
"sigs.k8s.io/controller-runtime/pkg/controller"
4242
"sigs.k8s.io/controller-runtime/pkg/event"
4343
"sigs.k8s.io/controller-runtime/pkg/handler"
@@ -217,7 +217,7 @@ var _ = Describe("application", func() {
217217
instance, err := ControllerManagedBy(m).
218218
For(&appsv1.ReplicaSet{}).
219219
Owns(&appsv1.ReplicaSet{}).
220-
WithOptions(controller.Options{MaxConcurrentReconciles: maxConcurrentReconciles}).
220+
WithOptions(controller.Options{Controller: config.Controller{MaxConcurrentReconciles: maxConcurrentReconciles}}).
221221
Build(noop)
222222
Expect(err).NotTo(HaveOccurred())
223223
Expect(instance).NotTo(BeNil())
@@ -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: config.Controller{
239239
GroupKindConcurrency: map[string]int{
240240
"ReplicaSet.apps": maxConcurrentReconciles,
241241
},

pkg/config/config.go

Lines changed: 10 additions & 4 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,10 +69,10 @@ func File() *DeferredFileLoader {
6369
}
6470

6571
// Complete will use sync.Once to set the scheme.
66-
func (d *DeferredFileLoader) Complete() (v1alpha1.ControllerManagerConfigurationSpec, error) {
72+
func (d *DeferredFileLoader) Complete() (v1alpha1.ControllerManagerConfigurationSpec, error) { //nolint:staticcheck
6773
d.once.Do(d.loadFile)
6874
if d.err != nil {
69-
return v1alpha1.ControllerManagerConfigurationSpec{}, d.err
75+
return v1alpha1.ControllerManagerConfigurationSpec{}, d.err //nolint:staticcheck
7076
}
7177
return d.ControllerManagerConfiguration.Complete()
7278
}

pkg/config/config_suite_test.go

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

pkg/config/config_test.go

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

pkg/config/controller.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package config
18+
19+
import "time"
20+
21+
// Controller contains configuration options for a controller.
22+
type Controller struct {
23+
// GroupKindConcurrency is a map from a Kind to the number of concurrent reconciliation
24+
// allowed for that controller.
25+
//
26+
// When a controller is registered within this manager using the builder utilities,
27+
// users have to specify the type the controller reconciles in the For(...) call.
28+
// If the object's kind passed matches one of the keys in this map, the concurrency
29+
// for that controller is set to the number specified.
30+
//
31+
// The key is expected to be consistent in form with GroupKind.String(),
32+
// e.g. ReplicaSet in apps group (regardless of version) would be `ReplicaSet.apps`.
33+
GroupKindConcurrency map[string]int
34+
35+
// MaxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 1.
36+
MaxConcurrentReconciles int
37+
38+
// CacheSyncTimeout refers to the time limit set to wait for syncing caches.
39+
// Defaults to 2 minutes if not set.
40+
CacheSyncTimeout time.Duration
41+
42+
// RecoverPanic indicates whether the panic caused by reconcile should be recovered.
43+
// Defaults to the Controller.RecoverPanic setting from the Manager if unset.
44+
RecoverPanic *bool
45+
46+
// NeedLeaderElection indicates whether the controller needs to use leader election.
47+
// Defaults to true, which means the controller will use leader election.
48+
NeedLeaderElection *bool
49+
}

pkg/config/doc.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package config contains functionality for interacting with ComponentConfig
18-
// files
19-
//
20-
// # DeferredFileLoader
21-
//
22-
// This uses a deferred file decoding allowing you to chain your configuration
23-
// setup. You can pass this into manager.Options#File and it will load your
24-
// config.
17+
// Package config contains functionality for interacting with
18+
// configuration for controller-runtime components.
2519
package config

pkg/config/example_test.go

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

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: 14 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.
@@ -101,6 +105,8 @@ type ControllerConfigurationSpec struct {
101105
}
102106

103107
// ControllerMetrics defines the metrics configs.
108+
//
109+
// Deprecated: This package has been deprecated and will be removed in a future release.
104110
type ControllerMetrics struct {
105111
// BindAddress is the TCP address that the controller should bind to
106112
// for serving prometheus metrics.
@@ -110,6 +116,8 @@ type ControllerMetrics struct {
110116
}
111117

112118
// ControllerHealth defines the health configs.
119+
//
120+
// Deprecated: This package has been deprecated and will be removed in a future release.
113121
type ControllerHealth struct {
114122
// HealthProbeBindAddress is the TCP address that the controller should bind to
115123
// for serving health probes
@@ -127,6 +135,8 @@ type ControllerHealth struct {
127135
}
128136

129137
// ControllerWebhook defines the webhook server for the controller.
138+
//
139+
// Deprecated: This package has been deprecated and will be removed in a future release.
130140
type ControllerWebhook struct {
131141
// Port is the port that the webhook server serves at.
132142
// It is used to set webhook.Server.Port.
@@ -149,6 +159,8 @@ type ControllerWebhook struct {
149159
// +kubebuilder:object:root=true
150160

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

@@ -157,6 +169,8 @@ type ControllerManagerConfiguration struct {
157169
}
158170

159171
// Complete returns the configuration for controller-runtime.
172+
//
173+
// Deprecated: This package has been deprecated and will be removed in a future release.
160174
func (c *ControllerManagerConfigurationSpec) Complete() (ControllerManagerConfigurationSpec, error) {
161175
return *c, nil
162176
}

0 commit comments

Comments
 (0)