Skip to content

Commit

Permalink
fix: use the override snapshot when looking for matched overrides (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiying-lin authored Mar 29, 2024
1 parent ebf2951 commit 42794c8
Show file tree
Hide file tree
Showing 8 changed files with 796 additions and 457 deletions.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/controllers/rollout/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func createUpdateInfo(binding *fleetv1beta1.ClusterResourceBinding, crp *fleetv1
// Thus, it also returns a bool indicating whether there are out of sync bindings to be rolled to differentiate those
// two cases.
func (r *Reconciler) pickBindingsToRoll(ctx context.Context, allBindings []*fleetv1beta1.ClusterResourceBinding, latestResourceSnapshot *fleetv1beta1.ClusterResourceSnapshot, crp *fleetv1beta1.ClusterResourcePlacement,
matchedCROs []*fleetv1alpha1.ClusterResourceOverride, matchedROs []*fleetv1alpha1.ResourceOverride) ([]toBeUpdatedBinding, []toBeUpdatedBinding, bool, error) {
matchedCROs []*fleetv1alpha1.ClusterResourceOverrideSnapshot, matchedROs []*fleetv1alpha1.ResourceOverrideSnapshot) ([]toBeUpdatedBinding, []toBeUpdatedBinding, bool, error) {
// Those are the bindings that are chosen by the scheduler to be applied to selected clusters.
// They include the bindings that are already applied to the clusters and the bindings that are newly selected by the scheduler.
schedulerTargetedBinds := make([]*fleetv1beta1.ClusterResourceBinding, 0)
Expand Down
176 changes: 95 additions & 81 deletions pkg/controllers/rollout/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ func TestPickBindingsToRoll(t *testing.T) {
allBindings []*fleetv1beta1.ClusterResourceBinding
latestResourceSnapshotName string
crp *fleetv1beta1.ClusterResourcePlacement
matchedCROs []*fleetv1alpha1.ClusterResourceOverride
matchedROs []*fleetv1alpha1.ResourceOverride
matchedCROs []*fleetv1alpha1.ClusterResourceOverrideSnapshot
matchedROs []*fleetv1alpha1.ResourceOverrideSnapshot
clusters []clusterv1beta1.MemberCluster
wantTobeUpdatedBindings []int
wantDesiredBindingsSpec []fleetv1beta1.ResourceBindingSpec // used to construct the want toBeUpdatedBindings
Expand Down Expand Up @@ -791,8 +791,8 @@ func TestPickBindingsToRoll(t *testing.T) {
latestResourceSnapshotName: "snapshot-2",
crp: clusterResourcePlacementForTest("test",
createPlacementPolicyForTest(fleetv1beta1.PickAllPlacementType, 0)),
matchedROs: []*fleetv1alpha1.ResourceOverride{},
matchedCROs: []*fleetv1alpha1.ClusterResourceOverride{},
matchedROs: []*fleetv1alpha1.ResourceOverrideSnapshot{},
matchedCROs: []*fleetv1alpha1.ClusterResourceOverrideSnapshot{},
wantTobeUpdatedBindings: []int{0},
wantDesiredBindingsSpec: []fleetv1beta1.ResourceBindingSpec{
{
Expand All @@ -810,21 +810,23 @@ func TestPickBindingsToRoll(t *testing.T) {
latestResourceSnapshotName: "snapshot-2",
crp: clusterResourcePlacementForTest("test",
createPlacementPolicyForTest(fleetv1beta1.PickAllPlacementType, 0)),
matchedCROs: []*fleetv1alpha1.ClusterResourceOverride{
matchedCROs: []*fleetv1alpha1.ClusterResourceOverrideSnapshot{
{
ObjectMeta: metav1.ObjectMeta{
Name: "cro-1",
},
Spec: fleetv1alpha1.ClusterResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key1": "value1",
Spec: fleetv1alpha1.ClusterResourceOverrideSnapshotSpec{
OverrideSpec: fleetv1alpha1.ClusterResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key1": "value1",
},
},
},
},
Expand All @@ -836,22 +838,24 @@ func TestPickBindingsToRoll(t *testing.T) {
},
},
},
matchedROs: []*fleetv1alpha1.ResourceOverride{
matchedROs: []*fleetv1alpha1.ResourceOverrideSnapshot{
{
ObjectMeta: metav1.ObjectMeta{
Name: "ro-2",
Namespace: "test",
},
Spec: fleetv1alpha1.ResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key2": "value2",
Spec: fleetv1alpha1.ResourceOverrideSnapshotSpec{
OverrideSpec: fleetv1alpha1.ResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key2": "value2",
},
},
},
},
Expand Down Expand Up @@ -898,21 +902,23 @@ func TestPickBindingsToRoll(t *testing.T) {
latestResourceSnapshotName: "snapshot-2",
crp: clusterResourcePlacementForTest("test",
createPlacementPolicyForTest(fleetv1beta1.PickAllPlacementType, 0)),
matchedCROs: []*fleetv1alpha1.ClusterResourceOverride{
matchedCROs: []*fleetv1alpha1.ClusterResourceOverrideSnapshot{
{
ObjectMeta: metav1.ObjectMeta{
Name: "cro-1",
},
Spec: fleetv1alpha1.ClusterResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key1": "value1",
Spec: fleetv1alpha1.ClusterResourceOverrideSnapshotSpec{
OverrideSpec: fleetv1alpha1.ClusterResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key1": "value1",
},
},
},
},
Expand All @@ -924,22 +930,24 @@ func TestPickBindingsToRoll(t *testing.T) {
},
},
},
matchedROs: []*fleetv1alpha1.ResourceOverride{
matchedROs: []*fleetv1alpha1.ResourceOverrideSnapshot{
{
ObjectMeta: metav1.ObjectMeta{
Name: "ro-2",
Namespace: "test",
},
Spec: fleetv1alpha1.ResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key2": "value2",
Spec: fleetv1alpha1.ResourceOverrideSnapshotSpec{
OverrideSpec: fleetv1alpha1.ResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key2": "value2",
},
},
},
},
Expand Down Expand Up @@ -975,21 +983,23 @@ func TestPickBindingsToRoll(t *testing.T) {
latestResourceSnapshotName: "snapshot-1",
crp: clusterResourcePlacementForTest("test",
createPlacementPolicyForTest(fleetv1beta1.PickAllPlacementType, 0)),
matchedCROs: []*fleetv1alpha1.ClusterResourceOverride{
matchedCROs: []*fleetv1alpha1.ClusterResourceOverrideSnapshot{
{
ObjectMeta: metav1.ObjectMeta{
Name: "cro-1",
},
Spec: fleetv1alpha1.ClusterResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key1": "value1",
Spec: fleetv1alpha1.ClusterResourceOverrideSnapshotSpec{
OverrideSpec: fleetv1alpha1.ClusterResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key1": "value1",
},
},
},
},
Expand All @@ -1001,22 +1011,24 @@ func TestPickBindingsToRoll(t *testing.T) {
},
},
},
matchedROs: []*fleetv1alpha1.ResourceOverride{
matchedROs: []*fleetv1alpha1.ResourceOverrideSnapshot{
{
ObjectMeta: metav1.ObjectMeta{
Name: "ro-2",
Namespace: "test",
},
Spec: fleetv1alpha1.ResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key2": "value2",
Spec: fleetv1alpha1.ResourceOverrideSnapshotSpec{
OverrideSpec: fleetv1alpha1.ResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key2": "value2",
},
},
},
},
Expand Down Expand Up @@ -1282,21 +1294,23 @@ func TestPickBindingsToRoll(t *testing.T) {
generateClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster1),
},
latestResourceSnapshotName: "snapshot-1",
matchedCROs: []*fleetv1alpha1.ClusterResourceOverride{
matchedCROs: []*fleetv1alpha1.ClusterResourceOverrideSnapshot{
{
ObjectMeta: metav1.ObjectMeta{
Name: "cro-1",
},
Spec: fleetv1alpha1.ClusterResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key1": "value1",
Spec: fleetv1alpha1.ClusterResourceOverrideSnapshotSpec{
OverrideSpec: fleetv1alpha1.ClusterResourceOverrideSpec{
Policy: &fleetv1alpha1.OverridePolicy{
OverrideRules: []fleetv1alpha1.OverrideRule{
{
ClusterSelector: &fleetv1beta1.ClusterSelector{
ClusterSelectorTerms: []fleetv1beta1.ClusterSelectorTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"key1": "value1",
},
},
},
},
Expand Down
Loading

0 comments on commit 42794c8

Please sign in to comment.