Skip to content

Commit 82e0e84

Browse files
authored
fix: move reasons to once place (#119)
1 parent 50907ff commit 82e0e84

31 files changed

+589
-575
lines changed

pkg/controllers/clusterresourceplacement/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (r *Reconciler) handleUpdate(ctx context.Context, crp *fleetv1beta1.Cluster
185185
scheduleCondition := metav1.Condition{
186186
Status: metav1.ConditionFalse,
187187
Type: string(fleetv1beta1.ClusterResourcePlacementScheduledConditionType),
188-
Reason: InvalidResourceSelectorsReason,
188+
Reason: condition.InvalidResourceSelectorsReason,
189189
Message: fmt.Sprintf("The resource selectors are invalid: %v", err),
190190
ObservedGeneration: crp.Generation,
191191
}
@@ -1194,7 +1194,7 @@ func buildScheduledCondition(crp *fleetv1beta1.ClusterResourcePlacement, latestS
11941194
return metav1.Condition{
11951195
Status: metav1.ConditionUnknown,
11961196
Type: string(fleetv1beta1.ClusterResourcePlacementScheduledConditionType),
1197-
Reason: SchedulingUnknownReason,
1197+
Reason: condition.SchedulingUnknownReason,
11981198
Message: "Scheduling has not completed",
11991199
ObservedGeneration: crp.Generation,
12001200
}

pkg/controllers/clusterresourceplacement/controller_integration_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ func checkClusterResourceSnapshot() *placementv1beta1.ClusterResourceSnapshot {
333333
}
334334

335335
func updateClusterSchedulingPolicySnapshotStatus(status metav1.ConditionStatus, clustersSelected bool) *placementv1beta1.ClusterSchedulingPolicySnapshot {
336-
reason := ResourceScheduleSucceededReason
336+
reason := condition.ResourceScheduleSucceededReason
337337
if status == metav1.ConditionFalse {
338-
reason = ResourceScheduleFailedReason
338+
reason = condition.ResourceScheduleFailedReason
339339
}
340340

341341
// Update scheduling condition
@@ -422,7 +422,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
422422
{
423423
Status: metav1.ConditionUnknown,
424424
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
425-
Reason: SchedulingUnknownReason,
425+
Reason: condition.SchedulingUnknownReason,
426426
},
427427
},
428428
},
@@ -461,7 +461,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
461461
{
462462
Status: metav1.ConditionTrue,
463463
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
464-
Reason: ResourceScheduleSucceededReason,
464+
Reason: condition.ResourceScheduleSucceededReason,
465465
},
466466
},
467467
},
@@ -479,7 +479,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
479479
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
480480
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
481481
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionUnknown))},
482-
{Name: ptr.To("reason"), Value: ptr.To(SchedulingUnknownReason)},
482+
{Name: ptr.To("reason"), Value: ptr.To(condition.SchedulingUnknownReason)},
483483
},
484484
Gauge: &prometheusclientmodel.Gauge{
485485
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -518,7 +518,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
518518
{
519519
Status: metav1.ConditionFalse,
520520
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
521-
Reason: ResourceScheduleFailedReason,
521+
Reason: condition.ResourceScheduleFailedReason,
522522
},
523523
},
524524
},
@@ -535,7 +535,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
535535
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
536536
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
537537
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionUnknown))},
538-
{Name: ptr.To("reason"), Value: ptr.To(SchedulingUnknownReason)},
538+
{Name: ptr.To("reason"), Value: ptr.To(condition.SchedulingUnknownReason)},
539539
},
540540
Gauge: &prometheusclientmodel.Gauge{
541541
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -547,7 +547,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
547547
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
548548
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
549549
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionFalse))},
550-
{Name: ptr.To("reason"), Value: ptr.To(ResourceScheduleFailedReason)},
550+
{Name: ptr.To("reason"), Value: ptr.To(condition.ResourceScheduleFailedReason)},
551551
},
552552
Gauge: &prometheusclientmodel.Gauge{
553553
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -577,7 +577,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
577577
{
578578
Status: metav1.ConditionTrue,
579579
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
580-
Reason: ResourceScheduleSucceededReason,
580+
Reason: condition.ResourceScheduleSucceededReason,
581581
},
582582
{
583583
Status: metav1.ConditionUnknown,
@@ -643,7 +643,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
643643
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
644644
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
645645
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionUnknown))},
646-
{Name: ptr.To("reason"), Value: ptr.To(SchedulingUnknownReason)},
646+
{Name: ptr.To("reason"), Value: ptr.To(condition.SchedulingUnknownReason)},
647647
},
648648
Gauge: &prometheusclientmodel.Gauge{
649649
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -672,7 +672,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
672672
{
673673
Status: metav1.ConditionTrue,
674674
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
675-
Reason: ResourceScheduleSucceededReason,
675+
Reason: condition.ResourceScheduleSucceededReason,
676676
},
677677
{
678678
Status: metav1.ConditionTrue,
@@ -787,7 +787,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
787787
{
788788
Status: metav1.ConditionTrue,
789789
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
790-
Reason: ResourceScheduleSucceededReason,
790+
Reason: condition.ResourceScheduleSucceededReason,
791791
},
792792
{
793793
Status: metav1.ConditionUnknown,
@@ -851,7 +851,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
851851
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
852852
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
853853
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionUnknown))},
854-
{Name: ptr.To("reason"), Value: ptr.To(SchedulingUnknownReason)},
854+
{Name: ptr.To("reason"), Value: ptr.To(condition.SchedulingUnknownReason)},
855855
},
856856
Gauge: &prometheusclientmodel.Gauge{
857857
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -880,7 +880,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
880880
{
881881
Status: metav1.ConditionTrue,
882882
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
883-
Reason: ResourceScheduleSucceededReason,
883+
Reason: condition.ResourceScheduleSucceededReason,
884884
},
885885
{
886886
Status: metav1.ConditionTrue,
@@ -993,7 +993,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
993993
{
994994
Status: metav1.ConditionUnknown,
995995
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
996-
Reason: SchedulingUnknownReason,
996+
Reason: condition.SchedulingUnknownReason,
997997
ObservedGeneration: 2,
998998
},
999999
{
@@ -1028,7 +1028,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
10281028
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
10291029
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
10301030
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionUnknown))},
1031-
{Name: ptr.To("reason"), Value: ptr.To(SchedulingUnknownReason)},
1031+
{Name: ptr.To("reason"), Value: ptr.To(condition.SchedulingUnknownReason)},
10321032
},
10331033
Gauge: &prometheusclientmodel.Gauge{
10341034
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -1047,7 +1047,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
10471047
{
10481048
Status: metav1.ConditionTrue,
10491049
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
1050-
Reason: ResourceScheduleSucceededReason,
1050+
Reason: condition.ResourceScheduleSucceededReason,
10511051
ObservedGeneration: 2,
10521052
},
10531053
{
@@ -1181,7 +1181,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
11811181
{
11821182
Status: metav1.ConditionTrue,
11831183
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
1184-
Reason: ResourceScheduleSucceededReason,
1184+
Reason: condition.ResourceScheduleSucceededReason,
11851185
},
11861186
{
11871187
Status: metav1.ConditionTrue,
@@ -1270,7 +1270,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
12701270
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
12711271
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
12721272
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionUnknown))},
1273-
{Name: ptr.To("reason"), Value: ptr.To(SchedulingUnknownReason)},
1273+
{Name: ptr.To("reason"), Value: ptr.To(condition.SchedulingUnknownReason)},
12741274
},
12751275
Gauge: &prometheusclientmodel.Gauge{
12761276
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -1439,7 +1439,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
14391439
{
14401440
Status: metav1.ConditionUnknown,
14411441
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
1442-
Reason: SchedulingUnknownReason,
1442+
Reason: condition.SchedulingUnknownReason,
14431443
},
14441444
},
14451445
},
@@ -1480,7 +1480,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
14801480
{
14811481
Status: metav1.ConditionTrue,
14821482
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
1483-
Reason: ResourceScheduleSucceededReason,
1483+
Reason: condition.ResourceScheduleSucceededReason,
14841484
},
14851485
{
14861486
Status: metav1.ConditionTrue,
@@ -1564,7 +1564,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
15641564
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
15651565
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
15661566
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionUnknown))},
1567-
{Name: ptr.To("reason"), Value: ptr.To(SchedulingUnknownReason)},
1567+
{Name: ptr.To("reason"), Value: ptr.To(condition.SchedulingUnknownReason)},
15681568
},
15691569
Gauge: &prometheusclientmodel.Gauge{
15701570
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -1663,7 +1663,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
16631663
{
16641664
Status: metav1.ConditionTrue,
16651665
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
1666-
Reason: ResourceScheduleSucceededReason,
1666+
Reason: condition.ResourceScheduleSucceededReason,
16671667
},
16681668
{
16691669
Status: metav1.ConditionTrue,
@@ -1747,7 +1747,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
17471747
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
17481748
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
17491749
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionUnknown))},
1750-
{Name: ptr.To("reason"), Value: ptr.To(SchedulingUnknownReason)},
1750+
{Name: ptr.To("reason"), Value: ptr.To(condition.SchedulingUnknownReason)},
17511751
},
17521752
Gauge: &prometheusclientmodel.Gauge{
17531753
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -1791,7 +1791,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
17911791
{
17921792
Status: metav1.ConditionTrue,
17931793
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
1794-
Reason: ResourceScheduleSucceededReason,
1794+
Reason: condition.ResourceScheduleSucceededReason,
17951795
},
17961796
{
17971797
Status: metav1.ConditionTrue,
@@ -1943,7 +1943,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
19431943
{
19441944
Status: metav1.ConditionFalse,
19451945
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
1946-
Reason: InvalidResourceSelectorsReason,
1946+
Reason: condition.InvalidResourceSelectorsReason,
19471947
},
19481948
},
19491949
},
@@ -1958,7 +1958,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
19581958
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
19591959
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
19601960
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionFalse))},
1961-
{Name: ptr.To("reason"), Value: ptr.To(InvalidResourceSelectorsReason)},
1961+
{Name: ptr.To("reason"), Value: ptr.To(condition.InvalidResourceSelectorsReason)},
19621962
},
19631963
Gauge: &prometheusclientmodel.Gauge{
19641964
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -2017,7 +2017,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
20172017
{
20182018
Status: metav1.ConditionUnknown,
20192019
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
2020-
Reason: SchedulingUnknownReason,
2020+
Reason: condition.SchedulingUnknownReason,
20212021
},
20222022
},
20232023
},
@@ -2040,7 +2040,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
20402040
{Name: ptr.To("generation"), Value: ptr.To(strconv.FormatInt(gotCRP.Generation, 10))},
20412041
{Name: ptr.To("conditionType"), Value: ptr.To(string(placementv1beta1.ClusterResourcePlacementScheduledConditionType))},
20422042
{Name: ptr.To("status"), Value: ptr.To(string(corev1.ConditionUnknown))},
2043-
{Name: ptr.To("reason"), Value: ptr.To(SchedulingUnknownReason)},
2043+
{Name: ptr.To("reason"), Value: ptr.To(condition.SchedulingUnknownReason)},
20442044
},
20452045
Gauge: &prometheusclientmodel.Gauge{
20462046
Value: ptr.To(float64(time.Now().UnixNano()) / 1e9),
@@ -2064,7 +2064,7 @@ var _ = Describe("Test ClusterResourcePlacement Controller", func() {
20642064
{
20652065
Status: metav1.ConditionTrue,
20662066
Type: string(placementv1beta1.ClusterResourcePlacementScheduledConditionType),
2067-
Reason: ResourceScheduleSucceededReason,
2067+
Reason: condition.ResourceScheduleSucceededReason,
20682068
},
20692069
{
20702070
Status: metav1.ConditionUnknown,

pkg/controllers/clusterresourceplacement/placement_controllerv1alpha1.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
fleetv1alpha1 "github.com/kubefleet-dev/kubefleet/apis/v1alpha1"
3636
"github.com/kubefleet-dev/kubefleet/pkg/metrics"
3737
"github.com/kubefleet-dev/kubefleet/pkg/utils"
38+
"github.com/kubefleet-dev/kubefleet/pkg/utils/condition"
3839
"github.com/kubefleet-dev/kubefleet/pkg/utils/controller"
3940
"github.com/kubefleet-dev/kubefleet/pkg/utils/informer"
4041
)
@@ -316,7 +317,7 @@ func (r *Reconciler) updatePlacementAppliedCondition(placement *fleetv1alpha1.Cl
316317
placement.SetConditions(metav1.Condition{
317318
Status: metav1.ConditionTrue,
318319
Type: string(fleetv1alpha1.ResourcePlacementStatusConditionTypeApplied),
319-
Reason: ApplySucceededReason,
320+
Reason: condition.ApplySucceededReason,
320321
Message: "Successfully applied resources to member clusters",
321322
ObservedGeneration: placement.Generation,
322323
})
@@ -329,7 +330,7 @@ func (r *Reconciler) updatePlacementAppliedCondition(placement *fleetv1alpha1.Cl
329330
placement.SetConditions(metav1.Condition{
330331
Status: metav1.ConditionUnknown,
331332
Type: string(fleetv1alpha1.ResourcePlacementStatusConditionTypeApplied),
332-
Reason: ApplyPendingReason,
333+
Reason: condition.ApplyPendingReason,
333334
Message: applyErr.Error(),
334335
ObservedGeneration: placement.Generation,
335336
})
@@ -342,7 +343,7 @@ func (r *Reconciler) updatePlacementAppliedCondition(placement *fleetv1alpha1.Cl
342343
placement.SetConditions(metav1.Condition{
343344
Status: metav1.ConditionFalse,
344345
Type: string(fleetv1alpha1.ResourcePlacementStatusConditionTypeApplied),
345-
Reason: ApplyFailedReason,
346+
Reason: condition.ApplyFailedReason,
346347
Message: applyErr.Error(),
347348
ObservedGeneration: placement.Generation,
348349
})

pkg/controllers/clusterresourceplacement/placement_status.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,6 @@ import (
3232
"github.com/kubefleet-dev/kubefleet/pkg/utils/controller"
3333
)
3434

35-
// ClusterResourcePlacementStatus condition reasons
36-
const (
37-
// InvalidResourceSelectorsReason is the reason string of placement condition when the selected resources are invalid
38-
// or forbidden.
39-
InvalidResourceSelectorsReason = "InvalidResourceSelectors"
40-
// SchedulingUnknownReason is the reason string of placement condition when the schedule status is unknown.
41-
SchedulingUnknownReason = "SchedulePending"
42-
43-
// ApplyFailedReason is the reason string of placement condition when the selected resources fail to apply.
44-
ApplyFailedReason = "ApplyFailed"
45-
// ApplyPendingReason is the reason string of placement condition when the selected resources are pending to apply.
46-
ApplyPendingReason = "ApplyPending"
47-
// ApplySucceededReason is the reason string of placement condition when the selected resources are applied successfully.
48-
ApplySucceededReason = "ApplySucceeded"
49-
)
50-
51-
// ResourcePlacementStatus condition reasons and message formats
52-
const (
53-
// ResourceScheduleSucceededReason is the reason string of placement condition when the selected resources are scheduled.
54-
ResourceScheduleSucceededReason = "ScheduleSucceeded"
55-
// ResourceScheduleFailedReason is the reason string of placement condition when the scheduler failed to schedule the selected resources.
56-
ResourceScheduleFailedReason = "ScheduleFailed"
57-
)
58-
5935
// calculateFailedToScheduleClusterCount calculates the count of failed to schedule clusters based on the scheduling policy.
6036
func calculateFailedToScheduleClusterCount(crp *fleetv1beta1.ClusterResourcePlacement, selected, unselected []*fleetv1beta1.ClusterDecision) int {
6137
failedToScheduleClusterCount := 0
@@ -106,7 +82,7 @@ func appendFailedToScheduleResourcePlacementStatuses(
10682
failedToScheduleCond := metav1.Condition{
10783
Status: metav1.ConditionFalse,
10884
Type: string(fleetv1beta1.ResourceScheduledConditionType),
109-
Reason: ResourceScheduleFailedReason,
85+
Reason: condition.ResourceScheduleFailedReason,
11086
Message: unselected[i].Reason,
11187
ObservedGeneration: crp.Generation,
11288
}

0 commit comments

Comments
 (0)