From c564d63be903440077e30f056f9ccdc9e94fa961 Mon Sep 17 00:00:00 2001 From: Thibault Mange <22740367+thibaultmg@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:27:47 +0200 Subject: [PATCH] add missing resources in deployer update Signed-off-by: Thibault Mange <22740367+thibaultmg@users.noreply.github.com> --- operators/pkg/deploying/deployer.go | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/operators/pkg/deploying/deployer.go b/operators/pkg/deploying/deployer.go index cae21c8671..60ac806735 100644 --- a/operators/pkg/deploying/deployer.go +++ b/operators/pkg/deploying/deployer.go @@ -12,6 +12,7 @@ import ( prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" appsv1 "k8s.io/api/apps/v1" + batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -56,6 +57,8 @@ func NewDeployer(client client.Client) *Deployer { "ServiceAccount": deployer.updateServiceAccount, "DaemonSet": deployer.updateDaemonSet, "ServiceMonitor": deployer.updateServiceMonitor, + "Endpoints": deployer.updateEndpoints, + "CronJob": deployer.updateCronJob, } return deployer } @@ -363,6 +366,34 @@ func (d *Deployer) updateServiceMonitor(ctx context.Context, desiredObj, runtime return nil } +func (d *Deployer) updateEndpoints(ctx context.Context, desiredObj, runtimeObj *unstructured.Unstructured) error { + desiredEndpoints, runtimeEndpoints, err := unstructuredPairToTyped[corev1.Endpoints](desiredObj, runtimeObj) + if err != nil { + return err + } + + if !apiequality.Semantic.DeepDerivative(desiredEndpoints.Subsets, runtimeEndpoints.Subsets) { + logUpdateInfo(runtimeObj) + return d.client.Update(ctx, desiredEndpoints) + } + + return nil +} + +func (d *Deployer) updateCronJob(ctx context.Context, desiredObj, runtimeObj *unstructured.Unstructured) error { + desiredCronJob, runtimeCronJob, err := unstructuredPairToTyped[batchv1.CronJob](desiredObj, runtimeObj) + if err != nil { + return err + } + + if !apiequality.Semantic.DeepDerivative(desiredCronJob.Spec, runtimeCronJob.Spec) { + logUpdateInfo(runtimeObj) + return d.client.Update(ctx, desiredCronJob) + } + + return nil +} + // unstructuredToType converts an unstructured.Unstructured object to a specified type. // It marshals the object to JSON and then unmarshals it into the target type. // The target parameter must be a pointer to the type T.