Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: generate predictable PodSpec
  • Loading branch information
julienmancuso committed Aug 15, 2025
commit 1fedf8076adcc0f8100e03602b6cd4f377f2213d
34 changes: 34 additions & 0 deletions deploy/cloud/operator/internal/controller_common/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/ai-dynamo/dynamo/deploy/cloud/operator/api/dynamo/common"
"github.com/ai-dynamo/dynamo/deploy/cloud/operator/internal/consts"
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -156,6 +157,14 @@ func SyncResource[T client.Object](ctx context.Context, r Reconciler, parentReso
return false, resource, fmt.Errorf("failed to check if spec has changed: %w", err)
}
if newHash != nil {
// Generate and log diff before updating
diff, diffErr := generateSpecDiff(oldResource, resource)
if diffErr != nil {
logs.V(1).Info(fmt.Sprintf("Failed to generate diff for %s: %v", resourceType, diffErr))
} else if diff != "" {
logs.Info(fmt.Sprintf("%s spec changes detected", resourceType), "diff", diff)
}

// update the spec of the current object with the desired spec
err = CopySpec(resource, oldResource)
if err != nil {
Expand Down Expand Up @@ -252,6 +261,31 @@ func IsSpecChanged(current client.Object, desired client.Object) (*string, error
return &hashStr, nil
}

// generateSpecDiff creates a unified diff showing changes between old and new resource specs
func generateSpecDiff(oldResource, newResource client.Object) (string, error) {
oldSpec, err := getSpec(oldResource)
if err != nil {
return "", fmt.Errorf("failed to get old spec: %w", err)
}

newSpec, err := getSpec(newResource)
if err != nil {
return "", fmt.Errorf("failed to get new spec: %w", err)
}

// Convert specs to sorted JSON for consistent comparison
oldSorted := SortKeys(oldSpec)
newSorted := SortKeys(newSpec)

// Generate diff using cmp
diff := cmp.Diff(oldSorted, newSorted)
if diff == "" {
return "", nil
}

return diff, nil
}

func GetSpecHash(obj client.Object) (string, error) {
spec, err := getSpec(obj)
if err != nil {
Expand Down