Skip to content

Commit

Permalink
add missing resources in deployer update
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Mange <[email protected]>
  • Loading branch information
thibaultmg committed Jun 3, 2024
1 parent ec27fc7 commit c564d63
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions operators/pkg/deploying/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c564d63

Please sign in to comment.