Skip to content

Commit

Permalink
fix: Log the diff of specs (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 authored Sep 3, 2024
1 parent ddd75b5 commit c0ea0d8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions controllers/weightsandbiases_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
35 changes: 35 additions & 0 deletions pkg/wandb/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c0ea0d8

Please sign in to comment.