diff --git a/pkg/controllers/clusterresourceplacement/controller.go b/pkg/controllers/clusterresourceplacement/controller.go index 5aaeea6af..4d0a1a4de 100644 --- a/pkg/controllers/clusterresourceplacement/controller.go +++ b/pkg/controllers/clusterresourceplacement/controller.go @@ -298,9 +298,9 @@ func (r *Reconciler) getOrCreateClusterSchedulingPolicySnapshot(ctx context.Cont if crp.Spec.Policy != nil && crp.Spec.Policy.PlacementType == fleetv1beta1.PickNPlacementType && crp.Spec.Policy.NumberOfClusters != nil { - latestPolicySnapshot.Annotations = map[string]string{ - fleetv1beta1.NumberOfClustersAnnotation: strconv.Itoa(int(*crp.Spec.Policy.NumberOfClusters)), - } + // Note that all policy snapshots should have the CRP generation annotation set already, + // so the Annotations field will not be nil. + latestPolicySnapshot.Annotations[fleetv1beta1.NumberOfClustersAnnotation] = strconv.Itoa(int(*crp.Spec.Policy.NumberOfClusters)) } if err := r.Client.Create(ctx, latestPolicySnapshot); err != nil { diff --git a/pkg/controllers/clusterresourceplacement/controller_test.go b/pkg/controllers/clusterresourceplacement/controller_test.go index 0ab94457b..3142b830a 100644 --- a/pkg/controllers/clusterresourceplacement/controller_test.go +++ b/pkg/controllers/clusterresourceplacement/controller_test.go @@ -169,6 +169,7 @@ func TestGetOrCreateClusterSchedulingPolicySnapshot(t *testing.T) { }, }, Annotations: map[string]string{ + fleetv1beta1.CRPGenerationAnnotation: strconv.Itoa(crpGeneration), fleetv1beta1.NumberOfClustersAnnotation: strconv.Itoa(3), }, }, @@ -400,6 +401,7 @@ func TestGetOrCreateClusterSchedulingPolicySnapshot(t *testing.T) { }, }, Annotations: map[string]string{ + fleetv1beta1.CRPGenerationAnnotation: strconv.Itoa(crpGeneration), fleetv1beta1.NumberOfClustersAnnotation: strconv.Itoa(3), }, }, @@ -459,6 +461,7 @@ func TestGetOrCreateClusterSchedulingPolicySnapshot(t *testing.T) { }, }, Annotations: map[string]string{ + fleetv1beta1.CRPGenerationAnnotation: strconv.Itoa(crpGeneration), fleetv1beta1.NumberOfClustersAnnotation: strconv.Itoa(3), }, },