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

feat: Support disable retrieval of label values for certain keys #9999

Merged
merged 1 commit into from Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 7 additions & 6 deletions docs/environment-variables.md
Expand Up @@ -148,9 +148,10 @@ data:

## Argo Server

| Name | Type | Default | Description |
|-------------------------|----------|---------|------------------------------------------------------------------------------------------------------------------------------|
| `FIRST_TIME_USER_MODAL` | `bool` | `true` | Show this modal. |
| `FEEDBACK_MODAL` | `bool` | `true` | Show this modal. |
| `NEW_VERSION_MODAL` | `bool` | `true` | Show this modal. |
| `POD_NAMES` | `string` | `v2` | Whether to have pod names contain the template name (v2) or be the node id (v1) - should be set the same for Controller |
| Name | Type | Default | Description |
|--------------------------------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------------|
| `DISABLE_VALUE_LIST_RETRIEVAL_KEY_PATTERN` | `string` | `""` | Disable the retrieval of the list of label values for keys based on this regular expression. |
| `FIRST_TIME_USER_MODAL` | `bool` | `true` | Show this modal. |
| `FEEDBACK_MODAL` | `bool` | `true` | Show this modal. |
| `NEW_VERSION_MODAL` | `bool` | `true` | Show this modal. |
| `POD_NAMES` | `string` | `v2` | Whether to have pod names contain the template name (v2) or be the node id (v1) - should be set the same for Controller |
17 changes: 17 additions & 0 deletions server/workflowarchive/archived_workflow_server.go
Expand Up @@ -3,6 +3,8 @@ package workflowarchive
import (
"context"
"fmt"
"os"
"regexp"
"sort"
"strconv"
"strings"
Expand All @@ -24,6 +26,8 @@ import (
"github.com/argoproj/argo-workflows/v3/workflow/util"
)

const disableValueListRetrievalKeyPattern = "DISABLE_VALUE_LIST_RETRIEVAL_KEY_PATTERN"

type archivedWorkflowServer struct {
wfArchive sqldb.WorkflowArchive
}
Expand Down Expand Up @@ -184,6 +188,15 @@ func (w *archivedWorkflowServer) ListArchivedWorkflowLabelKeys(ctx context.Conte
return labelkeys, nil
}

func matchLabelKeyPattern(key string) bool {
pattern, _ := os.LookupEnv(disableValueListRetrievalKeyPattern)
if pattern == "" {
return false
}
match, _ := regexp.MatchString(pattern, key)
return match
}

func (w *archivedWorkflowServer) ListArchivedWorkflowLabelValues(ctx context.Context, req *workflowarchivepkg.ListArchivedWorkflowLabelValuesRequest) (*wfv1.LabelValues, error) {
options := req.ListOptions

Expand All @@ -202,6 +215,10 @@ func (w *archivedWorkflowServer) ListArchivedWorkflowLabelValues(ctx context.Con
} else {
return nil, fmt.Errorf("operation %v is not supported", requirement.Operator())
}
if matchLabelKeyPattern(key) {
log.WithFields(log.Fields{"labelKey": key}).Info("Skipping retrieving the list of values for label key")
return &wfv1.LabelValues{Items: []string{}}, nil
}

labels, err := w.wfArchive.ListWorkflowsLabelValues(key)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions server/workflowarchive/archived_workflow_server_test.go
Expand Up @@ -2,6 +2,7 @@ package workflowarchive

import (
"context"
"os"
"testing"
"time"

Expand Down Expand Up @@ -190,6 +191,15 @@ func Test_archivedWorkflowServer(t *testing.T) {
resp, err := w.ListArchivedWorkflowLabelValues(ctx, &workflowarchivepkg.ListArchivedWorkflowLabelValuesRequest{ListOptions: &metav1.ListOptions{LabelSelector: "my-key"}})
assert.NoError(t, err)
assert.Len(t, resp.Items, 2)

assert.False(t, matchLabelKeyPattern("my-key"))
_ = os.Setenv(disableValueListRetrievalKeyPattern, "my-key")
assert.True(t, matchLabelKeyPattern("my-key"))
assert.False(t, matchLabelKeyPattern("wrong key"))
resp, err = w.ListArchivedWorkflowLabelValues(ctx, &workflowarchivepkg.ListArchivedWorkflowLabelValuesRequest{ListOptions: &metav1.ListOptions{LabelSelector: "my-key"}})
assert.NoError(t, err)
assert.Len(t, resp.Items, 0)
_ = os.Unsetenv(disableValueListRetrievalKeyPattern)
})
t.Run("RetryArchivedWorkflow", func(t *testing.T) {
_, err := w.RetryArchivedWorkflow(ctx, &workflowarchivepkg.RetryArchivedWorkflowRequest{Uid: "failed-uid"})
Expand Down