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

return execution id on pipeline execute command #264

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

suhrud-kumar
Copy link

@suhrud-kumar suhrud-kumar commented Jul 19, 2020

We are building a wrapper around spin cli, so if spin cli could execution id then we could use it to poll spinnaker to get the status of the pipeline. Looks like the gate api already returns the pipeline execution id but we are not returning it to user. I made a couple of changes for this to work.

before code changes

spin pipeline execute -a testapp -n samplemicroservice
Pipeline execution started

after

./spin pipeline execute -a testapp -n samplemicroservice
{
 "ref": "/pipelines/01EDK74BBVZ97QPWDXBYWARVH4"
}

I understand the code in gateapi is auto-generated using swagger, so probably something needs to be updated in gate service as well (probably here - https://github.com/spinnaker/gate/blob/master/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/PipelineController.groovy#L198). I'm not well versed with java so I'm not sure what needs to be changed there. I'm updating my code here, so that we know what needs to be changed.

This also fixes - spinnaker/spinnaker#5657

cc: @kevinawoo

@spinnakerbot
Copy link

The following commits need their title changed:

  • 0803295: manual fix to return pipeline execution id

  • 1310ceb: return execution id on pipeline execute command

Please format your commit title into the form:

<type>(<scope>): <subject>, e.g. fix(kubernetes): address NPE in status check

This allows us to easily generate changelogs & determine semantic version numbers when cutting releases. You can read more about commit conventions here.

Copy link
Member

@kevinawoo kevinawoo left a comment

Choose a reason for hiding this comment

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

hey @suhrud-kumar you're right that we need to have the fix in gate.

I'm hesitant to merge this because it's going to get dropped in the next release because we just replace the autogenerated code blindly.

@suhrud-kumar
Copy link
Author

suhrud-kumar commented Jul 21, 2020

hey @suhrud-kumar you're right that we need to have the fix in gate.

I'm hesitant to merge this because it's going to get dropped in the next release because we just replace the autogenerated code blindly.

yes, I agree. I just updated code here so that it could serve as pointer for what needs to be fixed in gate(which i'm not familiar with). Do you want me to open an issue with gate for this ?

@kevinawoo
Copy link
Member

Yeah, you can open a issue in spinnaker/spinnaker to update it and someone else might take it.

@Chinikins
Copy link
Contributor

I don't think this is fixed in the gate yet but I think my PR could help here too: #311 we often need to get the execution IDs for pipelines for various reasons too.

@boonware
Copy link

boonware commented Sep 3, 2021

Any update on this? Looks like Spin CLI still does not support this. It's a crucial feature.

@Chinikins
Copy link
Contributor

could we update this PR with latest master branch? 🙏 Just being able to see the response returned I think would be helpful and enables users to parse it as needed.

@girish-netskope
Copy link

Any updates on this? Its a cruical thing to have.

Copy link
Contributor

@karlskewes karlskewes left a comment

Choose a reason for hiding this comment

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

This PR looks pretty close on initial inspection.
Was there a reason to do the JSON decoding in the swagger generated code instead of in execute.go ?

@@ -87,7 +87,7 @@ func executePipeline(cmd *cobra.Command, options *executeOptions) error {
}
}

resp, err := options.GateClient.PipelineControllerApi.InvokePipelineConfigUsingPOST1(options.GateClient.Context,
successPayload, resp, err := options.GateClient.PipelineControllerApi.InvokePipelineConfigUsingPOST1(options.GateClient.Context,
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing the JSON decoding in the generated file, why not attempt a JSON decode of the response body resp here?

Copy link
Contributor

@karlskewes karlskewes Mar 31, 2023

Choose a reason for hiding this comment

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

It looks like it might be better to use the newer Gate API options.GateClient.PipelineControllerApi.InvokePipelineConfigViaEchoUsingPOST instead.

This returns an interface{} which we can marshal into a new struct, e.g: type executedPipelines struct {...} and then log out.
The struct will hold a list of executed pipelines because a single trigger (spin's POST) can invoke multiple pipelines.

See Gate groovy returned object which would land in the Go empty interface.

    return [
      eventId: eventId,
      ref    : String.format("/pipelines/%s", executionId)
    ]

Per: https://github.com/spinnaker/gate/blob/6e751aa7d7c9a4f116b85b6f4b73d5203d902ce7/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy#L94-L116

Comment on lines +637 to +639
if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
return successPayload, localVarHttpResponse, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be moved to execute.go per my comment above.
Then do a pass to ensure errors are checked and resp.Body is closed, etc.

@shufanhao
Copy link

shall we merge this PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants