Merge pull request #3292 from tsatam/ARO-4632/operator-predicates

ARO Operator - Reduce unnecessary reconciles by limiting watched resources/changes
This commit is contained in:
Maitiú Ó Ciaráin 2024-07-09 15:43:21 +02:00 коммит произвёл GitHub
Родитель 10e5de36b5 08bf84c329
Коммит ff69ffef6a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
23 изменённых файлов: 111 добавлений и 156 удалений

Просмотреть файл

@ -6,7 +6,6 @@ package autosizednodes
import (
"context"
"fmt"
"strings"
"github.com/Azure/go-autorest/autorest/to"
mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
@ -21,6 +20,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
)
type Reconciler struct {
@ -101,19 +101,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager prepares the controller with info who to watch
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
clusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
name := o.GetName()
return strings.EqualFold(arov1alpha1.SingletonClusterName, name)
})
b := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(clusterPredicate))
// Controller adds ControllerManagedBy to KubeletConfit created by this controller.
// Any changes will trigger reconcile, but only for that config.
return b.
Named(ControllerName).
// Controller adds ControllerManagedBy to KubeletConfit created by this controller.
// Any changes will trigger reconcile, but only for that config.
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Owns(&mcv1.KubeletConfig{}).
Named(ControllerName).
Complete(r)
}

Просмотреть файл

@ -19,6 +19,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
)
const (
@ -59,16 +60,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager creates the controller
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
aroBannerPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == BannerName
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
// watching ConsoleNotifications in case a user edits it
Watches(&source.Kind{Type: &consolev1.ConsoleNotification{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(aroBannerPredicate)).
Named(ControllerName).

Просмотреть файл

@ -20,6 +20,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/conditions"
)
@ -117,16 +118,12 @@ func (r *Reconciler) condition(checkErr error, result result) *operatorv1.Operat
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
defaultClusterDNSPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == "default"
})
builder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &operatorv1.DNS{}},
&handler.EnqueueRequestForObject{},

Просмотреть файл

@ -22,6 +22,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/conditions"
)
@ -118,20 +119,12 @@ func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
defaultIngressControllerPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetNamespace() == "openshift-ingress-operator" && o.GetName() == "default"
})
clusterVersionPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == "version"
})
builder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &operatorv1.IngressController{}},
&handler.EnqueueRequestForObject{},
@ -140,7 +133,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
Watches(
&source.Kind{Type: &configv1.ClusterVersion{}},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(clusterVersionPredicate),
builder.WithPredicates(predicates.ClusterVersion),
)
return builder.Named(ControllerName).Complete(r)

Просмотреть файл

@ -18,6 +18,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/conditions"
)
@ -122,12 +123,8 @@ func (r *Reconciler) conditionType() string {
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
builder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate))
return builder.Named(ControllerName).Complete(r)
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Named(ControllerName).
Complete(r)
}

Просмотреть файл

@ -21,6 +21,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/clusterauthorizer"
"github.com/Azure/ARO-RP/pkg/util/conditions"
)
@ -114,16 +115,12 @@ func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
clusterSPPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == clusterauthorizer.AzureCredentialSecretName && o.GetNamespace() == clusterauthorizer.AzureCredentialSecretNameSpace
})
builder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&handler.EnqueueRequestForObject{},

Просмотреть файл

@ -23,6 +23,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/controllers/base"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
)
const (
@ -164,16 +165,12 @@ func (r *CloudProviderConfigReconciler) Reconcile(ctx context.Context, request c
func (r *CloudProviderConfigReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.Log.Info("starting cloud-provider-config controller")
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
cloudProviderConfigPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == cloudProviderConfigName.Name && o.GetNamespace() == cloudProviderConfigName.Namespace
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &corev1.ConfigMap{}},
&handler.EnqueueRequestForObject{},

Просмотреть файл

@ -21,10 +21,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/version"
)
@ -163,12 +163,9 @@ func (r *Reconciler) defaultOperator() *configv1.ClusterOperator {
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
// we want to reconcile on status changes on the ARO Cluster resource here, unlike most other reconcilers
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicates.AROCluster)).
Owns(&configv1.ClusterOperator{}).
Named(ControllerName).
Complete(r)

Просмотреть файл

@ -18,6 +18,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/controllers/base"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
)
@ -81,12 +82,8 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, request ctrl.Request)
// SetupWithManager setup our mananger
func (r *ClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Named(ClusterControllerName).
Complete(r)
}

Просмотреть файл

@ -20,6 +20,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/controllers/base"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
)
@ -111,12 +112,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Owns(&appsv1.DaemonSet{}).
Owns(&corev1.ConfigMap{}).
Owns(&corev1.Namespace{}).

Просмотреть файл

@ -22,6 +22,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/controllers/guardrails/config"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/deployer"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
)
@ -167,12 +168,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
grBuilder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate))
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{})))
resources, err := r.deployer.Template(&config.GuardRailsDeploymentConfig{}, staticFiles)
if err != nil {

Просмотреть файл

@ -19,6 +19,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/controllers/base"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
)
const (
@ -80,12 +81,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager setup the mananger for openshift ingress controller resource
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
builder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate))
return builder.Named(ControllerName).Complete(r)
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Named(ControllerName).
Complete(r)
}

Просмотреть файл

@ -6,7 +6,6 @@ package machinehealthcheck
import (
"context"
_ "embed"
"strings"
"time"
configv1 "github.com/openshift/api/config/v1"
@ -27,6 +26,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/controllers/base"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
)
@ -166,22 +166,15 @@ func (r *Reconciler) isClusterUpgrading(ctx context.Context) (bool, error) {
// SetupWithManager will manage only our MHC resource with our specific controller name
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return strings.EqualFold(arov1alpha1.SingletonClusterName, o.GetName())
})
clusterVersionPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == "version"
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Named(ControllerName).
Owns(&machinev1beta1.MachineHealthCheck{}).
Owns(&monitoringv1.PrometheusRule{}).
Watches(
&source.Kind{Type: &configv1.ClusterVersion{}},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(clusterVersionPredicate),
builder.WithPredicates(predicates.ClusterVersion),
).
Complete(r)
}

Просмотреть файл

@ -15,11 +15,11 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"github.com/Azure/ARO-RP/pkg/operator"
"github.com/Azure/ARO-RP/pkg/operator/controllers/base"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
)
const (
@ -108,13 +108,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
machineSetPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
role := o.GetLabels()["machine.openshift.io/cluster-api-machine-role"]
return strings.EqualFold("worker", role)
})
return ctrl.NewControllerManagedBy(mgr).
For(&machinev1beta1.MachineSet{}, builder.WithPredicates(machineSetPredicate)).
For(&machinev1beta1.MachineSet{}, builder.WithPredicates(predicates.MachineRoleWorker)).
Named(ControllerName).
Complete(r)
}

Просмотреть файл

@ -27,6 +27,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/controllers/base"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
)
const (
@ -205,16 +206,12 @@ func (r *MonitoringReconciler) monitoringConfigMap(ctx context.Context) (*corev1
func (r *MonitoringReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.Log.Info("starting cluster monitoring controller")
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
monitoringConfigMapPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == monitoringName.Name && o.GetNamespace() == monitoringName.Namespace
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
// https://github.com/kubernetes-sigs/controller-runtime/issues/1173
// equivalent to For(&v1.ConfigMap{}, ...)., but can't call For multiple times on one builder
Watches(

Просмотреть файл

@ -25,6 +25,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/controllers/muo/config"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/deployer"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
@ -170,20 +171,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
pullSecretPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return (o.GetName() == pullSecretName.Name && o.GetNamespace() == pullSecretName.Namespace)
})
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
muoBuilder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(pullSecretPredicate),
builder.WithPredicates(predicates.PullSecret),
)
resources, err := r.deployer.Template(&config.MUODeploymentConfig{}, staticFiles)

Просмотреть файл

@ -30,6 +30,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
)
@ -112,23 +113,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
pullSecretPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return (o.GetName() == pullSecretName.Name && o.GetNamespace() == pullSecretName.Namespace) ||
(o.GetName() == operator.SecretName && o.GetNamespace() == operator.Namespace)
})
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
// https://github.com/kubernetes-sigs/controller-runtime/issues/1173
// equivalent to For(&v1.Secret{})., but can't call For multiple times on one builder
Watches(
&source.Kind{Type: &corev1.Secret{}},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(pullSecretPredicate),
builder.WithPredicates(predicate.Or(predicates.PullSecret, predicates.BackupPullSecret)),
).
Named(ControllerName).
Complete(r)

Просмотреть файл

@ -19,6 +19,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
)
@ -95,12 +96,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager setup our mananger
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Owns(&rbacv1.ClusterRole{}).
Owns(&rbacv1.ClusterRoleBinding{}).
Named(ControllerName).

Просмотреть файл

@ -23,6 +23,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
"github.com/Azure/ARO-RP/pkg/util/version"
)
@ -153,12 +154,8 @@ func (r *Reconciler) remove(ctx context.Context, instance *arov1alpha1.Cluster)
// SetupWithManager creates the controller
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Owns(&corev1.Namespace{}).
Owns(&appsv1.DaemonSet{}).
Owns(&securityv1.SecurityContextConstraints{}).

Просмотреть файл

@ -20,6 +20,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/azureclient"
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/storage"
"github.com/Azure/ARO-RP/pkg/util/clusterauthorizer"
@ -111,18 +112,10 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager creates the controller
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
masterMachinePredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
role, ok := o.GetLabels()["machine.openshift.io/cluster-api-machine-role"]
return ok && role == "master"
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
Watches(&source.Kind{Type: &machinev1beta1.Machine{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(masterMachinePredicate)). // to reconcile on master machine replacement
Watches(&source.Kind{Type: &machinev1beta1.MachineSet{}}, &handler.EnqueueRequestForObject{}). // to reconcile on worker machinesets
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(&source.Kind{Type: &machinev1beta1.Machine{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleMaster)). // to reconcile on master machine replacement
Watches(&source.Kind{Type: &machinev1beta1.MachineSet{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleWorker)). // to reconcile on worker machines
Named(ControllerName).
Complete(r)
}

Просмотреть файл

@ -22,6 +22,7 @@ import (
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/azureclient"
"github.com/Azure/ARO-RP/pkg/util/clusterauthorizer"
"github.com/Azure/ARO-RP/pkg/util/subnet"
@ -149,18 +150,10 @@ func (r *reconcileManager) reconcileSubnets(ctx context.Context) error {
// SetupWithManager creates the controller
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
aroClusterPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == arov1alpha1.SingletonClusterName
})
masterMachinePredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
role, ok := o.GetLabels()["machine.openshift.io/cluster-api-machine-role"]
return ok && role == "master"
})
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(aroClusterPredicate)).
Watches(&source.Kind{Type: &machinev1beta1.Machine{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(masterMachinePredicate)). // to reconcile on master machine replacement
Watches(&source.Kind{Type: &machinev1beta1.MachineSet{}}, &handler.EnqueueRequestForObject{}). // to reconcile on worker machinesets
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(&source.Kind{Type: &machinev1beta1.Machine{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleMaster)). // to reconcile on master machine replacement
Watches(&source.Kind{Type: &machinev1beta1.MachineSet{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleWorker)). // to reconcile on worker machines
Named(ControllerName).
Complete(r)
}

Просмотреть файл

@ -11,11 +11,16 @@ import (
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/operator/predicates"
"github.com/Azure/ARO-RP/pkg/util/version"
)
@ -86,7 +91,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
// SetupWithManager setup our manager
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(&source.Kind{Type: &configv1.ClusterVersion{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.ClusterVersion)).
Named(ControllerName).
Complete(r)
}

Просмотреть файл

@ -0,0 +1,43 @@
package predicates
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"strings"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
)
var AROCluster predicate.Predicate = predicate.NewPredicateFuncs(func(o client.Object) bool {
return strings.EqualFold(arov1alpha1.SingletonClusterName, o.GetName())
})
var MachineRoleMaster predicate.Predicate = predicate.NewPredicateFuncs(func(o client.Object) bool {
role, ok := o.GetLabels()["machine.openshift.io/cluster-api-machine-role"]
return ok && strings.EqualFold("master", role)
})
var MachineRoleWorker predicate.Predicate = predicate.NewPredicateFuncs(func(o client.Object) bool {
role, ok := o.GetLabels()["machine.openshift.io/cluster-api-machine-role"]
return ok && strings.EqualFold("worker", role)
})
var ClusterVersion predicate.Predicate = predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.GetName() == "version"
})
var pullSecretName = types.NamespacedName{Name: "pull-secret", Namespace: "openshift-config"}
var PullSecret predicate.Predicate = predicate.NewPredicateFuncs(func(o client.Object) bool {
return (o.GetName() == pullSecretName.Name && o.GetNamespace() == pullSecretName.Namespace)
})
var backupPullSecretName = types.NamespacedName{Name: operator.SecretName, Namespace: operator.Namespace}
var BackupPullSecret predicate.Predicate = predicate.NewPredicateFuncs(func(o client.Object) bool {
return (o.GetName() == backupPullSecretName.Name && o.GetNamespace() == backupPullSecretName.Namespace)
})