diff --git a/controllers/weightsandbiases_controller.go b/controllers/weightsandbiases_controller.go index b2ceaad..87dea6d 100644 --- a/controllers/weightsandbiases_controller.go +++ b/controllers/weightsandbiases_controller.go @@ -214,9 +214,10 @@ func (r *WeightsAndBiasesReconciler) Reconcile(ctx context.Context, req ctrl.Req log.Info("No changes found") statusManager.Set(status.Completed) return ctrlqueue.Requeue(desiredSpec) - } else { + } + if r.Debug { diff := currentActiveSpec.DiffValues(desiredSpec) - log.Info("Changes found", "diff", diff) + log.Info("Specs are not equal", "diff", diff) } } diff --git a/pkg/wandb/spec/spec.go b/pkg/wandb/spec/spec.go index 8eda878..08343fa 100644 --- a/pkg/wandb/spec/spec.go +++ b/pkg/wandb/spec/spec.go @@ -88,6 +88,41 @@ func (s *Spec) IsEqual(spec *Spec) bool { return isReleaseEqual && isValuesEqual && isMetadataEqual } +func (s *Spec) DiffValues(other *Spec) map[string]interface{} { + return diffMaps(s.Values, other.Values) +} + +func diffMaps(a, b map[string]interface{}) map[string]interface{} { + diff := make(map[string]interface{}) + for key, aValue := range a { + if bValue, ok := b[key]; ok { + if !reflect.DeepEqual(aValue, bValue) { + switch aValue.(type) { + case map[string]interface{}: + if bMap, ok := bValue.(map[string]interface{}); ok { + nestedDiff := diffMaps(aValue.(map[string]interface{}), bMap) + if len(nestedDiff) > 0 { + diff[key] = nestedDiff + } + } else { + diff[key] = aValue + } + default: + diff[key] = aValue + } + } + } else { + diff[key] = aValue + } + } + for key, bValue := range b { + if _, ok := a[key]; !ok { + diff[key] = bValue + } + } + return diff +} + func (s *Spec) mergeConfig(values Values) (err error) { if s.Values == nil { s.Values = values @@ -159,38 +194,3 @@ func maskValues(values map[string]interface{}) map[string]interface{} { } return newValues } - -func (s *Spec) DiffValues(other *Spec) map[string]interface{} { - return diffMaps(s.Values, other.Values) -} - -func diffMaps(a, b map[string]interface{}) map[string]interface{} { - diff := make(map[string]interface{}) - for key, aValue := range a { - if bValue, ok := b[key]; ok { - if !reflect.DeepEqual(aValue, bValue) { - switch aValue.(type) { - case map[string]interface{}: - if bMap, ok := bValue.(map[string]interface{}); ok { - nestedDiff := diffMaps(aValue.(map[string]interface{}), bMap) - if len(nestedDiff) > 0 { - diff[key] = nestedDiff - } - } else { - diff[key] = aValue - } - default: - diff[key] = aValue - } - } - } else { - diff[key] = aValue - } - } - for key, bValue := range b { - if _, ok := a[key]; !ok { - diff[key] = bValue - } - } - return diff -}