-
Notifications
You must be signed in to change notification settings - Fork 250
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
--dry-run Option for tkn pipeline start #643
Conversation
The following is the coverage report on pkg/.
|
@@ -376,6 +381,10 @@ func getOptionsByType(resources resourceOptionsFilter, restype string) []string | |||
|
|||
func (opt *startOptions) startPipeline(pName string) error { | |||
pr := &v1alpha1.PipelineRun{ | |||
TypeMeta: metav1.TypeMeta{ | |||
APIVersion: "tekton.dev/v1alpha1", |
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.
How to specify the APIVersion seems difficult. This could maybe be pulled from the pipeline?
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 we would want at least to have it in a global since that string is scattered everywhere, but that's a refactoring that can be done for later....
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 it's fine for now, but indeed, good question. I would guess we default to a hard coded version, and we could have some smart code that checks what api version are available in the cluster (and adjust from it or error out from there)
pkg/cmd/pipeline/start.go
Outdated
return err | ||
} | ||
|
||
if err := ioutil.WriteFile(opt.DryRun, prBytes, os.ModePerm); err != nil { |
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 do not have unit tests for this since it writes a local file. Would it make sense to write the file and then delete it as part of the unit test?
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.
not sure if that's the proper way but that's how i would do it 😅
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.
Sure, I'll try it.
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.
Wondering if this approach is the right way here, but there are at least unit tests for errors/marshaling the pipelinerun.
I like the idea! thinking about it, what do you think about |
🤔 Yeah, I could see this. So potentially convert |
The following is the coverage report on pkg/.
|
The following is the coverage report on pkg/.
|
The following is the coverage report on pkg/.
|
The following is the coverage report on pkg/.
|
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.
Any reason to have the -f
? Doesn't tkn pipeline start --dry-run -o yaml > foo.yaml
work ? (and its equivalent in Powershell
).
We are using -f
as input elsewhere in tkn
, and I also wonder what happens we want some input
someday ? I think, the initial bet is to use stdout
and let other tools that can manage stdout
do there thing.
To add more to my previous comment, I wanna be able to do something like |
humm yeah make sense, sorry @danielhelfand that i made. you change it 🙇 |
Yeah, that makes sense. I can see scenarios where you don't actually want to output a file so makes sense. Also makes it easier to write tests for. Would |
Yes 👼 |
namespace: "", | ||
input: cs2, | ||
wantError: false, | ||
want: `apiVersion: tekton.dev/v1alpha1 |
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 these should be golden files, but I think it would be better to refactor these to golden files in a separate pr.
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.
Yes they should be golden files 👼 Could be done now or in a follow-up, as you want 😉
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.
Will refactor them all in a separate pr.
The following is the coverage report on pkg/.
|
} | ||
|
||
if format == "json" { | ||
prBytes, err := json.MarshalIndent(pr, "", "\t") |
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 do something besides tab for indent if there are thoughts on that.
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.
no idea 😅
I think kubectl
prints it without indent
and let the user pass it through a tool for indent ?
/cc @chmouel
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 guess I would like the indent here if the behavior is to print for the end user to see.
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.
they are spaces on kubectl output or at least according to whitespace-mode in emacs
as long it's yamllint compatible i think it's fine for me!
I guess I would like the indent here if the behavior is to print for the end user to see.
It's fine either way? printed to end user or not we could do indent?
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.
Without the indent, it's all crammed to the left like below:
{
"kind": "PipelineRun",
"apiVersion": "tekton.dev/v1alpha1",
"metadata": {
"generateName": "deploy-pipeline-run-",
"namespace": "default",
"creationTimestamp": null
},
"spec": {
"pipelineRef": {
"name": "deploy-pipeline"
},
"resources": [
{
"name": "app-git",
"resourceRef": {
"name": "nodejs-ex-git"
}
},
{
"name": "app-image",
"resourceRef": {
"name": "nodejs-ex-image"
}
}
],
"serviceAccountName": "default",
"podTemplate": {}
},
"status": {}
}
With the indent, it's as follows:
{
"kind": "PipelineRun",
"apiVersion": "tekton.dev/v1alpha1",
"metadata": {
"generateName": "deploy-pipeline-run-",
"namespace": "default",
"creationTimestamp": null
},
"spec": {
"pipelineRef": {
"name": "deploy-pipeline"
},
"resources": [
{
"name": "app-git",
"resourceRef": {
"name": "nodejs-ex-git"
}
},
{
"name": "app-image",
"resourceRef": {
"name": "nodejs-ex-image"
}
}
],
"serviceAccountName": "default",
"podTemplate": {}
},
"status": {}
}
I think I'll keep as is.
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.
yes please big +1 on indents! any chanced to check if yamllint can validate it ? (i mean not a test but manually)
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.
Yes, it works with yamllint.
@@ -376,6 +381,10 @@ func getOptionsByType(resources resourceOptionsFilter, restype string) []string | |||
|
|||
func (opt *startOptions) startPipeline(pName string) error { | |||
pr := &v1alpha1.PipelineRun{ | |||
TypeMeta: metav1.TypeMeta{ | |||
APIVersion: "tekton.dev/v1alpha1", |
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 it's fine for now, but indeed, good question. I would guess we default to a hard coded version, and we could have some smart code that checks what api version are available in the cluster (and adjust from it or error out from there)
} | ||
|
||
if format == "json" { | ||
prBytes, err := json.MarshalIndent(pr, "", "\t") |
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.
no idea 😅
I think kubectl
prints it without indent
and let the user pass it through a tool for indent ?
/cc @chmouel
namespace: "", | ||
input: cs2, | ||
wantError: false, | ||
want: `apiVersion: tekton.dev/v1alpha1 |
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.
Yes they should be golden files 👼 Could be done now or in a follow-up, as you want 😉
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vdemeester The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The following is the coverage report on pkg/.
|
The following is the coverage report on pkg/.
|
/lgtm Looking Good! 🤙🏽 |
#513 | [Daniel Helfand] update versions in README for 0.6.0 | 2019/12/12-02:36 #514 | [Chmouel Boudjnah] Add info in README about debian installs | 2019/12/12-04:27 #515 | [Chmouel Boudjnah] Change NFPM package name | 2019/12/12-04:44 #516 | [Chmouel Boudjnah] Fix install bash and zsh completion | 2019/12/13-04:55 #518 | [Chmouel Boudjnah] Tektoncd Release 0.9.2 | 2019/12/13-05:37 #508 | [16yuki0702] Making task logs interactive. | 2019/12/16-02:57 #517 | [Daniel Helfand] test for tkn task start --filename | 2019/12/16-03:11 #525 | [Jason Hall] Attempt to fix formatting of examples | 2019/12/18-09:07 #528 | [Chmouel Boudjnah] Set default to False for Show Logs on TaskRun and PipelineRun | 2019/12/18-10:11 #533 | [Daniel Helfand] show cancelled instead of failed for pr and tr desc | 2019/12/19-10:10 null | [Vincent Demeester] Switch to gotest.tools/v3 instead of testify 🐺 | 2019/12/20-04:44 null | [Vincent Demeester] Use ./hack/tools.go instead of dummy_test.go ⚓ | 2019/12/20-05:14 null | [Vincent Demeester] Bump github.com/imdario/mergo to 0.3.8 | 2019/12/20-05:33 null | [Chmouel Boudjnah] Add piyush as an OWNER 🕺 | 2019/12/20-08:04 null | [Piyush Garg] Add triggertemplate list | 2019/12/23-00:08 null | [Piyush Garg] Fix CI | 2019/12/23-10:09 null | [Daniel Helfand] remove namespace check for clustertask | 2019/12/23-10:38 null | [Piyush Garg] Add triggerbinding list | 2019/12/23-14:36 null | [Piyush Garg] Add eventlistener list | 2019/12/26-06:12 null | [Pradeep Kumar] Adds command to delete triggertemplate | 2019/12/26-21:38 null | [Daniel Helfand] converting taskrun desc tests to use step state test builder | 2019/12/27-00:24 null | [Pradeep Kumar] change test name | 2019/12/27-09:20 null | [Pradeep Kumar] Add command to delete triggerbinding | 2019/12/27-11:11 null | [Piyush Garg] Bump hashicorp/golang-lru | 2019/12/28-04:01 null | [Khurram Baig] Add Command to Remove EventListener | 2020/01/02-08:53 null | [Daniel Helfand] error message for using --last with tkn task start -f | 2020/01/02-09:39 null | [16yuki0702] Refactoring pipeline log tests. | 2020/01/02-09:51 null | [Daniel Helfand] updating release notes for CLI | 2020/01/06-07:22 null | [Daniel Helfand] add choco package to README and minor edits | 2020/01/06-08:17 null | [Piyush Garg] Refactor triggertemplate list test | 2020/01/07-00:29 null | [Chmouel Boudjnah] Syncronize cobra to latest | 2020/01/07-09:01 null | [Scott] Update all delete commands to support multiple arguments | 2020/01/08-13:02 null | [16yuki0702] Refactoring pipeline start tests. | 2020/01/09-07:56 null | [Daniel Helfand] add tkn task start -f with remote files | 2020/01/09-10:01 null | [Scott] Refactor delete command code to make a bit more DRY | 2020/01/10-02:49 null | [Daniel Helfand] add nil check for pr desc taskrun sorting | 2020/01/10-07:12 null | [Chmouel Boudjnah] Add coloured status condition | 2020/01/10-15:20 null | [Chmouel Boudjnah] Add colouring to steps status too | 2020/01/13-10:29 null | [Daniel Helfand] correct tkn task start typo | 2020/01/13-14:18 null | [Daniel Helfand] add tkn clustertask start | 2020/01/14-08:29 null | [Daniel Helfand] remove second taskrun from pr desc test | 2020/01/15-00:01 null | [Chmouel Boudjnah] Subtle cosmetics changes to describe command | 2020/01/15-09:58 null | [Chmouel Boudjnah] Show fluffy decorations only when we can or when the user wants it | 2020/01/15-09:58 null | [Chmouel Boudjnah] Fix release tarball version to remove the v at first | 2020/01/15-11:38 null | [Chmouel Boudjnah] Add Namespace to tkn pipeline desc | 2020/01/15-14:57 null | [Chmouel Boudjnah] Fix to auto select the first pipeline when only one is available | 2020/01/16-02:45 null | [Chmouel Boudjnah] Disable TestPipelineLog_Interactive | 2020/01/16-02:45 null | [Daniel Helfand] tkn create command | 2020/01/16-03:32 null | [Chmouel Boudjnah] Do not show bracket when showing the RunAfter.Tasks in Pipeline desc | 2020/01/16-04:07 null | [Chmouel Boudjnah] Set no colours automatically when not running with a tty or a pipe | 2020/01/16-16:33 null | [Chmouel Boudjnah] Skipping flakey interactive tests | 2020/01/17-07:42 null | [Vincent Demeester] Use golden package for unit test for Task 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Use golden package for unit test in TaskRun 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Use golden package for unit test for Pipeline 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Use golden package for unit test for PipelineRun 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Use golden package for unit test for Condition 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Use golden package for unit test for ClusterTask 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Use golden package for unit test for TriggerBinding 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Use golden package for unit test for TriggerTemplate 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Use golden package for unit test for EventListener 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Use golden package for unit test for PipelineResource 🐐 | 2020/01/19-15:20 null | [Vincent Demeester] Add `test-unit-update-golden` target to update golden files 🐟 | 2020/01/19-15:20 null | [Chmouel Boudjnah] generate steps name when none has been provided | 2020/01/20-00:02 null | [Chmouel Boudjnah] Add tests for k8.Condition | 2020/01/20-04:27 null | [Daniel Helfand] add tkn clustertask desc | 2020/01/20-11:11 null | [Chmouel Boudjnah] Add emojis to pipeline/pipelinerun/task/taskrun describe | 2020/01/22-08:40 null | [Chmouel Boudjnah] tkn clustertask describe zsh completion is broken | 2020/01/22-12:21 null | [Chmouel Boudjnah] Add emojis support for tkn clustertask describe command | 2020/01/22-12:44 null | [Piyush Garg] Return error inspite of nil | 2020/01/23-08:28 null | [Chmouel Boudjnah] Implement output for pipeline describe | 2020/01/27-03:07 null | [Daniel Helfand] sort steps for tr desc by StartedAt | 2020/01/28-03:57 null | [Scott] Add flag to task and pipeline to only delete related resources | 2020/01/28-08:47 null | [Vincent Demeester] Remove 🏻 from the step emoji 🍲 | 2020/01/28-10:00 null | [Chmouel Boudjnah] Refactor a bit custom output function | 2020/01/28-10:57 null | [Chmouel Boudjnah] Fix PipelineResource custom output | 2020/01/28-10:57 null | [Chmouel Boudjnah] Fix PipelineRuns custom output | 2020/01/28-10:57 #648 | [Chmouel Boudjnah] Fix Task custom output | 2020/01/28-10:57 #648 | [Chmouel Boudjnah] Fix TaskRuns custom output | 2020/01/28-10:57 #648 | [Chmouel Boudjnah] Fix ClusterTask custom output | 2020/01/28-10:57 #643 | [Daniel Helfand] --dry-run option for tkn pipeline start | 2020/01/29-02:50 #653 | [Chmouel Boudjnah] Minor wording fixes on the RELEASE_PROCESS document | 2020/01/29-04:26 #656 | [Vincent Demeester] Use gotest.tools assert package instead of testify 🍵 | 2020/01/29-05:16 #657 | [Daniel Helfand] refactor --dry-run tests for tkn pipeline start | 2020/01/29-10:55 #661 | [Chmouel Boudjnah] Fix output=name for pipeline list | 2020/01/30-10:08 #658 | [Piyush Garg] Bump tektoncd/pipeline and tektoncd/triggers | 2020/01/31-03:37 null | [Piyush Garg] Fix workspace not getting copied with --last | 2020/01/31-04:34 null | [16yuki0702] This fixes #639 | 2020/01/31-06:46 null | [ansky] Remove extra empty lines | 2020/01/31-10:30 null | [Daniel Helfand] remove tkn create | 2020/01/31-10:52 null | [Daniel Helfand] add --dry-run option for tkn task start | 2020/02/03-00:59 null | [Daniel Helfand] add --dry-run option for tkn ct start | 2020/02/03-01:17 null | [16yuki0702] Fix overriding GenerateName on taskrun. | 2020/02/03-06:23 Signed-off-by: Piyush Garg <[email protected]>
Closes #372
Changes
This pull request adds a
--dry-run
option fortkn pipeline start
. The idea would be to print the pipelinerun to stdout so a user can look over the pipelinerun without actually running the pipeline.An
--output
option will also be made available to output the dry run in yaml or json:Output the pipeline named pipelinename in namespace ns in yaml:
tkn pipeline start pipelinename -n ns --dry-run --output yaml
Output the pipeline named pipelinename in namespace ns in json:
tkn pipeline start pipelinename -n ns --dry-run -o json
Not using output flag with --dry-run uses yaml output default:
tkn pipeline start pipelinename -n ns --dry-run
Example out:
output = json
output = yaml
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
make docs
andmake man
if needed.make check
Release Notes