Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add pod name format annotation. Fixes #6962 and #6989 #6982

Merged
merged 3 commits into from
Oct 29, 2021

Conversation

JPZ13
Copy link
Member

@JPZ13 JPZ13 commented Oct 19, 2021

Signed-off-by: J.P. Zivalich jp@pipekit.io

This PR:

  • Adds the pod name version as an annotation to a workflow
  • Displays ui logs for a given workflow based on the annotation
  • Adds a function to get a template name from a template ref

Fixes #6962 and #6989

@codecov
Copy link

codecov bot commented Oct 19, 2021

Codecov Report

Merging #6982 (f4c7cee) into master (64fce4a) will decrease coverage by 0.03%.
The diff coverage is 48.00%.

❗ Current head f4c7cee differs from pull request most recent head 5d72b97. Consider uploading reports for the commit 5d72b97 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6982      +/-   ##
==========================================
- Coverage   48.55%   48.52%   -0.04%     
==========================================
  Files         265      265              
  Lines       19329    19367      +38     
==========================================
+ Hits         9386     9398      +12     
- Misses       8892     8914      +22     
- Partials     1051     1055       +4     
Impacted Files Coverage Δ
workflow/common/common.go 80.00% <ø> (ø)
workflow/util/pod_name.go 48.00% <31.57%> (+1.33%) ⬆️
workflow/controller/operator.go 71.62% <100.00%> (+0.08%) ⬆️
util/tls/tls.go 52.17% <0.00%> (-12.12%) ⬇️
workflow/metrics/server.go 13.23% <0.00%> (-6.07%) ⬇️
config/config.go 28.57% <0.00%> (-3.01%) ⬇️
cmd/argo/commands/get.go 58.30% <0.00%> (-0.59%) ⬇️
workflow/controller/workflowpod.go 73.89% <0.00%> (-0.52%) ⬇️
workflow/controller/controller.go 22.53% <0.00%> (-0.07%) ⬇️
workflow/metrics/metrics.go 76.11% <0.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64fce4a...5d72b97. Read the comment docs.

@JPZ13
Copy link
Member Author

JPZ13 commented Oct 20, 2021

@tczhao I validated that the default v2 logs are showing up properly. I have some other obligations to attend to this evening and can't validate the v1 path until tomorrow. In the meantime, are you free to review?

@tczhao
Copy link
Member

tczhao commented Oct 20, 2021

Thanks @JPZ13, will take a look in my afternoon


// setWfPodNamesAnnotation sets an annotation on a workflow with the pod naming
// convention version
func setWfPodNamesAnnotation(wf *wfv1.Workflow) {
Copy link
Member

@tczhao tczhao Oct 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe need a test for this function, the rest looks good

@@ -142,6 +142,8 @@ func newWorkflowOperationCtx(wf *wfv1.Workflow, wfc *WorkflowController) *wfOper
// You can use DeepCopy() to make a deep copy of original object and modify this copy
// Or create a copy manually for better performance
wfCopy := wf.DeepCopyObject().(*wfv1.Workflow)
setWfPodNamesAnnotation(wfCopy)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking perhaps if we should annotate at pod level instead?
so that in rolling upgrade (podname v1->v2), we won't end up having a workflow that has first n pods using v1 but get annotated as v2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. @tczhao can you help me with these two questions to clarify my mental model?:

  1. Does newWorkflowOperationCtx get invoked in the case of a rolling upgrade? If so, when and where?
  2. Are pod annotations persisted when the workflow is archived? If so, where can I get them from?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think newWorkflowOperationCtx get invoked at least every time when there's a workflow update e.g. pod finished
  2. good point, pod annotation doesn't persist in workflow crd

I wonder if we can only add annotation for new workflow
or just accept this as a caveat

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to support rolling upgrades. In that case, workflows are either:

  • Complete, not annotated - v1.
  • Already running, not annotated - therefore v1.
  • New (status.pending="") - annotate with pod name version from config.
  • Already running, annotated - use annotation.

I think that means we can be confident of which format we are using.

There is a specific block of code which sets up new workflows:

https://github.com/argoproj/argo-workflows/blob/master/workflow/controller/operator.go#L264

That's the place to add the annotation.

@JPZ13 JPZ13 changed the title fix: Add pod name format annotation. Fixes #6962 fix: Add pod name format annotation. Fixes #6962 and #6989 Oct 20, 2021
@tczhao
Copy link
Member

tczhao commented Oct 21, 2021

Hi @JPZ13 ,
I thought it's more relevant here since this PR is about pod name v1/v2 mappings

I think we need to modify this

public getContainerLogs(workflow: Workflow, nodeId: string, container: string, grep: string, archived: boolean): Observable<LogEntry> {
const getLogsFromArtifact = () => this.getContainerLogsFromArtifact(workflow, nodeId, container, grep, archived);
// If our workflow is archived, don't even bother inspecting the cluster for logs since it's likely
// that the Workflow and associated pods have been deleted
if (archived) {
return getLogsFromArtifact();
}
// return archived log if main container is finished and has artifact
return Observable.fromPromise(this.isWorkflowNodePendingOrRunning(workflow, nodeId)).switchMap(isPendingOrRunning => {
if (!isPendingOrRunning && this.hasArtifactLogs(workflow, nodeId, container) && container === 'main') {
return getLogsFromArtifact();
}
return this.getContainerLogsFromCluster(workflow, nodeId, container, grep).catch(getLogsFromArtifact);
});
}

to have the live log uses podname and the archive log uses nodeId

backend:
(live: find log using pod name in k8s)
(archive: find archived log location using workflow[nodeId])

this should solve #6947

@JPZ13
Copy link
Member Author

JPZ13 commented Oct 22, 2021

Thanks for the heads up on that @tczhao! I'm hopefully gonna get this PR wrapped up this weekend. Can I get your eyes on it once complete?

@JPZ13 JPZ13 marked this pull request as ready for review October 23, 2021 23:46
@tczhao
Copy link
Member

tczhao commented Oct 26, 2021

LGTM

ui/package.json Outdated
@@ -12,6 +12,7 @@
"test": "jest"
},
"dependencies": {
"@types/lodash": "^4.14.175",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this library has security vulns, can we avoid it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure!

return workflowName;
}

let prefix = `${workflowName}-${templateName}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor - inline

return node.templateName;
}

const name = get(node, 'templateRef.template');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor - inline

@@ -142,6 +142,8 @@ func newWorkflowOperationCtx(wf *wfv1.Workflow, wfc *WorkflowController) *wfOper
// You can use DeepCopy() to make a deep copy of original object and modify this copy
// Or create a copy manually for better performance
wfCopy := wf.DeepCopyObject().(*wfv1.Workflow)
setWfPodNamesAnnotation(wfCopy)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to support rolling upgrades. In that case, workflows are either:

  • Complete, not annotated - v1.
  • Already running, not annotated - therefore v1.
  • New (status.pending="") - annotate with pod name version from config.
  • Already running, annotated - use annotation.

I think that means we can be confident of which format we are using.

There is a specific block of code which sets up new workflows:

https://github.com/argoproj/argo-workflows/blob/master/workflow/controller/operator.go#L264

That's the place to add the annotation.

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Add annotation reading to ui

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Refactor get annotations

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Fix lint error

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Fix template names for template refs

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Fix linting errors

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Fix live logs vs archived logs

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Fix failing unit test

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Add test

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Change wf marking location

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Update ui

Signed-off-by: J.P. Zivalich <jp@pipekit.io>

Remove lodash

Signed-off-by: J.P. Zivalich <jp@pipekit.io>
@JPZ13
Copy link
Member Author

JPZ13 commented Oct 28, 2021

Updated for your changes @alexec

Signed-off-by: J.P. Zivalich <jp@pipekit.io>
const (
// PodNameVersion1 is the v1 name that uses node ids for pod names
PodNameVersion1 PodNameVersion = "v1"
// PodNameVersion2 is the v2 name that uses workflow name combined with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

um, nodeID + templateName?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor PodNameV1

Copy link
Contributor

@alexec alexec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see minor comments

Signed-off-by: J.P. Zivalich <jp@pipekit.io>
@alexec alexec merged commit 1e87159 into argoproj:master Oct 29, 2021
@alexec alexec mentioned this pull request Nov 5, 2021
25 tasks
@sarabala1979 sarabala1979 mentioned this pull request Dec 15, 2021
73 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants