mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-06 06:06:50 +08:00
update: updated logic to filter workflow templates by labels. It now supports AND so you can filter by multiple labels
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -96,3 +97,16 @@ func LabelFromString(value string) (label *Label, err error) {
|
||||
|
||||
return label, nil
|
||||
}
|
||||
|
||||
// LabelsToJSONString converts an array of labels to a json string representing an object
|
||||
// where the keys are the label keys and the values are the label values
|
||||
func LabelsToJSONString(labels []*Label) (string, error) {
|
||||
labelMap := LabelsToMapping(labels...)
|
||||
|
||||
resultBytes, err := json.Marshal(labelMap)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(resultBytes), nil
|
||||
}
|
||||
|
@@ -409,14 +409,11 @@ func (c *Client) selectWorkflowTemplatesQuery(namespace string, paginator *pagin
|
||||
OrderBy("wt.created_at DESC")
|
||||
|
||||
if filter != nil && len(filter.Labels) > 0 {
|
||||
sb = sb.Join("labels l ON wt.id = l.resource_id AND l.resource = 'workflow_template'")
|
||||
|
||||
// Note: multiple labels are not yet supported. The below will not correctly AND label selection.
|
||||
for _, lbl := range filter.Labels {
|
||||
sb = sb.Where(sq.Eq{
|
||||
"l.key": lbl.Key,
|
||||
"l.value": lbl.Value,
|
||||
})
|
||||
labelsJSON, err := LabelsToJSONString(filter.Labels)
|
||||
if err != nil {
|
||||
log.Printf("[error] %v", err)
|
||||
} else {
|
||||
sb = sb.Where("wt.labels @> ?", labelsJSON)
|
||||
}
|
||||
}
|
||||
sb = *paginator.ApplyToSelect(&sb)
|
||||
|
@@ -136,7 +136,6 @@ func (s *WorkflowTemplateServer) CloneWorkflowTemplate(ctx context.Context, req
|
||||
}
|
||||
|
||||
//Verify the cloned template name doesn't exist already
|
||||
|
||||
templatesCount, err := client.CountWorkflowTemplatesByName(req.Name, req.Name, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user