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
feat: Customize workfow metadata from event data #4783
feat: Customize workfow metadata from event data #4783
Conversation
@@ -40,6 +40,17 @@ type Submit struct { | |||
// WorkflowTemplateRef the workflow template to submit | |||
WorkflowTemplateRef WorkflowTemplateRef `json:"workflowTemplateRef" protobuf:"bytes,1,opt,name=workflowTemplateRef"` | |||
|
|||
// WorkflowName optional means to customize the name of the submitted workflow | |||
WorkflowName *WorkflowName `json:"workflowName,omitempty" protobuf:"bytes,2,opt,name=workflowName"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great.
- We could allow for future changes, e.g. templating labels and annotations.
- We could make the names fully based on the expression environment - no suffix.
metadata:
name: payload.message + timestamp
Useful as follows:
metadata:
name: payload.github.repo + "-" + payload.github.sha1
Maybe in the future:
metadata:
annotations:
sha1: payload.github.sha1
Value *AnyString `json:"value,omitempty" protobuf:"bytes,1,opt,name=value"` | ||
|
||
// ValueFrom is the source for the workflow name | ||
ValueFrom *ValueFrom `json:"valueFrom,omitempty" protobuf:"bytes,2,opt,name=valueFrom"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need value
or valueFrom
at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should I be using instead? I used those to stay somewhat similar to how parameters are defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my comment is irrelevant - I want you to replace workflowName
with metadata
server/event/dispatch/operation.go
Outdated
|
||
// Prevent expressions that evaluate to types which will generate invalid names. | ||
switch v := result.(type) { | ||
case string: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can just return v, nil
here
@alexec The codegen check is failing. The comment in the PR creation form says to run "make codegen" to fix it. When I run that nothing changes in the git repo. Any ideas on what I can try? |
Option 1
|
@alexec I reworked the change to fix your comments. However, codegen is still failing. It's complaining about the changes I made to the operation_test.go file. Why is that? I assume you'd want unit tests added for this change. |
You need to apply this patch to fix the codegen issue:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great - thank you for going above-and-beyond with also implementing labels and annotations - I wasn't expecting this!
// Arguments extracted from the event and then set as arguments to the workflow created. | ||
Arguments *Arguments `json:"arguments,omitempty" protobuf:"bytes,2,opt,name=arguments"` | ||
Arguments *Arguments `json:"arguments,omitempty" protobuf:"bytes,3,opt,name=arguments"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is important not to change these numbers as it breaks clients - can you leave this as 3 and make metadata 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew I shouldn't have done that. Fixed.
server/event/dispatch/operation.go
Outdated
return nil, err | ||
} | ||
|
||
if len(wf.Name) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor - I'd prefer wf.Name == ""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if err != nil { | ||
return err | ||
} | ||
wf.Labels[labelKey] = evalLabel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might need to check if wf.Labels == nil
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Did the same for annotations.
server/event/dispatch/operation.go
Outdated
return "", fmt.Errorf("failed to evaluate workflow %s expression: %w", errorInfo, err) | ||
} | ||
|
||
switch v := result.(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor - v, ok := result.(string)
is a more conventional way of doing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks for showing me this.
Signed-off-by: Michael Albers <michael.john.albers@gmail.com>
Signed-off-by: Michael Albers <michael.john.albers@gmail.com>
Signed-off-by: Michael Albers <michael.john.albers@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I wonder if this supports getting name from metadata (HTTP headers), I tried following but got errors in argo-server:
|
Signed-off-by: Michael Albers michael.john.albers@gmail.com
Checklist:
Fixes #4640