Progressing status conditions, true wins (#1332)

Signed-off-by: annelau <annelau@salesforce.com>
Co-authored-by: annelau <annelau@salesforce.com>
This commit is contained in:
Anne Lau
2026-01-15 22:53:14 -08:00
committed by GitHub
parent 8029ed38eb
commit 4dc99cd621
2 changed files with 109 additions and 7 deletions

View File

@@ -127,13 +127,27 @@ func newAggregateAvailableCondition(aggCondition aggregateCondition, generation
func newAggregateConditionFromRules(conditionType string, generation int64, agg aggregateCondition) metav1.Condition {
var status metav1.ConditionStatus
switch {
case agg.numFalse > 0:
status = metav1.ConditionFalse
case agg.numUnknown > 0 || agg.numTrue == 0:
status = metav1.ConditionUnknown
default:
status = metav1.ConditionTrue
// Progressing uses opposite logic: True if ANY resource is progressing
if conditionType == workapiv1.WorkProgressing {
switch {
case agg.numTrue > 0:
status = metav1.ConditionTrue
case agg.numUnknown > 0:
status = metav1.ConditionUnknown
default:
status = metav1.ConditionFalse
}
} else {
// Default logic: False wins, then Unknown, then True
switch {
case agg.numFalse > 0:
status = metav1.ConditionFalse
case agg.numUnknown > 0 || agg.numTrue == 0:
status = metav1.ConditionUnknown
default:
status = metav1.ConditionTrue
}
}
// Use manifest condition message if there is only one, otherwise use generic message

View File

@@ -751,6 +751,94 @@ func TestConditionRules(t *testing.T) {
{Type: workapiv1.WorkComplete, Status: util.ConditionNotFound},
},
},
{
name: "work Progressing is True when any manifest is progressing (True wins)",
existingResources: []runtime.Object{
testingcommon.NewUnstructuredWithContent(
"v1", "NewObject", "ns1", "n1",
map[string]any{"spec": map[string]any{"key1": "val1"}}),
testingcommon.NewUnstructuredWithContent(
"v1", "NewObject", "ns1", "n2",
map[string]any{"spec": map[string]any{"key1": "val2"}}),
},
configOption: []workapiv1.ManifestConfigOption{
{
ResourceIdentifier: workapiv1.ResourceIdentifier{Resource: "newobjects", Namespace: "ns1", Name: "n1"},
ConditionRules: []workapiv1.ConditionRule{
{
Type: workapiv1.CelConditionExpressionsType,
Condition: workapiv1.ManifestProgressing,
CelExpressions: []string{"true"},
},
},
},
{
ResourceIdentifier: workapiv1.ResourceIdentifier{Resource: "newobjects", Namespace: "ns1", Name: "n2"},
ConditionRules: []workapiv1.ConditionRule{
{
Type: workapiv1.CelConditionExpressionsType,
Condition: workapiv1.ManifestProgressing,
CelExpressions: []string{"false"},
},
},
},
},
manifests: []workapiv1.ManifestCondition{
newManifest("", "v1", "newobjects", "ns1", "n1"),
newManifest("", "v1", "newobjects", "ns1", "n2"),
},
expectedManifestConditions: [][]metav1.Condition{
{{Type: workapiv1.ManifestProgressing, Status: metav1.ConditionTrue, Reason: workapiv1.ConditionRuleEvaluated}},
{{Type: workapiv1.ManifestProgressing, Status: metav1.ConditionFalse, Reason: workapiv1.ConditionRuleEvaluated}},
},
expectedWorkConditions: []metav1.Condition{
{Type: workapiv1.WorkProgressing, Status: metav1.ConditionTrue, Reason: "ConditionRulesAggregated"},
},
},
{
name: "work Progressing is False when no manifest is progressing",
existingResources: []runtime.Object{
testingcommon.NewUnstructuredWithContent(
"v1", "NewObject", "ns1", "n1",
map[string]any{"spec": map[string]any{"key1": "val1"}}),
testingcommon.NewUnstructuredWithContent(
"v1", "NewObject", "ns1", "n2",
map[string]any{"spec": map[string]any{"key1": "val2"}}),
},
configOption: []workapiv1.ManifestConfigOption{
{
ResourceIdentifier: workapiv1.ResourceIdentifier{Resource: "newobjects", Namespace: "ns1", Name: "n1"},
ConditionRules: []workapiv1.ConditionRule{
{
Type: workapiv1.CelConditionExpressionsType,
Condition: workapiv1.ManifestProgressing,
CelExpressions: []string{"false"},
},
},
},
{
ResourceIdentifier: workapiv1.ResourceIdentifier{Resource: "newobjects", Namespace: "ns1", Name: "n2"},
ConditionRules: []workapiv1.ConditionRule{
{
Type: workapiv1.CelConditionExpressionsType,
Condition: workapiv1.ManifestProgressing,
CelExpressions: []string{"false"},
},
},
},
},
manifests: []workapiv1.ManifestCondition{
newManifest("", "v1", "newobjects", "ns1", "n1"),
newManifest("", "v1", "newobjects", "ns1", "n2"),
},
expectedManifestConditions: [][]metav1.Condition{
{{Type: workapiv1.ManifestProgressing, Status: metav1.ConditionFalse, Reason: workapiv1.ConditionRuleEvaluated}},
{{Type: workapiv1.ManifestProgressing, Status: metav1.ConditionFalse, Reason: workapiv1.ConditionRuleEvaluated}},
},
expectedWorkConditions: []metav1.Condition{
{Type: workapiv1.WorkProgressing, Status: metav1.ConditionFalse, Reason: "ConditionRulesAggregated"},
},
},
}
for _, c := range cases {