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
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -96,3 +97,16 @@ func LabelFromString(value string) (label *Label, err error) {
|
|||||||
|
|
||||||
return label, nil
|
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")
|
OrderBy("wt.created_at DESC")
|
||||||
|
|
||||||
if filter != nil && len(filter.Labels) > 0 {
|
if filter != nil && len(filter.Labels) > 0 {
|
||||||
sb = sb.Join("labels l ON wt.id = l.resource_id AND l.resource = 'workflow_template'")
|
labelsJSON, err := LabelsToJSONString(filter.Labels)
|
||||||
|
if err != nil {
|
||||||
// Note: multiple labels are not yet supported. The below will not correctly AND label selection.
|
log.Printf("[error] %v", err)
|
||||||
for _, lbl := range filter.Labels {
|
} else {
|
||||||
sb = sb.Where(sq.Eq{
|
sb = sb.Where("wt.labels @> ?", labelsJSON)
|
||||||
"l.key": lbl.Key,
|
|
||||||
"l.value": lbl.Value,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb = *paginator.ApplyToSelect(&sb)
|
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
|
//Verify the cloned template name doesn't exist already
|
||||||
|
|
||||||
templatesCount, err := client.CountWorkflowTemplatesByName(req.Name, req.Name, nil)
|
templatesCount, err := client.CountWorkflowTemplatesByName(req.Name, req.Name, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Reference in New Issue
Block a user