diff --git a/controllers/apicast_controller.go b/controllers/apicast_controller.go index d33e89e9..8cca62a0 100644 --- a/controllers/apicast_controller.go +++ b/controllers/apicast_controller.go @@ -30,7 +30,6 @@ import ( autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" ) @@ -59,10 +58,9 @@ func (r *ApicastReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.Apicast{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -87,10 +85,9 @@ func (r *ApicastReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct } resources = append(resources, production...) - err = r.ReconcileOwnedResources(ctx, instance, resources) - if err != nil { - logger.Error(err, "unable to update owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, resources) + if result.IsReturnAndRequeue() { + return result.Values() } return ctrl.Result{}, nil diff --git a/controllers/autossl_controller.go b/controllers/autossl_controller.go index 04d4e4b2..4df2388c 100644 --- a/controllers/autossl_controller.go +++ b/controllers/autossl_controller.go @@ -30,7 +30,6 @@ import ( autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" ) @@ -58,10 +57,9 @@ func (r *AutoSSLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.AutoSSL{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -88,10 +86,9 @@ func (r *AutoSSLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct } resources = append(resources, workload...) - err = r.ReconcileOwnedResources(ctx, instance, resources) - if err != nil { - logger.Error(err, "unable to update owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, resources) + if result.IsReturnAndRequeue() { + return result.Values() } return ctrl.Result{}, nil diff --git a/controllers/backend_controller.go b/controllers/backend_controller.go index 2335b63c..f2693d2d 100644 --- a/controllers/backend_controller.go +++ b/controllers/backend_controller.go @@ -32,7 +32,6 @@ import ( corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/source" @@ -64,10 +63,9 @@ func (r *BackendReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.Backend{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -103,10 +101,9 @@ func (r *BackendReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct resources = append(resources, cron_resources...) // Reconcile all resources - err = r.ReconcileOwnedResources(ctx, instance, resources) - if err != nil { - logger.Error(err, "unable to reconcile owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, resources) + if result.IsReturnAndRequeue() { + return result.Values() } return ctrl.Result{}, nil diff --git a/controllers/corsproxy_controller.go b/controllers/corsproxy_controller.go index 47ce8331..88251f8f 100644 --- a/controllers/corsproxy_controller.go +++ b/controllers/corsproxy_controller.go @@ -32,7 +32,6 @@ import ( corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/source" @@ -63,10 +62,9 @@ func (r *CORSProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.CORSProxy{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -89,10 +87,9 @@ func (r *CORSProxyReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } resources = append(resources, workload...) - err = r.ReconcileOwnedResources(ctx, instance, resources) - if err != nil { - logger.Error(err, "unable to reconcile owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, resources) + if result.IsReturnAndRequeue() { + return result.Values() } return ctrl.Result{}, nil diff --git a/controllers/echoapi_controller.go b/controllers/echoapi_controller.go index c59015d6..79323b7b 100644 --- a/controllers/echoapi_controller.go +++ b/controllers/echoapi_controller.go @@ -30,7 +30,6 @@ import ( autoscalingv2 "k8s.io/api/autoscaling/v2" corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" ) @@ -58,10 +57,9 @@ func (r *EchoAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.EchoAPI{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -78,10 +76,9 @@ func (r *EchoAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct return ctrl.Result{}, err } - err = r.ReconcileOwnedResources(ctx, instance, resources) - if err != nil { - logger.Error(err, "unable to update owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, resources) + if result.IsReturnAndRequeue() { + return result.Values() } return ctrl.Result{}, nil diff --git a/controllers/mappingservice_controller.go b/controllers/mappingservice_controller.go index 2547bc3a..1d7bad79 100644 --- a/controllers/mappingservice_controller.go +++ b/controllers/mappingservice_controller.go @@ -32,7 +32,6 @@ import ( corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/source" @@ -63,10 +62,9 @@ func (r *MappingServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reque ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.MappingService{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -89,10 +87,9 @@ func (r *MappingServiceReconciler) Reconcile(ctx context.Context, req ctrl.Reque } resources = append(resources, workload...) - err = r.ReconcileOwnedResources(ctx, instance, resources) - if err != nil { - logger.Error(err, "unable to reconcile owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, resources) + if result.IsReturnAndRequeue() { + return result.Values() } return ctrl.Result{}, nil diff --git a/controllers/redisshard_controller.go b/controllers/redisshard_controller.go index 9b8709fb..25dbb2cf 100644 --- a/controllers/redisshard_controller.go +++ b/controllers/redisshard_controller.go @@ -21,7 +21,7 @@ import ( "fmt" "time" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/reconciler" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators/redisshard" "github.com/3scale/saas-operator/pkg/redis/client" @@ -38,7 +38,7 @@ import ( // RedisShardReconciler reconciles a RedisShard object type RedisShardReconciler struct { - basereconciler.Reconciler + *reconciler.Reconciler Log logr.Logger Pool *redis.ServerPool } @@ -57,10 +57,9 @@ func (r *RedisShardReconciler) Reconcile(ctx context.Context, req ctrl.Request) ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.RedisShard{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -72,19 +71,18 @@ func (r *RedisShardReconciler) Reconcile(ctx context.Context, req ctrl.Request) instance.Spec, ) - if err := r.ReconcileOwnedResources(ctx, instance, gen.Resources()); err != nil { - logger.Error(err, "unable to update owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, gen.Resources()) + if result.IsReturnAndRequeue() { + return result.Values() } - shard, result, err := r.setRedisRoles(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, + shard, result := r.setRedisRoles(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, *instance.Spec.MasterIndex, *instance.Spec.SlaveCount+1, gen.ServiceName(), logger) - - if result != nil || err != nil { - return *result, err + if result.IsReturnAndRequeue() { + return result.Values() } - if err = r.updateStatus(ctx, shard, instance, logger); err != nil { + if err := r.updateStatus(ctx, shard, instance, logger); err != nil { return ctrl.Result{}, err } @@ -101,7 +99,8 @@ func (r *RedisShardReconciler) SetupWithManager(mgr ctrl.Manager) error { Complete(r) } -func (r *RedisShardReconciler) setRedisRoles(ctx context.Context, key types.NamespacedName, masterIndex, replicas int32, serviceName string, log logr.Logger) (*sharded.Shard, *ctrl.Result, error) { +func (r *RedisShardReconciler) setRedisRoles(ctx context.Context, key types.NamespacedName, + masterIndex, replicas int32, serviceName string, log logr.Logger) (*sharded.Shard, reconciler.Result) { var masterHostPort string redisURLs := make(map[string]string, replicas) @@ -110,11 +109,12 @@ func (r *RedisShardReconciler) setRedisRoles(ctx context.Context, key types.Name key := types.NamespacedName{Name: fmt.Sprintf("%s-%d", serviceName, i), Namespace: key.Namespace} err := r.Client.Get(ctx, key, pod) if err != nil { - return &sharded.Shard{Name: key.Name}, &ctrl.Result{}, err + return &sharded.Shard{Name: key.Name}, reconciler.Result{Error: err} } if pod.Status.PodIP == "" { log.Info("waiting for pod IP to be allocated") - return &sharded.Shard{Name: key.Name}, &ctrl.Result{RequeueAfter: 5 * time.Second}, nil + // return &sharded.Shard{Name: key.Name}, &ctrl.Result{RequeueAfter: 5 * time.Second}, nil + return &sharded.Shard{Name: key.Name}, reconciler.Result{Requeue: true, RequeueAfter: 5 * time.Second} } redisURLs[fmt.Sprintf("%s-%d", serviceName, i)] = fmt.Sprintf("redis://%s:%d", pod.Status.PodIP, 6379) @@ -125,16 +125,16 @@ func (r *RedisShardReconciler) setRedisRoles(ctx context.Context, key types.Name shard, err := sharded.NewShardFromTopology(key.Name, redisURLs, r.Pool) if err != nil { - return shard, &ctrl.Result{}, err + return shard, reconciler.Result{Error: err} } _, err = shard.Init(ctx, masterHostPort) if err != nil { log.Info("waiting for redis shard init") - return shard, &ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second}, nil + return shard, reconciler.Result{Requeue: true, RequeueAfter: 10 * time.Second} } - return shard, nil, nil + return shard, reconciler.Result{} } func (r *RedisShardReconciler) updateStatus(ctx context.Context, shard *sharded.Shard, instance *saasv1alpha1.RedisShard, log logr.Logger) error { diff --git a/controllers/sentinel_controller.go b/controllers/sentinel_controller.go index cb2c6413..8c93441e 100644 --- a/controllers/sentinel_controller.go +++ b/controllers/sentinel_controller.go @@ -21,7 +21,7 @@ import ( "errors" "time" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/reconciler" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators/sentinel" "github.com/3scale/saas-operator/pkg/reconcilers/threads" @@ -36,7 +36,6 @@ import ( corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/util/workqueue" "k8s.io/utils/pointer" ctrl "sigs.k8s.io/controller-runtime" @@ -49,7 +48,7 @@ import ( // SentinelReconciler reconciles a Sentinel object type SentinelReconciler struct { - basereconciler.Reconciler + *reconciler.Reconciler Log logr.Logger SentinelEvents threads.Manager Metrics threads.Manager @@ -72,14 +71,13 @@ func (r *SentinelReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.Sentinel{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, - key, - instance, + result := r.GetInstance(ctx, req, instance, pointer.String(saasv1alpha1.Finalizer), - []func(){r.SentinelEvents.CleanupThreads(instance), r.Metrics.CleanupThreads(instance)}) - if result != nil || err != nil { - return *result, err + r.SentinelEvents.CleanupThreads(instance), + r.Metrics.CleanupThreads(instance), + ) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -91,9 +89,9 @@ func (r *SentinelReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c instance.Spec, ) - if err := r.ReconcileOwnedResources(ctx, instance, gen.Resources()); err != nil { - logger.Error(err, "unable to update owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, gen.Resources()) + if result.IsReturnAndRequeue() { + return result.Values() } clustermap, err := gen.ClusterTopology(ctx) diff --git a/controllers/shardedredisbackup_controller.go b/controllers/shardedredisbackup_controller.go index f47bb8ad..a7edb4bd 100644 --- a/controllers/shardedredisbackup_controller.go +++ b/controllers/shardedredisbackup_controller.go @@ -23,7 +23,6 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" "k8s.io/utils/pointer" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -32,7 +31,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/reconciler" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/reconcilers/threads" "github.com/3scale/saas-operator/pkg/redis/backup" @@ -45,7 +44,7 @@ import ( // ShardedRedisBackupReconciler reconciles a ShardedRedisBackup object type ShardedRedisBackupReconciler struct { - basereconciler.Reconciler + *reconciler.Reconciler Log logr.Logger BackupRunner threads.Manager Pool *redis.ServerPool @@ -74,10 +73,9 @@ func (r *ShardedRedisBackupReconciler) Reconcile(ctx context.Context, req ctrl.R // ---------------------------------- instance := &saasv1alpha1.ShardedRedisBackup{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, pointer.String(saasv1alpha1.Finalizer), []func(){r.BackupRunner.CleanupThreads(instance)}) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, pointer.String(saasv1alpha1.Finalizer), r.BackupRunner.CleanupThreads(instance)) + if result.IsReturnAndRequeue() { + return result.Values() } instance.Default() diff --git a/controllers/shardedredisbackup_controller_test.go b/controllers/shardedredisbackup_controller_test.go index 9305927b..f09fa39e 100644 --- a/controllers/shardedredisbackup_controller_test.go +++ b/controllers/shardedredisbackup_controller_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/reconciler" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/util" "github.com/go-logr/logr" @@ -161,7 +161,7 @@ func TestShardedRedisBackupReconciler_reconcileBackupList(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := &ShardedRedisBackupReconciler{ - Reconciler: basereconciler.Reconciler{}, + Reconciler: &reconciler.Reconciler{}, Log: logr.Discard(), } got, err := r.reconcileBackupList(context.TODO(), tt.args.instance, tt.args.nextRun, tt.args.shards) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 25c7c238..e2b093e7 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -24,7 +24,7 @@ import ( "testing" "time" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/reconciler" marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1" "github.com/3scale/saas-operator/pkg/reconcilers/threads" "github.com/3scale/saas-operator/pkg/reconcilers/workloads" @@ -158,14 +158,14 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(HaveOccurred()) err = (&RedisShardReconciler{ - Reconciler: basereconciler.NewFromManager(mgr), + Reconciler: reconciler.NewFromManager(mgr), Log: ctrl.Log.WithName("controllers").WithName("RedisShard"), Pool: redisPool, }).SetupWithManager(mgr) Expect(err).ToNot(HaveOccurred()) err = (&SentinelReconciler{ - Reconciler: basereconciler.NewFromManager(mgr), + Reconciler: reconciler.NewFromManager(mgr), SentinelEvents: threads.NewManager(), Metrics: threads.NewManager(), Pool: redisPool, diff --git a/controllers/system_controller.go b/controllers/system_controller.go index f6eca48f..74f6ed68 100644 --- a/controllers/system_controller.go +++ b/controllers/system_controller.go @@ -33,7 +33,6 @@ import ( corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/source" @@ -66,10 +65,9 @@ func (r *SystemReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.System{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -125,10 +123,9 @@ func (r *SystemReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr // Tekton resources resources = append(resources, gen.Pipelines()...) - err = r.ReconcileOwnedResources(ctx, instance, resources) - if err != nil { - logger.Error(err, "unable to update owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, resources) + if result.IsReturnAndRequeue() { + return result.Values() } return ctrl.Result{}, nil diff --git a/controllers/twemproxyconfig_controller.go b/controllers/twemproxyconfig_controller.go index 7e2b487f..5809b030 100644 --- a/controllers/twemproxyconfig_controller.go +++ b/controllers/twemproxyconfig_controller.go @@ -23,7 +23,7 @@ import ( "sync" "time" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/reconciler" "github.com/3scale-ops/basereconciler/resource" saasv1alpha1 "github.com/3scale/saas-operator/api/v1alpha1" "github.com/3scale/saas-operator/pkg/generators/twemproxyconfig" @@ -36,7 +36,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" apierrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/types" "k8s.io/utils/pointer" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -49,7 +48,7 @@ import ( // TwemproxyConfigReconciler reconciles a TwemproxyConfig object type TwemproxyConfigReconciler struct { - basereconciler.Reconciler + *reconciler.Reconciler Log logr.Logger SentinelEvents threads.Manager Pool *redis.ServerPool @@ -69,12 +68,12 @@ func (r *TwemproxyConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.TwemproxyConfig{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, + result := r.GetInstance(ctx, req, instance, pointer.String(saasv1alpha1.Finalizer), - []func(){r.SentinelEvents.CleanupThreads(instance)}) - if result != nil || err != nil { - return *result, err + r.SentinelEvents.CleanupThreads(instance), + ) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API diff --git a/controllers/zync_controller.go b/controllers/zync_controller.go index 37e4beb8..5cbfc9ba 100644 --- a/controllers/zync_controller.go +++ b/controllers/zync_controller.go @@ -31,7 +31,6 @@ import ( corev1 "k8s.io/api/core/v1" policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/source" @@ -62,10 +61,9 @@ func (r *ZyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. ctx = log.IntoContext(ctx, logger) instance := &saasv1alpha1.Zync{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } // Apply defaults for reconcile but do not store them in the API @@ -98,10 +96,9 @@ func (r *ZyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. resources = append(resources, gen.Console.StatefulSet()) // Reconcile all resources - err = r.ReconcileOwnedResources(ctx, instance, resources) - if err != nil { - logger.Error(err, "unable to reconcile owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, resources) + if result.IsReturnAndRequeue() { + return result.Values() } return ctrl.Result{}, nil diff --git a/main.go b/main.go index 8673084a..bfbcb193 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/reconciler" marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1" externalsecretsv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1" grafanav1alpha1 "github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1" @@ -132,7 +132,7 @@ func main() { redisPool := redis.NewServerPool() if err = (&controllers.SentinelReconciler{ - Reconciler: basereconciler.NewFromManager(mgr), + Reconciler: reconciler.NewFromManager(mgr), SentinelEvents: threads.NewManager(), Metrics: threads.NewManager(), Log: ctrl.Log.WithName("controllers").WithName("Sentinel"), @@ -142,7 +142,7 @@ func main() { os.Exit(1) } if err = (&controllers.RedisShardReconciler{ - Reconciler: basereconciler.NewFromManager(mgr), + Reconciler: reconciler.NewFromManager(mgr), Log: ctrl.Log.WithName("controllers").WithName("RedisShard"), Pool: redisPool, }).SetupWithManager(mgr); err != nil { @@ -150,7 +150,7 @@ func main() { os.Exit(1) } if err = (&controllers.TwemproxyConfigReconciler{ - Reconciler: basereconciler.NewFromManager(mgr), + Reconciler: reconciler.NewFromManager(mgr), SentinelEvents: threads.NewManager(), Log: ctrl.Log.WithName("controllers").WithName("TwemproxyConfig"), Pool: redisPool, @@ -160,7 +160,7 @@ func main() { } if err = (&controllers.ShardedRedisBackupReconciler{ - Reconciler: basereconciler.NewFromManager(mgr), + Reconciler: reconciler.NewFromManager(mgr), BackupRunner: threads.NewManager(), Log: ctrl.Log.WithName("controllers").WithName("ShardedRedisBackup"), Pool: redisPool, diff --git a/pkg/generators/apicast/generator.go b/pkg/generators/apicast/generator.go index 05e67f27..afe5f153 100644 --- a/pkg/generators/apicast/generator.go +++ b/pkg/generators/apicast/generator.go @@ -142,15 +142,13 @@ func (gen *Generator) Resources() []resource.TemplateInterface { resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( grafanadashboard.New( types.NamespacedName{Name: gen.Component, Namespace: gen.Namespace}, - gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/apicast.json.gtpl"), - !gen.GrafanaDashboardSpec.IsDeactivated(), - ), + gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/apicast.json.gtpl")). + WithEnabled(!gen.GrafanaDashboardSpec.IsDeactivated()), resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( grafanadashboard.New( types.NamespacedName{Name: gen.Component + "-services", Namespace: gen.Namespace}, - gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/apicast-services.json.gtpl"), - !gen.GrafanaDashboardSpec.IsDeactivated(), - ), + gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/apicast-services.json.gtpl")). + WithEnabled(!gen.GrafanaDashboardSpec.IsDeactivated()), } } @@ -176,10 +174,8 @@ func (gen *EnvGenerator) Labels() map[string]string { return gen.GetLabels() } func (gen *EnvGenerator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated())) } func (gen *EnvGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -196,8 +192,8 @@ func (gen *EnvGenerator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint } func (gen *EnvGenerator) Services() []*resource.Template[*corev1.Service] { return []*resource.Template[*corev1.Service]{ - resource.NewTemplateFromObjectFunction(gen.gatewayService, true, mutators.SetServiceLiveValues()), - resource.NewTemplateFromObjectFunction(gen.mgmtService, true, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.gatewayService).WithMutation(mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.mgmtService).WithMutation(mutators.SetServiceLiveValues()), } } func (gen *EnvGenerator) SendTraffic() bool { return gen.Traffic } diff --git a/pkg/generators/autossl/generator.go b/pkg/generators/autossl/generator.go index 462a206c..96474cf0 100644 --- a/pkg/generators/autossl/generator.go +++ b/pkg/generators/autossl/generator.go @@ -85,9 +85,8 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.AutoSSLSpec) (Ge func (gen *Generator) Services() []*resource.Template[*corev1.Service] { return []*resource.Template[*corev1.Service]{ - resource.NewTemplateFromObjectFunction( - gen.service, true, - mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.service). + WithMutation(mutators.SetServiceLiveValues()), } } func (gen *Generator) SendTraffic() bool { return gen.Traffic } @@ -101,10 +100,8 @@ func (gen *Generator) TrafficSelector() map[string]string { var _ workloads.DeploymentWorkload = &Generator{} func (gen *Generator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated())) } func (gen *Generator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -124,7 +121,6 @@ func (gen *Generator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint { // GrafanaDashboard returns a basereconciler_resources.GrafanaDashboardTemplate func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { return resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( - grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/autossl.json.gtpl"), - !gen.Spec.GrafanaDashboard.IsDeactivated(), - ) + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/autossl.json.gtpl")). + WithEnabled(!gen.Spec.GrafanaDashboard.IsDeactivated()) } diff --git a/pkg/generators/backend/generator.go b/pkg/generators/backend/generator.go index aed33b6f..8fd92353 100644 --- a/pkg/generators/backend/generator.go +++ b/pkg/generators/backend/generator.go @@ -167,28 +167,24 @@ func (gen *Generator) Resources() []resource.TemplateInterface { return []resource.TemplateInterface{ // GrafanaDashboard resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( - grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.grafanaDashboardSpec, "dashboards/backend.json.gtpl"), - !gen.grafanaDashboardSpec.IsDeactivated(), - ), + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.grafanaDashboardSpec, "dashboards/backend.json.gtpl")). + WithEnabled(!gen.grafanaDashboardSpec.IsDeactivated()), // ExternalSecrets resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( pod.GenerateExternalSecretFn("backend-system-events-hook", gen.GetNamespace(), *gen.config.ExternalSecret.SecretStoreRef.Name, *gen.config.ExternalSecret.SecretStoreRef.Kind, *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Worker.Options), - true, ), resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( pod.GenerateExternalSecretFn("backend-internal-api", gen.GetNamespace(), *gen.config.ExternalSecret.SecretStoreRef.Name, *gen.config.ExternalSecret.SecretStoreRef.Kind, *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Listener.Options), - true, ), resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( pod.GenerateExternalSecretFn("backend-error-monitoring", gen.GetNamespace(), *gen.config.ExternalSecret.SecretStoreRef.Name, *gen.config.ExternalSecret.SecretStoreRef.Kind, - *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Listener.Options), - gen.config.ErrorMonitoringKey != nil, - ), + *gen.config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Listener.Options)). + WithEnabled(gen.config.ErrorMonitoringKey != nil), } } @@ -216,12 +212,10 @@ func (gen *ListenerGenerator) Labels() map[string]string { return gen.GetLabels() } func (gen *ListenerGenerator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(gen.ListenerSpec.HPA.IsDeactivated()), - mutators.RolloutTrigger{Name: "backend-internal-api", SecretName: pointer.String("backend-internal-api")}.Add(), - mutators.RolloutTrigger{Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}.Add(), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(gen.ListenerSpec.HPA.IsDeactivated())). + WithMutation(mutators.RolloutTrigger{Name: "backend-internal-api", SecretName: pointer.String("backend-internal-api")}.Add()). + WithMutation(mutators.RolloutTrigger{Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}.Add()) } func (gen *ListenerGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -242,8 +236,8 @@ func (gen *ListenerGenerator) MonitoredEndpoints() []monitoringv1.PodMetricsEndp } func (gen *ListenerGenerator) Services() []*resource.Template[*corev1.Service] { return []*resource.Template[*corev1.Service]{ - resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), - resource.NewTemplateFromObjectFunction(gen.internalService, true, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.service).WithMutation(mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.internalService).WithMutation(mutators.SetServiceLiveValues()), } } func (gen *ListenerGenerator) SendTraffic() bool { return gen.Traffic } @@ -272,12 +266,10 @@ type WorkerGenerator struct { var _ workloads.DeploymentWorkload = &WorkerGenerator{} func (gen *WorkerGenerator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(gen.WorkerSpec.HPA.IsDeactivated()), - mutators.RolloutTrigger{Name: "backend-system-events-hook", SecretName: pointer.String("backend-system-events-hook")}.Add(), - mutators.RolloutTrigger{Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}.Add(), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(gen.WorkerSpec.HPA.IsDeactivated())). + WithMutation(mutators.RolloutTrigger{Name: "backend-system-events-hook", SecretName: pointer.String("backend-system-events-hook")}.Add()). + WithMutation(mutators.RolloutTrigger{Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}.Add()) } func (gen *WorkerGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { return gen.WorkerSpec.HPA @@ -308,11 +300,9 @@ type CronGenerator struct { var _ workloads.DeploymentWorkload = &CronGenerator{} func (gen *CronGenerator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(true), - mutators.RolloutTrigger{Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}.Add(), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(true)). + WithMutation(mutators.RolloutTrigger{Name: "backend-error-monitoring", SecretName: pointer.String("backend-error-monitoring")}.Add()) } func (gen *CronGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { return &saasv1alpha1.HorizontalPodAutoscalerSpec{} diff --git a/pkg/generators/corsproxy/generator.go b/pkg/generators/corsproxy/generator.go index 16b228ac..7b152ec5 100644 --- a/pkg/generators/corsproxy/generator.go +++ b/pkg/generators/corsproxy/generator.go @@ -58,7 +58,7 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.CORSProxySpec) G func (gen *Generator) Services() []*resource.Template[*corev1.Service] { return []*resource.Template[*corev1.Service]{ - resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.service).WithMutation(mutators.SetServiceLiveValues()), } } func (gen *Generator) SendTraffic() bool { return gen.Traffic } @@ -72,11 +72,9 @@ func (gen *Generator) TrafficSelector() map[string]string { var _ workloads.DeploymentWorkload = &Generator{} func (gen *Generator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), - mutators.RolloutTrigger{Name: "cors-proxy-system-database", SecretName: pointer.String("cors-proxy-system-database")}.Add(), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated())). + WithMutation(mutators.RolloutTrigger{Name: "cors-proxy-system-database", SecretName: pointer.String("cors-proxy-system-database")}.Add()) } func (gen *Generator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -95,16 +93,13 @@ func (gen *Generator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint { func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { return resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( - grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/cors-proxy.json.gtpl"), - !gen.Spec.GrafanaDashboard.IsDeactivated(), - ) + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/cors-proxy.json.gtpl")). + WithEnabled(!gen.Spec.GrafanaDashboard.IsDeactivated()) } func (gen *Generator) ExternalSecret() *resource.Template[*externalsecretsv1beta1.ExternalSecret] { return resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( pod.GenerateExternalSecretFn("cors-proxy-system-database", gen.GetNamespace(), *gen.Spec.Config.ExternalSecret.SecretStoreRef.Name, *gen.Spec.Config.ExternalSecret.SecretStoreRef.Kind, - *gen.Spec.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options), - true, - ) + *gen.Spec.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options)) } diff --git a/pkg/generators/echoapi/generator.go b/pkg/generators/echoapi/generator.go index 50a70e22..a44c631e 100644 --- a/pkg/generators/echoapi/generator.go +++ b/pkg/generators/echoapi/generator.go @@ -54,7 +54,7 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.EchoAPISpec) Gen func (gen *Generator) Services() []*resource.Template[*corev1.Service] { return []*resource.Template[*corev1.Service]{ - resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.service).WithMutation(mutators.SetServiceLiveValues()), } } func (gen *Generator) SendTraffic() bool { return gen.Traffic } @@ -65,10 +65,8 @@ func (gen *Generator) TrafficSelector() map[string]string { } func (gen *Generator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated())) } func (gen *Generator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { diff --git a/pkg/generators/mappingservice/generator.go b/pkg/generators/mappingservice/generator.go index 48140ac2..8fb56d92 100644 --- a/pkg/generators/mappingservice/generator.go +++ b/pkg/generators/mappingservice/generator.go @@ -58,7 +58,7 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.MappingServiceSp func (gen *Generator) Services() []*resource.Template[*corev1.Service] { return []*resource.Template[*corev1.Service]{ - resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.service).WithMutation(mutators.SetServiceLiveValues()), } } func (gen *Generator) SendTraffic() bool { return gen.Traffic } @@ -72,11 +72,9 @@ func (gen *Generator) TrafficSelector() map[string]string { var _ workloads.DeploymentWorkload = &Generator{} func (gen *Generator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()), - mutators.RolloutTrigger{Name: "mapping-service-system-master-access-token", SecretName: util.Pointer("mapping-service-system-master-access-token")}.Add(), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated())). + WithMutation(mutators.RolloutTrigger{Name: "mapping-service-system-master-access-token", SecretName: util.Pointer("mapping-service-system-master-access-token")}.Add()) } func (gen *Generator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -95,16 +93,13 @@ func (gen *Generator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint { func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { return resource.NewTemplate( - grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/mapping-service.json.gtpl"), - !gen.Spec.GrafanaDashboard.IsDeactivated(), - ) + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/mapping-service.json.gtpl")). + WithEnabled(!gen.Spec.GrafanaDashboard.IsDeactivated()) } func (gen *Generator) ExternalSecret() *resource.Template[*externalsecretsv1beta1.ExternalSecret] { return resource.NewTemplate( pod.GenerateExternalSecretFn("mapping-service-system-master-access-token", gen.GetNamespace(), *gen.Spec.Config.ExternalSecret.SecretStoreRef.Name, *gen.Spec.Config.ExternalSecret.SecretStoreRef.Kind, - *gen.Spec.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options), - true, - ) + *gen.Spec.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options)) } diff --git a/pkg/generators/redisshard/generator.go b/pkg/generators/redisshard/generator.go index 957e2c3f..95290768 100644 --- a/pkg/generators/redisshard/generator.go +++ b/pkg/generators/redisshard/generator.go @@ -56,9 +56,9 @@ func (gen *Generator) ServiceName() string { // Returns all the resource templates that this generator manages func (gen *Generator) Resources() []resource.TemplateInterface { return []resource.TemplateInterface{ - resource.NewTemplateFromObjectFunction[*appsv1.StatefulSet](gen.statefulSet, true), - resource.NewTemplateFromObjectFunction[*corev1.Service](gen.service, true), - resource.NewTemplateFromObjectFunction[*corev1.ConfigMap](gen.redisConfigConfigMap, true), - resource.NewTemplateFromObjectFunction[*corev1.ConfigMap](gen.redisReadinessScriptConfigMap, true), + resource.NewTemplateFromObjectFunction[*appsv1.StatefulSet](gen.statefulSet), + resource.NewTemplateFromObjectFunction[*corev1.Service](gen.service), + resource.NewTemplateFromObjectFunction[*corev1.ConfigMap](gen.redisConfigConfigMap), + resource.NewTemplateFromObjectFunction[*corev1.ConfigMap](gen.redisReadinessScriptConfigMap), } } diff --git a/pkg/generators/sentinel/generator.go b/pkg/generators/sentinel/generator.go index bd96e8c3..1e581410 100644 --- a/pkg/generators/sentinel/generator.go +++ b/pkg/generators/sentinel/generator.go @@ -52,21 +52,21 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.SentinelSpec) Ge // Returns all the resource templates that this generator manages func (gen *Generator) Resources() []resource.TemplateInterface { resources := []resource.TemplateInterface{ - resource.NewTemplateFromObjectFunction[*appsv1.StatefulSet](gen.statefulSet, true), - resource.NewTemplateFromObjectFunction[*corev1.Service](gen.statefulSetService, true, mutators.SetServiceLiveValues()), - resource.NewTemplate[*policyv1.PodDisruptionBudget](pdb.New(gen.GetKey(), gen.GetLabels(), gen.GetSelector(), *gen.Spec.PDB), true), - resource.NewTemplateFromObjectFunction[*corev1.ConfigMap](gen.configMap, true), - resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard](grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/redis-sentinel.json.gtpl"), - !gen.Spec.GrafanaDashboard.IsDeactivated()), + resource.NewTemplateFromObjectFunction[*appsv1.StatefulSet](gen.statefulSet), + resource.NewTemplateFromObjectFunction[*corev1.Service](gen.statefulSetService).WithMutation(mutators.SetServiceLiveValues()), + resource.NewTemplate[*policyv1.PodDisruptionBudget](pdb.New(gen.GetKey(), gen.GetLabels(), gen.GetSelector(), *gen.Spec.PDB)), + resource.NewTemplateFromObjectFunction[*corev1.ConfigMap](gen.configMap), + resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard](grafanadashboard.New(gen.GetKey(), gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/redis-sentinel.json.gtpl")). + WithEnabled(!gen.Spec.GrafanaDashboard.IsDeactivated()), } for idx := 0; idx < int(*gen.Spec.Replicas); idx++ { i := idx resources = append(resources, resource.NewTemplateFromObjectFunction( - func() *corev1.Service { return gen.podServices(i) }, true, - mutators.SetServiceLiveValues(), - )) + func() *corev1.Service { return gen.podServices(i) }). + WithMutation(mutators.SetServiceLiveValues()), + ) } return resources diff --git a/pkg/generators/system/generator.go b/pkg/generators/system/generator.go index 63a3af85..7ea2e093 100644 --- a/pkg/generators/system/generator.go +++ b/pkg/generators/system/generator.go @@ -315,9 +315,8 @@ func NewGenerator(instance, namespace string, spec saasv1alpha1.SystemSpec) (Gen // GrafanaDashboard returns a basereconciler.GeneratorFunction func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { return resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( - grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/system.json.gtpl"), - !gen.GrafanaDashboardSpec.IsDeactivated(), - ) + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/system.json.gtpl")). + WithEnabled(!gen.GrafanaDashboardSpec.IsDeactivated()) } func getSystemSecrets() []string { @@ -346,7 +345,6 @@ func (gen *Generator) ExternalSecrets() []resource.TemplateInterface { *gen.Config.ExternalSecret.SecretStoreRef.Name, *gen.Config.ExternalSecret.SecretStoreRef.Kind, *gen.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.Options, ), - true, ), ) } @@ -385,7 +383,8 @@ var _ workloads.WithTraffic = &AppGenerator{} func (gen *AppGenerator) Services() []*resource.Template[*corev1.Service] { return []*resource.Template[*corev1.Service]{ - resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.service). + WithMutation(mutators.SetServiceLiveValues()), } } func (gen *AppGenerator) SendTraffic() bool { return gen.Traffic } @@ -396,10 +395,9 @@ func (gen *AppGenerator) TrafficSelector() map[string]string { } func (gen *AppGenerator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - append(getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret), mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()))..., - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutations(getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret)). + WithMutation(mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated())) } func (gen *AppGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -434,10 +432,9 @@ type SidekiqGenerator struct { } func (gen *SidekiqGenerator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - append(getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret), mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated()))..., - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutations(getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret)). + WithMutation(mutators.SetDeploymentReplicas(gen.Spec.HPA.IsDeactivated())) } func (gen *SidekiqGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -472,8 +469,8 @@ type SearchdGenerator struct { func (gen *SearchdGenerator) StatefulSetWithTraffic() []resource.TemplateInterface { return []resource.TemplateInterface{ - resource.NewTemplateFromObjectFunction[*appsv1.StatefulSet](gen.statefulset, gen.Enabled), - resource.NewTemplateFromObjectFunction[*corev1.Service](gen.service, gen.Enabled, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction[*appsv1.StatefulSet](gen.statefulset).WithEnabled(gen.Enabled), + resource.NewTemplateFromObjectFunction[*corev1.Service](gen.service).WithEnabled(gen.Enabled).WithMutation(mutators.SetServiceLiveValues()), } } @@ -489,9 +486,9 @@ type ConsoleGenerator struct { } func (gen *ConsoleGenerator) StatefulSet() *resource.Template[*appsv1.StatefulSet] { - return resource.NewTemplateFromObjectFunction( - gen.statefulset, gen.Enabled, - getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret)...) + return resource.NewTemplateFromObjectFunction(gen.statefulset). + WithEnabled(gen.Enabled). + WithMutations(getSystemSecretsRolloutTriggers(gen.ConfigFilesSecret)) } // SystemTektonGenerator has methods to generate resources for system tekton tasks @@ -513,8 +510,8 @@ func (gen *Generator) Pipelines() []resource.TemplateInterface { for _, tr := range gen.Tekton { copy := tr resources = append(resources, - resource.NewTemplateFromObjectFunction[*pipelinev1beta1.Task](copy.task, copy.Enabled), - resource.NewTemplateFromObjectFunction[*pipelinev1beta1.Pipeline](copy.pipeline, copy.Enabled), + resource.NewTemplateFromObjectFunction[*pipelinev1beta1.Task](copy.task).WithEnabled(copy.Enabled), + resource.NewTemplateFromObjectFunction[*pipelinev1beta1.Pipeline](copy.pipeline).WithEnabled(copy.Enabled), ) } diff --git a/pkg/generators/twemproxyconfig/generator.go b/pkg/generators/twemproxyconfig/generator.go index 93603926..124dc51e 100644 --- a/pkg/generators/twemproxyconfig/generator.go +++ b/pkg/generators/twemproxyconfig/generator.go @@ -217,13 +217,12 @@ func (gen *Generator) getMonitoredReadWriteSlavesWithFallbackToMasters(ctx conte // Returns the twemproxy config ConfigMap func (gen *Generator) ConfigMap() *resource.Template[*corev1.ConfigMap] { - return resource.NewTemplateFromObjectFunction(func() *corev1.ConfigMap { return gen.configMap(true) }, true) + return resource.NewTemplateFromObjectFunction(func() *corev1.ConfigMap { return gen.configMap(true) }) } func (gen *Generator) GrafanaDashboard() *resource.Template[*grafanav1alpha1.GrafanaDashboard] { return resource.NewTemplate( grafanadashboard.New(types.NamespacedName{Name: fmt.Sprintf("%s-%s", gen.InstanceName, gen.Component), Namespace: gen.Namespace}, - gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/twemproxy.json.gtpl"), - !gen.Spec.GrafanaDashboard.IsDeactivated(), - ) + gen.GetLabels(), *gen.Spec.GrafanaDashboard, "dashboards/twemproxy.json.gtpl")). + WithEnabled(!gen.Spec.GrafanaDashboard.IsDeactivated()) } diff --git a/pkg/generators/zync/generator.go b/pkg/generators/zync/generator.go index 3c99838c..26ff55f5 100644 --- a/pkg/generators/zync/generator.go +++ b/pkg/generators/zync/generator.go @@ -107,15 +107,13 @@ func (gen *Generator) Resources() []resource.TemplateInterface { return []resource.TemplateInterface{ // GrafanaDashboard resource.NewTemplate[*grafanav1alpha1.GrafanaDashboard]( - grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/zync.json.gtpl"), - !gen.GrafanaDashboardSpec.IsDeactivated(), - ), + grafanadashboard.New(gen.GetKey(), gen.GetLabels(), gen.GrafanaDashboardSpec, "dashboards/zync.json.gtpl")). + WithEnabled(!gen.GrafanaDashboardSpec.IsDeactivated()), // ExternalSecret resource.NewTemplate[*externalsecretsv1beta1.ExternalSecret]( pod.GenerateExternalSecretFn("zync", gen.GetNamespace(), *gen.Config.ExternalSecret.SecretStoreRef.Name, *gen.Config.ExternalSecret.SecretStoreRef.Kind, *gen.Config.ExternalSecret.RefreshInterval, gen.GetLabels(), gen.API.Options), - true, ), } } @@ -140,11 +138,9 @@ func (gen *APIGenerator) Labels() map[string]string { return gen.GetLabels() } func (gen *APIGenerator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(gen.APISpec.HPA.IsDeactivated()), - mutators.RolloutTrigger{Name: "zync", SecretName: util.Pointer("zync")}.Add(), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(gen.APISpec.HPA.IsDeactivated())). + WithMutation(mutators.RolloutTrigger{Name: "zync", SecretName: util.Pointer("zync")}.Add()) } func (gen *APIGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { @@ -160,7 +156,7 @@ func (gen *APIGenerator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint } func (gen *APIGenerator) Services() []*resource.Template[*corev1.Service] { return []*resource.Template[*corev1.Service]{ - resource.NewTemplateFromObjectFunction(gen.service, true, mutators.SetServiceLiveValues()), + resource.NewTemplateFromObjectFunction(gen.service).WithMutation(mutators.SetServiceLiveValues()), } } func (gen *APIGenerator) SendTraffic() bool { return gen.Traffic } @@ -183,11 +179,9 @@ type QueGenerator struct { var _ workloads.DeploymentWorkload = &QueGenerator{} func (gen *QueGenerator) Deployment() *resource.Template[*appsv1.Deployment] { - return resource.NewTemplateFromObjectFunction( - gen.deployment, true, - mutators.SetDeploymentReplicas(gen.QueSpec.HPA.IsDeactivated()), - mutators.RolloutTrigger{Name: "zync", SecretName: pointer.String("zync")}.Add(), - ) + return resource.NewTemplateFromObjectFunction(gen.deployment). + WithMutation(mutators.SetDeploymentReplicas(gen.QueSpec.HPA.IsDeactivated())). + WithMutation(mutators.RolloutTrigger{Name: "zync", SecretName: pointer.String("zync")}.Add()) } func (gen *QueGenerator) HPASpec() *saasv1alpha1.HorizontalPodAutoscalerSpec { return gen.QueSpec.HPA @@ -211,9 +205,7 @@ type ConsoleGenerator struct { } func (gen *ConsoleGenerator) StatefulSet() *resource.Template[*appsv1.StatefulSet] { - return resource.NewTemplateFromObjectFunction( - gen.statefulset, gen.Enabled, - mutators.SetDeploymentReplicas(true), - mutators.RolloutTrigger{Name: "zync", SecretName: pointer.String("zync")}.Add(), - ) + return resource.NewTemplateFromObjectFunction(gen.statefulset). + WithMutation(mutators.SetDeploymentReplicas(true)). + WithMutation(mutators.RolloutTrigger{Name: "zync", SecretName: pointer.String("zync")}.Add()) } diff --git a/pkg/reconcilers/workloads/deployment_based_workload.go b/pkg/reconcilers/workloads/deployment_based_workload.go index a499cabd..27decf19 100644 --- a/pkg/reconcilers/workloads/deployment_based_workload.go +++ b/pkg/reconcilers/workloads/deployment_based_workload.go @@ -3,7 +3,7 @@ package workloads import ( "reflect" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/reconciler" "github.com/3scale-ops/basereconciler/resource" marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1" "github.com/3scale/saas-operator/pkg/resource_builders/envoyconfig" @@ -24,13 +24,13 @@ import ( ) type WorkloadReconciler struct { - basereconciler.Reconciler + *reconciler.Reconciler } // NewFromManager constructs a new Reconciler from the given manager func NewFromManager(mgr manager.Manager) WorkloadReconciler { return WorkloadReconciler{ - Reconciler: basereconciler.NewFromManager(mgr), + Reconciler: reconciler.NewFromManager(mgr), } } @@ -72,17 +72,20 @@ func workloadResources(workload DeploymentWorkload) []resource.TemplateInterface Apply(trafficSelectorToDeployment(workload)), resource.NewTemplate[*policyv1.PodDisruptionBudget]( - pdb.New(EmptyKey, EmptyLabel, EmptySelector, *workload.PDBSpec()), !workload.PDBSpec().IsDeactivated()). + pdb.New(EmptyKey, EmptyLabel, EmptySelector, *workload.PDBSpec())). + WithEnabled(!workload.PDBSpec().IsDeactivated()). Apply(meta[*policyv1.PodDisruptionBudget](workload)). Apply(selector[*policyv1.PodDisruptionBudget](workload)), resource.NewTemplate[*autoscalingv2.HorizontalPodAutoscaler]( - hpa.New(EmptyKey, EmptyLabel, *workload.HPASpec()), !workload.HPASpec().IsDeactivated()). + hpa.New(EmptyKey, EmptyLabel, *workload.HPASpec())). + WithEnabled(!workload.HPASpec().IsDeactivated()). Apply(meta[*autoscalingv2.HorizontalPodAutoscaler](workload)). Apply(scaleTargetRefToHPA(workload)), resource.NewTemplate[*monitoringv1.PodMonitor]( - podmonitor.New(EmptyKey, EmptyLabel, EmptySelector, workload.MonitoredEndpoints()...), len(workload.MonitoredEndpoints()) > 0). + podmonitor.New(EmptyKey, EmptyLabel, EmptySelector, workload.MonitoredEndpoints()...)). + WithEnabled(len(workload.MonitoredEndpoints()) > 0). Apply(meta[*monitoringv1.PodMonitor](workload)). Apply(selector[*monitoringv1.PodMonitor](workload)), } @@ -91,7 +94,8 @@ func workloadResources(workload DeploymentWorkload) []resource.TemplateInterface if w, ok := workload.(WithEnvoySidecar); ok { resources = append(resources, resource.NewTemplate[*marin3rv1alpha1.EnvoyConfig]( - envoyconfig.New(EmptyKey, EmptyKey.Name, factory.Default(), w.EnvoyDynamicConfigurations()...), len(w.EnvoyDynamicConfigurations()) > 0). + envoyconfig.New(EmptyKey, EmptyKey.Name, factory.Default(), w.EnvoyDynamicConfigurations()...)). + WithEnabled(len(w.EnvoyDynamicConfigurations()) > 0). Apply(meta[*marin3rv1alpha1.EnvoyConfig](w)). Apply(nodeIdToEnvoyConfig(w)), ) diff --git a/pkg/reconcilers/workloads/deployment_based_workload_test.go b/pkg/reconcilers/workloads/deployment_based_workload_test.go index 14d908b8..5fc46e8c 100644 --- a/pkg/reconcilers/workloads/deployment_based_workload_test.go +++ b/pkg/reconcilers/workloads/deployment_based_workload_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/3scale-ops/basereconciler/mutators" - basereconciler "github.com/3scale-ops/basereconciler/reconciler" + "github.com/3scale-ops/basereconciler/reconciler" "github.com/3scale-ops/basereconciler/resource" reconcilerutil "github.com/3scale-ops/basereconciler/util" marin3rv1alpha1 "github.com/3scale-ops/marin3r/apis/marin3r/v1alpha1" @@ -264,7 +264,7 @@ func TestWorkloadReconciler_NewDeploymentWorkload(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := &WorkloadReconciler{ - Reconciler: basereconciler.Reconciler{ + Reconciler: &reconciler.Reconciler{ Client: tt.fields.Client, Scheme: tt.fields.Scheme, }, @@ -301,9 +301,7 @@ func Test_applyTrafficSelectorToDeployment(t *testing.T) { template: resource.NewTemplate[*appsv1.Deployment]( func(client.Object) (*appsv1.Deployment, error) { return &appsv1.Deployment{}, nil - }, - false, - ), + }), args: args{ w: &TestWorkloadGenerator{ TTrafficSelector: map[string]string{"tskey": "tsvalue"}, @@ -345,9 +343,7 @@ func Test_applyHPAScaleTargetRef(t *testing.T) { template: resource.NewTemplate[*autoscalingv2.HorizontalPodAutoscaler]( func(client.Object) (*autoscalingv2.HorizontalPodAutoscaler, error) { return &autoscalingv2.HorizontalPodAutoscaler{}, nil - }, - false, - ), + }), args: args{ w: &TestWorkloadGenerator{ TName: "test", @@ -392,7 +388,6 @@ func Test_applyMeta(t *testing.T) { name: "Adds meta to a ConfigMap", template: resource.NewTemplate[*corev1.ConfigMap]( func(client.Object) (*corev1.ConfigMap, error) { return &corev1.ConfigMap{}, nil }, - false, ), args: args{ w: &TestWorkloadGenerator{ @@ -417,7 +412,6 @@ func Test_applyMeta(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"okey": "ovalue"}}, }, nil }, - false, ), args: args{ w: &TestWorkloadGenerator{ @@ -458,7 +452,6 @@ func Test_applyMeta(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "my-service"}, }, nil }, - false, ), args: args{ w: &TestWorkloadGenerator{ @@ -502,7 +495,6 @@ func Test_applyTrafficSelectorToService(t *testing.T) { name: "Applies pod selector to Service (traffic to w1)", template: resource.NewTemplate[*corev1.Service]( func(client.Object) (*corev1.Service, error) { return &corev1.Service{}, nil }, - true, ), args: args{ main: &TestWorkloadGenerator{ @@ -626,7 +618,6 @@ func Test_applyNodeIdToEnvoyConfig(t *testing.T) { func(client.Object) (*marin3rv1alpha1.EnvoyConfig, error) { return &marin3rv1alpha1.EnvoyConfig{}, nil }, - false, ), args: args{ w: &TestWorkloadGenerator{ diff --git a/pkg/reconcilers/workloads/test/test_controller.go b/pkg/reconcilers/workloads/test/test_controller.go index dab69bb0..c3d1b049 100644 --- a/pkg/reconcilers/workloads/test/test_controller.go +++ b/pkg/reconcilers/workloads/test/test_controller.go @@ -63,10 +63,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu ctx = log.IntoContext(ctx, logger) instance := &v1alpha1.Test{} - key := types.NamespacedName{Name: req.Name, Namespace: req.Namespace} - result, err := r.GetInstance(ctx, key, instance, nil, nil) - if result != nil || err != nil { - return *result, err + result := r.GetInstance(ctx, req, instance, nil, nil) + if result.IsReturnAndRequeue() { + return result.Values() } main := &TestWorkloadGenerator{ @@ -93,10 +92,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } // Reconcile all resources - err = r.ReconcileOwnedResources(ctx, instance, deployments) - if err != nil { - logger.Error(err, "unable to reconcile owned resources") - return ctrl.Result{}, err + result = r.ReconcileOwnedResources(ctx, instance, deployments) + if result.IsReturnAndRequeue() { + return result.Values() } return ctrl.Result{}, nil @@ -145,7 +143,6 @@ func (gen *TestWorkloadGenerator) Services() []*resource.Template[*corev1.Servic }, }, nil }, - true, ), } } @@ -176,14 +173,9 @@ func (gen *TestWorkloadGenerator) Deployment() *resource.Template[*appsv1.Deploy }, }, }, nil - }, - true, - mutators.RolloutTrigger{ - Name: "secret", - SecretName: pointer.String("secret"), - }.Add(), - mutators.SetDeploymentReplicas(true), - ) + }). + WithMutation(mutators.RolloutTrigger{Name: "secret", SecretName: pointer.String("secret")}.Add()). + WithMutation(mutators.SetDeploymentReplicas(true)) } func (gen *TestWorkloadGenerator) MonitoredEndpoints() []monitoringv1.PodMetricsEndpoint { return nil }