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

Sort the steps of taskrun based on the steps of task #963

Merged
merged 1 commit into from
Jun 14, 2019
Merged

Sort the steps of taskrun based on the steps of task #963

merged 1 commit into from
Jun 14, 2019

Conversation

houshengbo
Copy link

@houshengbo houshengbo commented Jun 6, 2019

Changes

Closes: #942

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide
for more details.

Release Notes

release-note

@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Jun 6, 2019
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 6, 2019
@houshengbo
Copy link
Author

/assign @hrishin @bobcatfish @vdemeester

@chmouel
Copy link
Member

chmouel commented Jun 7, 2019

this sounds worthwhile enough to mention in the release note,

func sortTaskRunSteps(taskRunSteps []v1alpha1.StepState, taskSpecSteps []corev1.Container) {
// Generate the map matching the step name and its index
sorter := constructTaskStepsSorter(taskSpecSteps)
for index, step := range taskRunSteps {
Copy link
Member

Choose a reason for hiding this comment

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

We may be able to use the sort package here 👼

Copy link
Author

Choose a reason for hiding this comment

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

I tried, but the the sort package is easy to sort the array with a filed or multiple fields in itself. Have not figured out to sort one array by aligning with another array.


sortTaskRunSteps(taskRunStatusSteps, task.Spec.Steps)

for index, step := range task.Spec.Steps {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would be more clear to do the cmp.Diff on the taskRunStatusSteps and an expectedTaskRunStatusSteps instead 👼

Copy link
Author

Choose a reason for hiding this comment

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

My question is how to create the fake taskRunStatusSteps and the expectedTaskRunStatusSteps?

Copy link
Member

Choose a reason for hiding this comment

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

well, expectedTaskRunStatusStep would be declared as taskRunStatusSteps but in the right order 👼

Copy link
Author

Choose a reason for hiding this comment

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

Got it.

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 7, 2019
Copy link
Member

@hrishin hrishin left a comment

Choose a reason for hiding this comment

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

Thank you @houshengbo 😄 for the PR.
Left few comments, please me know if that makes sense? 🙇‍♂️

@@ -361,6 +415,12 @@ func updateStatusFromPod(taskRun *v1alpha1.TaskRun, pod *corev1.Pod, resourceLis
})
}

if len(taskSpecSteps) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

wondering if this check is really needed? 🤔

Copy link
Author

Choose a reason for hiding this comment

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

I change the code structure a bit in order to separate the sortTaskRun function.

if len(taskSpecSteps) > 0 {
trt := new(TaskRunWithTask)
trt.Init(taskRun.Status.Steps, taskSpecSteps[0])
sort.Sort(trt)
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if sorting should be done outside of updateStatusFromPod method? 🤔
In that way

  • Writing the unit test would be easy
  • Single responsibility: Sorting responsibility could be taken outside of methods scope

Copy link
Author

Choose a reason for hiding this comment

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

I change the code structure a bit in order to separate the sortTaskRun function.

@houshengbo
Copy link
Author

@hrishin I have changed the structure of the code a bit. In order to separate the sort function, we have to make sure it is done between we get the taskrun and we update the taskrun.

@houshengbo
Copy link
Author

/retest

@hrishin
Copy link
Member

hrishin commented Jun 11, 2019

Thank you @houshengbo 🙇‍♂️

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

One nit, otherwise looks good
/lgtm

mapForSort map[string]int
}

func (trt *TaskRunWithTask) Init(taskRunSteps []v1alpha1.StepState, taskSpecSteps []corev1.Container) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I feel we don't need this and we could just declare it inline here

trt := &TaskRunWithTask{
	taskRunSteps: taskRunSteps,
        mapForSort: trt.constructTaskStepsSorter(taskSpecSteps),
}

But it's more a aesthetic thing than anything, so I am ok with both I think 👼

Copy link
Author

Choose a reason for hiding this comment

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

Thx.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 12, 2019
Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @houshengbo !! I have a couple of requests:

// elements of the array in the Swap function.
return true
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we move this logic out of the reconciler into a separate file / separate package? 🙏 the less code in the reconciler the better :D

Copy link
Collaborator

Choose a reason for hiding this comment

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

This would include moving sortTaskRunStepOrder and making it exported in the new package (SortTaskRunStepOrder)

Copy link
Author

@houshengbo houshengbo Jun 13, 2019

Choose a reason for hiding this comment

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

I thought about it before.

Would you mind we have a new package with a more general name like utils, so that we can put this sorter and maybe further algorithm(TBD) inside it? @bobcatfish

Copy link
Author

Choose a reason for hiding this comment

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

I'd like to name a new package utils.

Copy link
Member

Choose a reason for hiding this comment

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

@houshengbo I would definitely advise against utils 😅 generic names like utils or helpers do not convey anything of what is inside. This function is about sorting taskrun, so it could either be called sort (inside taskrun) or something a tiny bit more general like list ?

Copy link
Author

Choose a reason for hiding this comment

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

Forget about my previous comment.
what about stepsorting

Copy link
Member

Choose a reason for hiding this comment

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

@houshengbo 🤗 as it's related to tasks I feel it would be better in a package name that has task in (the path or the name) (tasks.SortBySpecOrder instead of my previous propositon)

cc @bobcatfish as I am not the greatest to find correct names 😂

Copy link
Collaborator

@bobcatfish bobcatfish Jun 13, 2019

Choose a reason for hiding this comment

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

ooo i like both the ideas! stepsorting is pretty close to what I would have suggested but I think @vdemeester is right, we'd end up with something like stepsorting.Sort 🤔

we have been kind of in need of a status related package for a while now (we have lots have status stuff in the reconciler) how about something like taskrunstatus or status, so we could have taskrunstatus.SortSteps or status.SortSteps?

Copy link
Member

Choose a reason for hiding this comment

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

ohh I do like the status package 😻 status.SortSteps sounds really good to me !

Copy link
Author

Choose a reason for hiding this comment

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

yep, I think we can agree on that.

trt.mapForSort = trt.constructTaskStepsSorter(taskSpecSteps)
}

// This function constructTaskStepsSorter constructs a map matching the names of
Copy link
Collaborator

Choose a reason for hiding this comment

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

the expected format for comments like this i usually for them to start with the name of the function, e.g.:

// constructTaskStepsSorter constructs a map matching the names of ...

Copy link
Author

Choose a reason for hiding this comment

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

Done. Thx.

}}

sortTaskRunStepOrder(taskRunStatusSteps, task.Spec.Steps)
if d := cmp.Diff(taskRunStatusSteps, expectedStepState); d != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is pretty minor but the test would be a bit easier to read if it asserted the names of the names of the steps only, e.g. something like:

actualStepOrder := []string{}
for _, state :=  range(taskRunStatusSteps) {
    actualStepOrder = append(actualStepOrder, state.name)
}

expectedStepOrder := []string{"hello", "exit", "world", "nop"}
if d := cmp.Diff(actualStepOrder, expectedStepOrder); d != "" {
}

Then you can completely get rid of expectedStepState :D

Copy link
Collaborator

Choose a reason for hiding this comment

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

(this would also make it a bit easier to add a few more tests cases as well)

Copy link
Author

Choose a reason for hiding this comment

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

Done. Thx.

@@ -82,6 +83,58 @@ const (
imageDigestExporterContainerName = "step-image-digest-exporter"
)

type TaskRunWithTask struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I got a bit confused about what this type was - it seems to me like the main goal of this type is to sort StepStates, how about calling it something like StepStateSorter?

Copy link
Author

Choose a reason for hiding this comment

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

Done. Thx.

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 13, 2019
@houshengbo houshengbo changed the title Sort the steps of taskrun based on the steps of task WIP: Sort the steps of taskrun based on the steps of task Jun 13, 2019
@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 13, 2019
@bobcatfish bobcatfish mentioned this pull request Jun 13, 2019
3 tasks
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added lgtm Indicates that a PR is ready to be merged. and removed lgtm Indicates that a PR is ready to be merged. labels Jun 14, 2019
@houshengbo houshengbo changed the title WIP: Sort the steps of taskrun based on the steps of task Sort the steps of taskrun based on the steps of task Jun 14, 2019
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 14, 2019
Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

Looking good! I just have a minor request about docs, otherwise good to go 🙏

docs/taskruns.md Outdated
If multiple `steps` are defined in the `Task` invoked by the `TaskRun`, we will see the
`status.steps` of the `TaskRun` displayed in the same order as they are defined in
`spec.steps` of the `Task`, when the `TaskRun` is accessed by the `get` command, e.g.
`kubectl get taskrun <name> -o yaml`. Replace \<name\> with the name of the `TaskRun`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for adding this! could you put it in a status section on it's own, maybe between the syntax and ordering sections, and add a link to the new section in the overview at the top of the file? https:/tektoncd/pipeline/blob/master/docs/pipelines.md#pipelines

This will give us a place to start putting more docs about the status in the future as well.

Copy link
Author

Choose a reason for hiding this comment

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

This is a change on the file taskruns.md, not pipeline.md.
Do you actually mean to add a section in taskruns.md?

Copy link
Collaborator

Choose a reason for hiding this comment

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

whoops my bad! no taskruns is the right place :D


// The order of the container statuses has been shuffled, not aligning with the order of the
// spec steps of the Task any more. After Reconcile is called, we should see the order of status
// steps in TaksRun has been converted to the same one as in spec steps of the Task.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice comment!

trt := new(StepStateSorter)
trt.Init(taskRunSteps, taskSpecSteps)
sort.Sort(trt)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice, thanks for making the new package!

actualStepOrder = append(actualStepOrder, state.Name)
}

expectedStepOrder := []string{"hello", "exit", "world", "nop"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice, i like how the expected order is hardcoded here, very clear!

@bobcatfish
Copy link
Collaborator

I0614 17:21:03.378] 2019/06/14 17:21:03 util.go:142: Please use kubetest --gcp-service-account=/etc/test-account/service-account.json (instead of deprecated GOOGLE_APPLICATION_CREDENTIALS=/etc/test-account/service-account.json)
I0614 17:21:03.379] 2019/06/14 17:21:03 main.go:761: --gcp-project is missing, trying to fetch a project from boskos.
I0614 17:21:03.379] (for local runs please set --gcp-project to your dev project)
I0614 17:21:03.379] 2019/06/14 17:21:03 main.go:773: provider gke, will acquire project type gke-project from boskos
I0614 17:21:03.434] 2019/06/14 17:21:03 main.go:312: Something went wrong: failed to prepare test environment: --provider=gke boskos failed to acquire project: resource not found
I0614 17:21:03.462] Test subprocess exited with code 0

bah, reopened tektoncd/plumbing#29

/test pull-tekton-pipeline-integration-tests

@bobcatfish
Copy link
Collaborator

I0614 18:16:31.836] 2019/06/14 18:16:31 error processing import paths in "config/controller.yaml": Get https://gcr.io/v2/: net/http: TLS handshake timeout

whyyyyyyyy

@bobcatfish
Copy link
Collaborator

/test pull-tekton-pipeline-integration-tests

@bobcatfish
Copy link
Collaborator

/lgtm
/meow space

@tekton-robot
Copy link
Collaborator

@bobcatfish: cat image

In response to this:

/lgtm
/meow space

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 14, 2019
@houshengbo
Copy link
Author

@bobcatfish Thank you.

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 14, 2019
@bobcatfish
Copy link
Collaborator

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 14, 2019
@bobcatfish
Copy link
Collaborator

/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bobcatfish, houshengbo

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 14, 2019
@tekton-robot tekton-robot merged commit 8552f8b into tektoncd:master Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Order TaskRun.Status.Steps same way as Task.Spec.Steps
7 participants