Refactored name to uid.

This commit is contained in:
Aleksandr Melnikov
2020-05-13 15:44:34 -07:00
committed by rushtehrani
parent 460b7c0604
commit 735b10c025
2 changed files with 62 additions and 60 deletions

View File

@@ -467,7 +467,7 @@ func (c *Client) FinishWorkflowExecutionStatisticViaExitHandler(namespace, name
return err
}
func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, name string, workflowTemplateID int64) (err error) {
func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, uid string, workflowTemplateID int64) (err error) {
query, args, err := c.workflowTemplatesSelectBuilder(namespace).
Where(sq.Eq{
"wt.id": workflowTemplateID,
@@ -515,7 +515,7 @@ func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, name strin
insertMap := sq.Eq{
"uid": cronUid,
"workflow_template_version_id": cronWorkflow.WorkflowTemplateVersionId,
"name": name,
"name": uid,
"namespace": namespace,
"phase": wfv1.NodePending,
"cron_workflow_id": cronWorkflow.ID,
@@ -737,12 +737,12 @@ func (c *Client) WatchWorkflowExecution(namespace, uid string) (<-chan *Workflow
return workflowWatcher, nil
}
func (c *Client) GetWorkflowExecutionLogs(namespace, name, podName, containerName string) (<-chan *LogEntry, error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(name, metav1.GetOptions{})
func (c *Client) GetWorkflowExecutionLogs(namespace, uid, podName, containerName string) (<-chan *LogEntry, error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(uid, metav1.GetOptions{})
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"PodName": podName,
"ContainerName": containerName,
"Error": err.Error(),
@@ -762,7 +762,7 @@ func (c *Client) GetWorkflowExecutionLogs(namespace, name, podName, containerNam
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"PodName": podName,
"ContainerName": containerName,
"Error": err.Error(),
@@ -774,7 +774,7 @@ func (c *Client) GetWorkflowExecutionLogs(namespace, name, podName, containerNam
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"PodName": podName,
"ContainerName": containerName,
"Error": err.Error(),
@@ -788,7 +788,8 @@ func (c *Client) GetWorkflowExecutionLogs(namespace, name, podName, containerNam
return nil, util.NewUserError(codes.InvalidArgument, "Invaild range.")
}
opts.SetRange(0, int64(endOffset))
stream, err = s3Client.GetObject(config[ArtifactRepositoryBucketKey], "artifacts/"+namespace+"/"+name+"/"+podName+"/"+containerName+".log", opts)
stream, err = s3Client.GetObject(config[ArtifactRepositoryBucketKey], "artifacts/"+namespace+"/"+uid+"/"+podName+"/"+containerName+".log", opts)
} else {
stream, err = c.CoreV1().Pods(namespace).GetLogs(podName, &corev1.PodLogOptions{
Container: containerName,
@@ -801,7 +802,7 @@ func (c *Client) GetWorkflowExecutionLogs(namespace, name, podName, containerNam
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"PodName": podName,
"ContainerName": containerName,
"Error": err.Error(),
@@ -832,8 +833,8 @@ func (c *Client) GetWorkflowExecutionLogs(namespace, name, podName, containerNam
return logWatcher, err
}
func (c *Client) GetWorkflowExecutionMetrics(namespace, name, podName string) (metrics []*Metric, err error) {
_, err = c.GetWorkflowExecution(namespace, name)
func (c *Client) GetWorkflowExecutionMetrics(namespace, uid, podName string) (metrics []*Metric, err error) {
_, err = c.GetWorkflowExecution(namespace, uid)
if err != nil {
return nil, util.NewUserError(codes.NotFound, "Workflow not found.")
}
@@ -848,7 +849,7 @@ func (c *Client) GetWorkflowExecutionMetrics(namespace, name, podName string) (m
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"PodName": podName,
"Error": err.Error(),
}).Error("Can't get configuration.")
@@ -859,7 +860,7 @@ func (c *Client) GetWorkflowExecutionMetrics(namespace, name, podName string) (m
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"PodName": podName,
"Error": err.Error(),
}).Error("Can't connect to S3 storage.")
@@ -867,11 +868,12 @@ func (c *Client) GetWorkflowExecutionMetrics(namespace, name, podName string) (m
}
opts := s3.GetObjectOptions{}
stream, err = s3Client.GetObject(config[ArtifactRepositoryBucketKey], "artifacts/"+namespace+"/"+name+"/"+podName+"/sys-metrics.json", opts)
stream, err = s3Client.GetObject(config[ArtifactRepositoryBucketKey], "artifacts/"+namespace+"/"+uid+"/"+podName+"/sys-metrics.json", opts)
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"PodName": podName,
"Error": err.Error(),
}).Error("Metrics do not exist.")
@@ -881,7 +883,7 @@ func (c *Client) GetWorkflowExecutionMetrics(namespace, name, podName string) (m
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"PodName": podName,
"Error": err.Error(),
}).Error("Unknown.")
@@ -894,7 +896,7 @@ func (c *Client) GetWorkflowExecutionMetrics(namespace, name, podName string) (m
if err = json.Unmarshal(content, &metrics); err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"PodName": podName,
"Error": err.Error(),
}).Error("Error parsing metrics.")
@@ -904,8 +906,8 @@ func (c *Client) GetWorkflowExecutionMetrics(namespace, name, podName string) (m
return
}
func (c *Client) RetryWorkflowExecution(namespace, name string) (workflow *WorkflowExecution, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(name, metav1.GetOptions{})
func (c *Client) RetryWorkflowExecution(namespace, uid string) (workflow *WorkflowExecution, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(uid, metav1.GetOptions{})
if err != nil {
return
}
@@ -917,8 +919,8 @@ func (c *Client) RetryWorkflowExecution(namespace, name string) (workflow *Workf
return
}
func (c *Client) ResubmitWorkflowExecution(namespace, name string) (workflow *WorkflowExecution, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(name, metav1.GetOptions{})
func (c *Client) ResubmitWorkflowExecution(namespace, uid string) (workflow *WorkflowExecution, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(uid, metav1.GetOptions{})
if err != nil {
return
}
@@ -938,26 +940,26 @@ func (c *Client) ResubmitWorkflowExecution(namespace, name string) (workflow *Wo
return
}
func (c *Client) ResumeWorkflowExecution(namespace, name string) (workflow *WorkflowExecution, err error) {
err = argoutil.ResumeWorkflow(c.ArgoprojV1alpha1().Workflows(namespace), name, "")
func (c *Client) ResumeWorkflowExecution(namespace, uid string) (workflow *WorkflowExecution, err error) {
err = argoutil.ResumeWorkflow(c.ArgoprojV1alpha1().Workflows(namespace), uid, "")
if err != nil {
return
}
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(name, metav1.GetOptions{})
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(uid, metav1.GetOptions{})
workflow = typeWorkflow(wf)
return
}
func (c *Client) SuspendWorkflowExecution(namespace, name string) (err error) {
err = argoutil.SuspendWorkflow(c.ArgoprojV1alpha1().Workflows(namespace), name)
func (c *Client) SuspendWorkflowExecution(namespace, uid string) (err error) {
err = argoutil.SuspendWorkflow(c.ArgoprojV1alpha1().Workflows(namespace), uid)
return
}
func (c *Client) TerminateWorkflowExecution(namespace, name string) (err error) {
func (c *Client) TerminateWorkflowExecution(namespace, uid string) (err error) {
query := `DELETE FROM workflow_executions
USING workflow_template_versions, workflow_templates
WHERE workflow_executions.workflow_template_version_id = workflow_template_versions.id
@@ -965,16 +967,16 @@ func (c *Client) TerminateWorkflowExecution(namespace, name string) (err error)
AND workflow_templates.namespace = $1
AND workflow_executions.name = $2`
if _, err := c.DB.Exec(query, namespace, name); err != nil {
if _, err := c.DB.Exec(query, namespace, uid); err != nil {
return err
}
err = argoutil.TerminateWorkflow(c.ArgoprojV1alpha1().Workflows(namespace), name)
err = argoutil.TerminateWorkflow(c.ArgoprojV1alpha1().Workflows(namespace), uid)
return
}
func (c *Client) GetArtifact(namespace, name, key string) (data []byte, err error) {
func (c *Client) GetArtifact(namespace, uid, key string) (data []byte, err error) {
config, err := c.GetNamespaceConfig(namespace)
if err != nil {
return
@@ -990,7 +992,7 @@ func (c *Client) GetArtifact(namespace, name, key string) (data []byte, err erro
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"Key": key,
"Error": err.Error(),
}).Error("Metrics do not exist.")
@@ -1120,12 +1122,12 @@ func filterOutCustomTypesFromManifest(manifest []byte) (result []byte, err error
// prefix is the label prefix.
// e.g. prefix/my-label-key: my-label-value
func (c *Client) GetWorkflowExecutionLabels(namespace, name, prefix string) (labels map[string]string, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(name, metav1.GetOptions{})
func (c *Client) GetWorkflowExecutionLabels(namespace, uid, prefix string) (labels map[string]string, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(uid, metav1.GetOptions{})
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"Error": err.Error(),
}).Error("Workflow not found.")
return nil, util.NewUserError(codes.NotFound, "Workflow not found.")
@@ -1137,12 +1139,12 @@ func (c *Client) GetWorkflowExecutionLabels(namespace, name, prefix string) (lab
return
}
func (c *Client) DeleteWorkflowExecutionLabel(namespace, name string, keysToDelete ...string) (labels map[string]string, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(name, metav1.GetOptions{})
func (c *Client) DeleteWorkflowExecutionLabel(namespace, uid string, keysToDelete ...string) (labels map[string]string, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(uid, metav1.GetOptions{})
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"Error": err.Error(),
}).Error("Workflow not found.")
return nil, util.NewUserError(codes.NotFound, "Workflow not found.")
@@ -1153,12 +1155,12 @@ func (c *Client) DeleteWorkflowExecutionLabel(namespace, name string, keysToDele
return wf.Labels, nil
}
func (c *Client) DeleteWorkflowTemplateLabel(namespace, name string, keysToDelete ...string) (labels map[string]string, err error) {
wf, err := c.ArgoprojV1alpha1().WorkflowTemplates(namespace).Get(name, metav1.GetOptions{})
func (c *Client) DeleteWorkflowTemplateLabel(namespace, uid string, keysToDelete ...string) (labels map[string]string, err error) {
wf, err := c.ArgoprojV1alpha1().WorkflowTemplates(namespace).Get(uid, metav1.GetOptions{})
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"Error": err.Error(),
}).Error("Workflow Template not found.")
return nil, util.NewUserError(codes.NotFound, "Workflow Template not found.")
@@ -1172,12 +1174,12 @@ func (c *Client) DeleteWorkflowTemplateLabel(namespace, name string, keysToDelet
// prefix is the label prefix.
// we delete all labels with that prefix and set the new ones
// e.g. prefix/my-label-key: my-label-value
func (c *Client) SetWorkflowExecutionLabels(namespace, name, prefix string, keyValues map[string]string, deleteOld bool) (workflowLabels map[string]string, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(name, metav1.GetOptions{})
func (c *Client) SetWorkflowExecutionLabels(namespace, uid, prefix string, keyValues map[string]string, deleteOld bool) (workflowLabels map[string]string, err error) {
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(uid, metav1.GetOptions{})
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"Error": err.Error(),
}).Error("Workflow not found.")
return nil, util.NewUserError(codes.NotFound, "Workflow not found.")
@@ -1203,12 +1205,12 @@ func (c *Client) SetWorkflowExecutionLabels(namespace, name, prefix string, keyV
// prefix is the label prefix.
// we delete all labels with that prefix and set the new ones
// e.g. prefix/my-label-key: my-label-value
func (c *Client) SetWorkflowTemplateLabels(namespace, name, prefix string, keyValues map[string]string, deleteOld bool) (workflowLabels map[string]string, err error) {
wf, err := c.getArgoWorkflowTemplate(namespace, name, "latest")
func (c *Client) SetWorkflowTemplateLabels(namespace, uid, prefix string, keyValues map[string]string, deleteOld bool) (workflowLabels map[string]string, err error) {
wf, err := c.getArgoWorkflowTemplate(namespace, uid, "latest")
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"UID": uid,
"Error": err.Error(),
}).Error("Workflow Template not found.")
return nil, util.NewUserError(codes.NotFound, "Workflow Template not found.")