diff --git a/controllers/weightsandbiases_controller.go b/controllers/weightsandbiases_controller.go index b496e4c..5a15a06 100644 --- a/controllers/weightsandbiases_controller.go +++ b/controllers/weightsandbiases_controller.go @@ -190,6 +190,9 @@ func (r *WeightsAndBiasesReconciler) Reconcile(ctx context.Context, req ctrl.Req log.Info("No changes found") statusManager.Set(status.Completed) return ctrlqueue.Requeue(desiredSpec) + } else { + diff := currentActiveSpec.DiffValues(desiredSpec) + log.Info("Changes found", "diff", diff) } } diff --git a/pkg/wandb/spec/spec.go b/pkg/wandb/spec/spec.go index ca66ca6..7117493 100644 --- a/pkg/wandb/spec/spec.go +++ b/pkg/wandb/spec/spec.go @@ -155,3 +155,38 @@ 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 +}