Skip to content

Commit

Permalink
fix(diff): avoid cache miss in server-side diff (#20605) (#20609)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crenshaw <[email protected]>
Co-authored-by: Michael Crenshaw <[email protected]>
  • Loading branch information
gcp-cherry-pick-bot[bot] and crenshaw-dev authored Oct 31, 2024
1 parent cacb06a commit e48878b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,10 @@ func specEqualsCompareTo(spec v1alpha1.ApplicationSpec, comparedTo v1alpha1.Comp
currentSpec.Destination.Name = ""
}

// Set IsServerInferred to false on both, because that field is not important for comparison.
comparedTo.Destination.SetIsServerInferred(false)
currentSpec.Destination.SetIsServerInferred(false)

return reflect.DeepEqual(comparedTo, currentSpec)
}

Expand Down
4 changes: 4 additions & 0 deletions controller/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,10 @@ func TestUseDiffCache(t *testing.T) {
t.Fatalf("error merging app: %s", err)
}
}
if app.Spec.Destination.Name != "" && app.Spec.Destination.Server != "" {
// Simulate the controller's process for populating both of these fields.
app.Spec.Destination.SetInferredServer(app.Spec.Destination.Server)
}
return app
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,12 @@ type ApplicationDestination struct {
isServerInferred bool `json:"-"`
}

// SetIsServerInferred sets the isServerInferred flag. This is used to allow comparison between two destinations where
// one server is inferred and the other is not.
func (d *ApplicationDestination) SetIsServerInferred(inferred bool) {
d.isServerInferred = inferred
}

type ResourceHealthLocation string

var (
Expand Down

0 comments on commit e48878b

Please sign in to comment.