Skip to content

Commit

Permalink
use deep equal
Browse files Browse the repository at this point in the history
Signed-off-by: Coleen Iona Quadros <[email protected]>
  • Loading branch information
coleenquadros committed Nov 12, 2024
1 parent cef6b04 commit f3ecbf6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/ghodss/yaml"
cmomanifests "github.com/openshift/cluster-monitoring-operator/pkg/manifests"
operatorconfig "github.com/stolostron/multicluster-observability-operator/operators/pkg/config"
)
Expand Down Expand Up @@ -423,7 +422,7 @@ func createOrUpdateClusterMonitoringConfig(
newCMOCfg.PrometheusK8sConfig = newPmK8sConfig
}

if equality.Semantic.DeepEqual(*foundClusterMonitoringConfiguration, *newCMOCfg) {
if equality.Semantic.Deep(*foundClusterMonitoringConfiguration, *newCMOCfg) {
return nil
}

Expand Down
10 changes: 4 additions & 6 deletions operators/endpointmetrics/pkg/collector/metrics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
"strings"
"time"

"github.com/go-logr/logr"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"gopkg.in/yaml.v2"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
Expand Down Expand Up @@ -325,7 +323,7 @@ func (m *MetricsCollector) ensureService(ctx context.Context, isUWL bool) error
return fmt.Errorf("failed to get service %s/%s: %w", m.Namespace, name, err)
}

if !equality.Semantic.DeepDerivative(desiredService.Spec, foundService.Spec) {
if !equality.Semantic.DeepEqual(desiredService.Spec, foundService.Spec) {
m.Log.Info("Updating Service", "name", name, "namespace", m.Namespace)

foundService.Spec = desiredService.Spec
Expand Down Expand Up @@ -407,7 +405,7 @@ func (m *MetricsCollector) ensureServiceMonitor(ctx context.Context, isUWL bool)
return fmt.Errorf("failed to get ServiceMonitor %s/%s: %w", m.Namespace, name, err)
}

if !equality.Semantic.DeepDerivative(desiredSm.Spec, foundSm.Spec) {
if !equality.Semantic.DeepEqual(desiredSm.Spec, foundSm.Spec) {
m.Log.Info("Updating ServiceMonitor", "name", name, "namespace", m.Namespace)

foundSm.Spec = desiredSm.Spec
Expand Down Expand Up @@ -493,7 +491,7 @@ func (m *MetricsCollector) ensureAlertingRule(ctx context.Context, isUWL bool) e
return fmt.Errorf("failed to get PrometheusRule %s/%s: %w", m.Namespace, name, err)
}

if !equality.Semantic.DeepDerivative(desiredPromRule.Spec, foundPromRule.Spec) {
if !equality.Semantic.DeepEqual(desiredPromRule.Spec, foundPromRule.Spec) {
m.Log.Info("Updating PrometheusRule", "name", name, "namespace", m.Namespace)

foundPromRule.Spec = desiredPromRule.Spec
Expand Down Expand Up @@ -759,7 +757,7 @@ func (m *MetricsCollector) ensureDeployment(ctx context.Context, isUWL bool, dep
return fmt.Errorf("failed to get Deployment %s/%s: %w", m.Namespace, name, err)
}

isDifferentSpec := !equality.Semantic.DeepDerivative(desiredMetricsCollectorDep.Spec.Template.Spec, foundMetricsCollectorDep.Spec.Template.Spec)
isDifferentSpec := !equality.Semantic.DeepEqual(desiredMetricsCollectorDep.Spec.Template.Spec, foundMetricsCollectorDep.Spec.Template.Spec)
isDifferentReplicas := !equality.Semantic.DeepEqual(desiredMetricsCollectorDep.Spec.Replicas, foundMetricsCollectorDep.Spec.Replicas)
if isDifferentSpec || isDifferentReplicas || deployParams.forceRestart {
m.Log.Info("Updating Deployment", "name", name, "namespace", m.Namespace, "isDifferentSpec", isDifferentSpec, "isDifferentReplicas", isDifferentReplicas, "forceRestart", deployParams.forceRestart)
Expand Down
42 changes: 21 additions & 21 deletions operators/pkg/deploying/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (d *Deployer) updateDeployment(ctx context.Context, desiredObj, runtimeObj
return err
}

if !apiequality.Semantic.DeepDerivative(desiredDeploy.Spec, runtimeDepoly.Spec) {
if !apiequality.Semantic.DeepEqual(desiredDeploy.Spec, runtimeDepoly.Spec) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredDeploy)
}
Expand All @@ -123,8 +123,8 @@ func (d *Deployer) updateStatefulSet(ctx context.Context, desiredObj, runtimeObj
return err
}

if !apiequality.Semantic.DeepDerivative(desiredDepoly.Spec.Template, runtimeDepoly.Spec.Template) ||
!apiequality.Semantic.DeepDerivative(desiredDepoly.Spec.Replicas, runtimeDepoly.Spec.Replicas) {
if !apiequality.Semantic.DeepEqual(desiredDepoly.Spec.Template, runtimeDepoly.Spec.Template) ||
!apiequality.Semantic.DeepEqual(desiredDepoly.Spec.Replicas, runtimeDepoly.Spec.Replicas) {
logUpdateInfo(runtimeObj)
runtimeDepoly.Spec.Replicas = desiredDepoly.Spec.Replicas
runtimeDepoly.Spec.Template = desiredDepoly.Spec.Template
Expand All @@ -140,7 +140,7 @@ func (d *Deployer) updateService(ctx context.Context, desiredObj, runtimeObj *un
return err
}

if !apiequality.Semantic.DeepDerivative(desiredService.Spec, runtimeService.Spec) {
if !apiequality.Semantic.DeepEqual(desiredService.Spec, runtimeService.Spec) {
desiredService.ObjectMeta.ResourceVersion = runtimeService.ObjectMeta.ResourceVersion
desiredService.Spec.ClusterIP = runtimeService.Spec.ClusterIP
logUpdateInfo(runtimeObj)
Expand All @@ -156,7 +156,7 @@ func (d *Deployer) updateConfigMap(ctx context.Context, desiredObj, runtimeObj *
return err
}

if !apiequality.Semantic.DeepDerivative(desiredConfigMap.Data, runtimeConfigMap.Data) {
if !apiequality.Semantic.DeepEqual(desiredConfigMap.Data, runtimeConfigMap.Data) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredConfigMap)
}
Expand All @@ -171,7 +171,7 @@ func (d *Deployer) updateSecret(ctx context.Context, desiredObj, runtimeObj *uns
}

if desiredSecret.Data == nil ||
!apiequality.Semantic.DeepDerivative(desiredSecret.Data, runtimeSecret.Data) {
!apiequality.Semantic.DeepEqual(desiredSecret.Data, runtimeSecret.Data) {
logUpdateInfo(desiredObj)
return d.client.Update(ctx, desiredSecret)
}
Expand All @@ -184,8 +184,8 @@ func (d *Deployer) updateClusterRole(ctx context.Context, desiredObj, runtimeObj
return err
}

if !apiequality.Semantic.DeepDerivative(desiredClusterRole.Rules, runtimeClusterRole.Rules) ||
!apiequality.Semantic.DeepDerivative(desiredClusterRole.AggregationRule, runtimeClusterRole.AggregationRule) {
if !apiequality.Semantic.DeepEqual(desiredClusterRole.Rules, runtimeClusterRole.Rules) ||
!apiequality.Semantic.DeepEqual(desiredClusterRole.AggregationRule, runtimeClusterRole.AggregationRule) {
logUpdateInfo(desiredObj)
return d.client.Update(ctx, desiredClusterRole)
}
Expand All @@ -198,8 +198,8 @@ func (d *Deployer) updateClusterRoleBinding(ctx context.Context, desiredObj, run
return err
}

if !apiequality.Semantic.DeepDerivative(desiredClusterRoleBinding.Subjects, runtimeClusterRoleBinding.Subjects) ||
!apiequality.Semantic.DeepDerivative(desiredClusterRoleBinding.RoleRef, runtimeClusterRoleBinding.RoleRef) {
if !apiequality.Semantic.DeepEqual(desiredClusterRoleBinding.Subjects, runtimeClusterRoleBinding.Subjects) ||
!apiequality.Semantic.DeepEqual(desiredClusterRoleBinding.RoleRef, runtimeClusterRoleBinding.RoleRef) {
logUpdateInfo(desiredObj)
return d.client.Update(ctx, desiredClusterRoleBinding)
}
Expand All @@ -214,7 +214,7 @@ func (d *Deployer) updateCRD(ctx context.Context, desiredObj, runtimeObj *unstru

desiredCRD.ObjectMeta.ResourceVersion = runtimeCRD.ObjectMeta.ResourceVersion

if !apiequality.Semantic.DeepDerivative(desiredCRD.Spec, runtimeCRD.Spec) {
if !apiequality.Semantic.DeepEqual(desiredCRD.Spec, runtimeCRD.Spec) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredCRD)
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func (d *Deployer) updatePrometheus(ctx context.Context, desiredObj, runtimeObj
log.Info("Desired Prometheus: AdditionalAlertManagerConfig is null")
}

if !apiequality.Semantic.DeepDerivative(desiredPrometheus.Spec, runtimePrometheus.Spec) {
if !apiequality.Semantic.DeepEqual(desiredPrometheus.Spec, runtimePrometheus.Spec) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredPrometheus)
} else {
Expand All @@ -269,7 +269,7 @@ func (d *Deployer) updatePrometheusRule(ctx context.Context, desiredObj, runtime
return err
}

if !apiequality.Semantic.DeepDerivative(desiredPrometheusRule.Spec, runtimePrometheusRule.Spec) {
if !apiequality.Semantic.DeepEqual(desiredPrometheusRule.Spec, runtimePrometheusRule.Spec) {
logUpdateInfo(runtimeObj)
if desiredPrometheusRule.ResourceVersion != runtimePrometheusRule.ResourceVersion {
desiredPrometheusRule.ResourceVersion = runtimePrometheusRule.ResourceVersion
Expand All @@ -286,7 +286,7 @@ func (d *Deployer) updateIngress(ctx context.Context, desiredObj, runtimeObj *un
return err
}

if !apiequality.Semantic.DeepDerivative(desiredIngress.Spec, runtimeIngress.Spec) {
if !apiequality.Semantic.DeepEqual(desiredIngress.Spec, runtimeIngress.Spec) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredIngress)
}
Expand All @@ -300,7 +300,7 @@ func (d *Deployer) updateRole(ctx context.Context, desiredObj, runtimeObj *unstr
return err
}

if !apiequality.Semantic.DeepDerivative(desiredRole.Rules, runtimeRole.Rules) {
if !apiequality.Semantic.DeepEqual(desiredRole.Rules, runtimeRole.Rules) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredRole)
}
Expand All @@ -314,8 +314,8 @@ func (d *Deployer) updateRoleBinding(ctx context.Context, desiredObj, runtimeObj
return err
}

if !apiequality.Semantic.DeepDerivative(desiredRoleBinding.Subjects, runtimeRoleBinding.Subjects) ||
!apiequality.Semantic.DeepDerivative(desiredRoleBinding.RoleRef, runtimeRoleBinding.RoleRef) {
if !apiequality.Semantic.DeepEqual(desiredRoleBinding.Subjects, runtimeRoleBinding.Subjects) ||
!apiequality.Semantic.DeepEqual(desiredRoleBinding.RoleRef, runtimeRoleBinding.RoleRef) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredRoleBinding)
}
Expand All @@ -329,8 +329,8 @@ func (d *Deployer) updateServiceAccount(ctx context.Context, desiredObj, runtime
return err
}

if !apiequality.Semantic.DeepDerivative(desiredServiceAccount.ImagePullSecrets, runtimeServiceAccount.ImagePullSecrets) ||
!apiequality.Semantic.DeepDerivative(desiredServiceAccount.Secrets, runtimeServiceAccount.Secrets) {
if !apiequality.Semantic.DeepEquale(desiredServiceAccount.ImagePullSecrets, runtimeServiceAccount.ImagePullSecrets) ||

Check failure on line 332 in operators/pkg/deploying/deployer.go

View check run for this annotation

Red Hat Konflux / Red Hat Konflux / multicluster-observability-operator-acm-212-on-pull-request

operators/pkg/deploying/deployer.go#L332

apiequality.Semantic.DeepEquale undefined (type conversion.Equalities has no field or method DeepEquale)

Check failure on line 332 in operators/pkg/deploying/deployer.go

View check run for this annotation

Red Hat Konflux / Red Hat Konflux / endpoint-monitoring-operator-acm-212-on-pull-request

operators/pkg/deploying/deployer.go#L332

apiequality.Semantic.DeepEquale undefined (type conversion.Equalities has no field or method DeepEquale)
!apiequality.Semantic.DeepEqual(desiredServiceAccount.Secrets, runtimeServiceAccount.Secrets) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredServiceAccount)
}
Expand All @@ -344,7 +344,7 @@ func (d *Deployer) updateDaemonSet(ctx context.Context, desiredObj, runtimeObj *
return err
}

if !apiequality.Semantic.DeepDerivative(desiredDaemonSet.Spec, runtimeDaemonSet.Spec) {
if !apiequality.Semantic.DeepEqual(desiredDaemonSet.Spec, runtimeDaemonSet.Spec) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredDaemonSet)
}
Expand All @@ -358,7 +358,7 @@ func (d *Deployer) updateServiceMonitor(ctx context.Context, desiredObj, runtime
return err
}

if !apiequality.Semantic.DeepDerivative(desiredServiceMonitor.Spec, runtimeServiceMonitor.Spec) {
if !apiequality.Semantic.DeepEqual(desiredServiceMonitor.Spec, runtimeServiceMonitor.Spec) {
logUpdateInfo(runtimeObj)
return d.client.Update(ctx, desiredServiceMonitor)
}
Expand Down

0 comments on commit f3ecbf6

Please sign in to comment.