mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-11 08:30:03 +08:00
fix: deleting labels and getting labels for workflow execution
* Fixed issue where ReplaceLabels did not work when no labels were passed in (a delete essentially) * Updated workflow execution to also get the labels * Removed unusued GetResourceIdBuilder method.
This commit is contained in:
@@ -43,21 +43,6 @@ func (c *Client) ListLabels(resource string, uid string) (labels []*Label, err e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetResourceIdBuilder(resource, uid string) (*sq.SelectBuilder, error) {
|
|
||||||
tableName := TypeToTableName(resource)
|
|
||||||
if tableName == "" {
|
|
||||||
return nil, fmt.Errorf("unknown resources '%v'", resource)
|
|
||||||
}
|
|
||||||
|
|
||||||
sb := sb.Select("id").
|
|
||||||
From(tableName).
|
|
||||||
Where(sq.Eq{
|
|
||||||
"uid": uid,
|
|
||||||
})
|
|
||||||
|
|
||||||
return &sb, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) AddLabels(namespace, resource, uid string, keyValues map[string]string) error {
|
func (c *Client) AddLabels(namespace, resource, uid string, keyValues map[string]string) error {
|
||||||
tx, err := c.DB.Begin()
|
tx, err := c.DB.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -122,10 +107,6 @@ func (c *Client) AddLabels(namespace, resource, uid string, keyValues map[string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ReplaceLabels(namespace, resource, uid string, keyValues map[string]string) error {
|
func (c *Client) ReplaceLabels(namespace, resource, uid string, keyValues map[string]string) error {
|
||||||
if len(keyValues) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
tx, err := c.DB.Begin()
|
tx, err := c.DB.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -154,10 +135,6 @@ func (c *Client) ReplaceLabels(namespace, resource, uid string, keyValues map[st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ReplaceLabelsUsingKnownID(namespace, resource string, resourceID uint64, uid string, keyValues map[string]string) error {
|
func (c *Client) ReplaceLabelsUsingKnownID(namespace, resource string, resourceID uint64, uid string, keyValues map[string]string) error {
|
||||||
if len(keyValues) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
tx, err := c.DB.Begin()
|
tx, err := c.DB.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -36,6 +36,7 @@ func apiWorkflowExecution(wf *v1.WorkflowExecution) (workflow *api.WorkflowExecu
|
|||||||
Name: wf.Name,
|
Name: wf.Name,
|
||||||
Phase: string(wf.Phase),
|
Phase: string(wf.Phase),
|
||||||
Manifest: wf.Manifest,
|
Manifest: wf.Manifest,
|
||||||
|
Labels: converter.MappingToKeyValue(wf.Labels),
|
||||||
}
|
}
|
||||||
|
|
||||||
if wf.StartedAt != nil && !wf.StartedAt.IsZero() {
|
if wf.StartedAt != nil && !wf.StartedAt.IsZero() {
|
||||||
@@ -156,6 +157,14 @@ func (s *WorkflowServer) GetWorkflowExecution(ctx context.Context, req *api.GetW
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mappedLabels, err := client.GetDbLabelsMapped(v1.TypeWorkflowExecution, wf.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if labels, ok := mappedLabels[wf.ID]; ok {
|
||||||
|
wf.Labels = labels
|
||||||
|
}
|
||||||
|
|
||||||
return apiWorkflowExecution(wf), nil
|
return apiWorkflowExecution(wf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user