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

[WIP] 🌱 Use manager and builder pkgs of controller-runtime explicitly. #7175

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/v1beta1/index/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"fmt"

"github.com/pkg/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)
Expand All @@ -34,7 +34,7 @@ const (

// ByClusterClassName adds the cluster class name index to the
// managers cache.
func ByClusterClassName(ctx context.Context, mgr ctrl.Manager) error {
func ByClusterClassName(ctx context.Context, mgr manager.Manager) error {
if err := mgr.GetCache().IndexField(ctx, &clusterv1.Cluster{},
ClusterClassNameField,
clusterByClassName,
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ package index
import (
"context"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/manager"

"sigs.k8s.io/cluster-api/feature"
)

// AddDefaultIndexes registers the default list of indexes.
func AddDefaultIndexes(ctx context.Context, mgr ctrl.Manager) error {
func AddDefaultIndexes(ctx context.Context, mgr manager.Manager) error {
if err := ByMachineNode(ctx, mgr); err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions api/v1beta1/index/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

"github.com/pkg/errors"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/noderefutil"
Expand All @@ -40,7 +40,7 @@ const (

// ByMachineNode adds the machine node name index to the
// managers cache.
func ByMachineNode(ctx context.Context, mgr ctrl.Manager) error {
func ByMachineNode(ctx context.Context, mgr manager.Manager) error {
if err := mgr.GetCache().IndexField(ctx, &clusterv1.Machine{},
MachineNodeNameField,
machineByNodeName,
Expand All @@ -64,7 +64,7 @@ func machineByNodeName(o client.Object) []string {

// ByMachineProviderID adds the machine providerID index to the
// managers cache.
func ByMachineProviderID(ctx context.Context, mgr ctrl.Manager) error {
func ByMachineProviderID(ctx context.Context, mgr manager.Manager) error {
if err := mgr.GetCache().IndexField(ctx, &clusterv1.Machine{},
MachineProviderIDField,
machineByProviderID,
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/machine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"sigs.k8s.io/cluster-api/util/version"
)

const defaultNodeDeletionTimeout = 10 * time.Second

func (m *Machine) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
func (m *Machine) SetupWebhookWithManager(mgr manager.Manager) error {
return builder.WebhookManagedBy(mgr).
For(m).
Complete()
}
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/machinedeployment_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"sigs.k8s.io/cluster-api/util/version"
)

func (m *MachineDeployment) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
func (m *MachineDeployment) SetupWebhookWithManager(mgr manager.Manager) error {
return builder.WebhookManagedBy(mgr).
For(m).
Complete()
}
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/machinehealthcheck_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

Expand All @@ -50,8 +51,8 @@ func SetMinNodeStartupTimeout(d metav1.Duration) {
minNodeStartupTimeout = d
}

func (m *MachineHealthCheck) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
func (m *MachineHealthCheck) SetupWebhookWithManager(mgr manager.Manager) error {
return builder.WebhookManagedBy(mgr).
For(m).
Complete()
}
Expand Down
7 changes: 4 additions & 3 deletions api/v1beta1/machineset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"sigs.k8s.io/cluster-api/util/version"
)

func (m *MachineSet) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
func (m *MachineSet) SetupWebhookWithManager(mgr manager.Manager) error {
return builder.WebhookManagedBy(mgr).
For(m).
Complete()
}
Expand Down
7 changes: 4 additions & 3 deletions bootstrap/kubeadm/api/v1beta1/kubeadmconfig_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"sigs.k8s.io/cluster-api/feature"
Expand All @@ -38,8 +39,8 @@ var (
pathConflictMsg = "path property must be unique among all files"
)

func (c *KubeadmConfig) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
func (c *KubeadmConfig) SetupWebhookWithManager(mgr manager.Manager) error {
return builder.WebhookManagedBy(mgr).
For(c).
Complete()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

func (r *KubeadmConfigTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
func (r *KubeadmConfigTemplate) SetupWebhookWithManager(mgr manager.Manager) error {
return builder.WebhookManagedBy(mgr).
For(r).
Complete()
}
Expand Down
7 changes: 4 additions & 3 deletions exp/addons/api/v1beta1/clusterresourceset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"sigs.k8s.io/cluster-api/feature"
)

func (m *ClusterResourceSet) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
func (m *ClusterResourceSet) SetupWebhookWithManager(mgr manager.Manager) error {
return builder.WebhookManagedBy(mgr).
For(m).
Complete()
}
Expand Down