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:
Andrey Melnikov
2020-05-17 13:25:08 -07:00
parent b9ccacc2ea
commit f8d7ec73ba
2 changed files with 9 additions and 23 deletions

View File

@@ -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

View File

@@ -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
} }