Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ Deprecate pkg/config/v1alpha1 types #2149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ 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.
ConfigFile = cfg.File
//
// Deprecated: This is deprecated in favor of using Options directly.
ConfigFile = cfg.File //nolint:staticcheck

// NewControllerManagedBy returns a new controller builder that will be started by the provided Manager.
NewControllerManagedBy = builder.ControllerManagedBy
Expand Down
4 changes: 2 additions & 2 deletions pkg/builder/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ func (blder *Builder) doController(r reconcile.Reconciler) error {
}

// Setup cache sync timeout.
if ctrlOptions.CacheSyncTimeout == 0 && globalOpts.CacheSyncTimeout != nil {
ctrlOptions.CacheSyncTimeout = *globalOpts.CacheSyncTimeout
if ctrlOptions.CacheSyncTimeout == 0 && globalOpts.CacheSyncTimeout > 0 {
ctrlOptions.CacheSyncTimeout = globalOpts.CacheSyncTimeout
}

controllerName, err := blder.getControllerName(gvk, hasGVK)
Expand Down
6 changes: 3 additions & 3 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (

"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/config"
"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 @@ -217,7 +217,7 @@ var _ = Describe("application", func() {
instance, err := ControllerManagedBy(m).
For(&appsv1.ReplicaSet{}).
Owns(&appsv1.ReplicaSet{}).
WithOptions(controller.Options{MaxConcurrentReconciles: maxConcurrentReconciles}).
WithOptions(controller.Options{Controller: config.Controller{MaxConcurrentReconciles: maxConcurrentReconciles}}).
Build(noop)
Expect(err).NotTo(HaveOccurred())
Expect(instance).NotTo(BeNil())
Expand All @@ -235,7 +235,7 @@ var _ = Describe("application", func() {

By("creating a controller manager")
m, err := manager.New(cfg, manager.Options{
Controller: v1alpha1.ControllerConfigurationSpec{
Controller: config.Controller{
GroupKindConcurrency: map[string]int{
"ReplicaSet.apps": maxConcurrentReconciles,
},
Expand Down
14 changes: 10 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ 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"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
)

// 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)
Complete() (v1alpha1.ControllerManagerConfigurationSpec, error) //nolint:staticcheck
}

// 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 @@ -52,6 +56,8 @@ 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 @@ -63,10 +69,10 @@ func File() *DeferredFileLoader {
}

// Complete will use sync.Once to set the scheme.
func (d *DeferredFileLoader) Complete() (v1alpha1.ControllerManagerConfigurationSpec, error) {
func (d *DeferredFileLoader) Complete() (v1alpha1.ControllerManagerConfigurationSpec, error) { //nolint:staticcheck
d.once.Do(d.loadFile)
if d.err != nil {
return v1alpha1.ControllerManagerConfigurationSpec{}, d.err
return v1alpha1.ControllerManagerConfigurationSpec{}, d.err //nolint:staticcheck
}
return d.ControllerManagerConfiguration.Complete()
}
Expand Down
29 changes: 0 additions & 29 deletions pkg/config/config_suite_test.go

This file was deleted.

48 changes: 0 additions & 48 deletions pkg/config/config_test.go

This file was deleted.

49 changes: 49 additions & 0 deletions pkg/config/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2023 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

import "time"

// Controller contains configuration options for a controller.
type Controller struct {
// GroupKindConcurrency is a map from a Kind to the number of concurrent reconciliation
// allowed for that controller.
//
// When a controller is registered within this manager using the builder utilities,
// users have to specify the type the controller reconciles in the For(...) call.
// If the object's kind passed matches one of the keys in this map, the concurrency
// for that controller is set to the number specified.
//
// The key is expected to be consistent in form with GroupKind.String(),
// e.g. ReplicaSet in apps group (regardless of version) would be `ReplicaSet.apps`.
GroupKindConcurrency map[string]int

// MaxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 1.
MaxConcurrentReconciles int

// CacheSyncTimeout refers to the time limit set to wait for syncing caches.
// Defaults to 2 minutes if not set.
CacheSyncTimeout time.Duration

// RecoverPanic indicates whether the panic caused by reconcile should be recovered.
// Defaults to the Controller.RecoverPanic setting from the Manager if unset.
RecoverPanic *bool

// NeedLeaderElection indicates whether the controller needs to use leader election.
// Defaults to true, which means the controller will use leader election.
NeedLeaderElection *bool
}
Comment on lines +21 to +49
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These options have to live in a different package, otherwise controller <-> manager get into a import cycle

10 changes: 2 additions & 8 deletions pkg/config/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package config contains functionality for interacting with ComponentConfig
// files
//
// # DeferredFileLoader
//
// 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.
// Package config contains functionality for interacting with
// configuration for controller-runtime components.
package config
53 changes: 0 additions & 53 deletions pkg/config/example_test.go

This file was deleted.

2 changes: 2 additions & 0 deletions pkg/config/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ 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: 6 additions & 0 deletions pkg/config/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ 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
14 changes: 14 additions & 0 deletions pkg/config/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ 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 @@ -75,6 +77,8 @@ 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 All @@ -101,6 +105,8 @@ type ControllerConfigurationSpec struct {
}

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

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

// ControllerWebhook defines the webhook server for the controller.
//
// Deprecated: This package has been deprecated and will be removed in a future release.
type ControllerWebhook struct {
// Port is the port that the webhook server serves at.
// It is used to set webhook.Server.Port.
Expand All @@ -149,6 +159,8 @@ 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"`

Expand All @@ -157,6 +169,8 @@ type ControllerManagerConfiguration struct {
}

// 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
}