Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Count Workflows with no phase as Pending for metrics #4628

Merged
merged 3 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion workflow/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ var indexers = cache.Indexers{
indexes.CronWorkflowIndex: indexes.MetaNamespaceLabelIndexFunc(common.LabelKeyCronWorkflow),
indexes.WorkflowTemplateIndex: indexes.MetaNamespaceLabelIndexFunc(common.LabelKeyWorkflowTemplate),
indexes.SemaphoreConfigIndexName: indexes.WorkflowSemaphoreKeysIndexFunc(),
indexes.WorkflowPhaseIndex: indexes.MetaLabelIndexFunc(common.LabelKeyPhase),
indexes.WorkflowPhaseIndex: indexes.MetaWorkflowPhaseIndexFunc(),
}

// Run starts an Workflow resource controller
Expand Down
10 changes: 7 additions & 3 deletions workflow/controller/indexes/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ import (

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/tools/cache"

"github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/workflow/common"
)

func MetaNamespaceLabelIndex(namespace, label string) string {
return namespace + "/" + label
}

func MetaLabelIndexFunc(label string) cache.IndexFunc {
func MetaWorkflowPhaseIndexFunc() cache.IndexFunc {
return func(obj interface{}) ([]string, error) {
v, err := meta.Accessor(obj)
if err != nil {
return []string{}, fmt.Errorf("object has no meta: %v", err)
}
if value, exists := v.GetLabels()[label]; exists {
if value, exists := v.GetLabels()[common.LabelKeyPhase]; exists {
return []string{value}, nil
} else {
return []string{}, nil
// If the object doesn't have a phase set, consider it pending
return []string{string(v1alpha1.NodePending)}, nil
Comment on lines +26 to +27
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was our previous behavior.

}
}
}
Expand Down
13 changes: 11 additions & 2 deletions workflow/controller/indexes/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/workflow/common"
)

func TestMetaNamespaceLabelIndex(t *testing.T) {
Expand All @@ -30,13 +31,21 @@ func TestMetaNamespaceLabelIndexFunc(t *testing.T) {
assert.ElementsMatch(t, values, []string{"my-ns/my-value"})
})
t.Run("Labelled No Namespace", func(t *testing.T) {
values, err := MetaLabelIndexFunc("my-label")(&wfv1.Workflow{
values, err := MetaWorkflowPhaseIndexFunc()(&wfv1.Workflow{
ObjectMeta: metav1.ObjectMeta{
Namespace: "my-ns",
Labels: map[string]string{"my-label": "my-value"},
Labels: map[string]string{common.LabelKeyPhase: "my-value"},
},
})
assert.NoError(t, err)
assert.ElementsMatch(t, values, []string{"my-value"})
})

t.Run("Labelled No Phase", func(t *testing.T) {
values, err := MetaWorkflowPhaseIndexFunc()(&wfv1.Workflow{
ObjectMeta: metav1.ObjectMeta{},
})
assert.NoError(t, err)
assert.ElementsMatch(t, values, []string{string(wfv1.NodePending)})
})
}