Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Behind the debug flag, order #24

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
5 changes: 3 additions & 2 deletions controllers/weightsandbiases_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

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