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

BUILD-476: Tekton Custom-Tasks Using Shipwright Builds #12

Merged
merged 4 commits into from
Feb 2, 2023

Conversation

otaviof
Copy link
Member

@otaviof otaviof commented Dec 12, 2022

Changes

Tekton Custom-Tasks controller.

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

Release Notes

Supporting Tekton Custom-Tasks referring to Shipwright Builds, triggering BuildRuns accordingly.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 12, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: otaviof

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 12, 2022
@otaviof
Copy link
Member Author

otaviof commented Dec 12, 2022

/assign @SaschaSchwarze0 @adambkaplan @coreydaley

Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

Nice work, even with parameter passing already. :-)

return RequeueOnError(err)
}

var br = &v1alpha1.BuildRun{}
Copy link
Member

Choose a reason for hiding this comment

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

The logic here is missing code to handle a canceled Run. I suggest the following:

  • If extra fields is empty (= BuildRun not yet created), then we do not create a BuildRun at all.
  • If extra fields is not empty (= BuildRun was created), then we retrieve the BuildRun, check if it is not complete, if so, we cancel it (= set .spec.status to BuildRunCancel). This will need update permission to be added.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I added the logic to handle both Tekton Run and BuildRun getting cancelled reflecting the status on each other. Please consider the latest changes.

pkg/filter/extra_fields.go Show resolved Hide resolved
Value: &v,
})
}
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Tekton has recently added ParamTypeObject. I guess we want to reject this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you have more examples about it? Thanks in advance.

Copy link
Member

Choose a reason for hiding this comment

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

The Tekton TEP is https://github.com/tektoncd/community/blob/main/teps/0075-object-param-and-result-types.md.

The general purpose is to better group many related parameters into one.

We don't support them in Shipwright and I at the moment do not yet see the need for them anyway because a Build is just one step of a larger pipeline and does rarely have groups of parameters. Vs. in a larger Tekton pipeline you could have parameters related to source code retrieval (Git repo, Git branch), build related (context directory, Dockerfile if we stick with image builds as an example), and maybe also deployment related (kube namespace, etc.)

Your code should have an else if checking for the explicit type ParamTypeString and an else block with things we do not support. The whole if might then be rewritten as a switch but that's up to what you prefer.

@otaviof otaviof force-pushed the BUILD-476 branch 3 times, most recently from 5b683f5 to 2c42230 Compare December 16, 2022 17:45
@otaviof otaviof requested review from SaschaSchwarze0 and removed request for sbose78 and adambkaplan December 16, 2022 17:47
@otaviof otaviof force-pushed the BUILD-476 branch 3 times, most recently from 1b8a910 to adc25ba Compare December 17, 2022 07:44
logger.V(0).Info("Marking the Tekton Run as successful!")
run.Status.MarkRunSucceeded(string(condition.Status), condition.Message)
}
run.Status.Conditions = append(run.Status.Conditions, condition)
Copy link
Member

Choose a reason for hiding this comment

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

This code is causing the list of conditions to grow while a BuildRun is running.

apiVersion: tekton.dev/v1alpha1
kind: Run
...
status:
  conditions:
  - lastTransitionTime: "2023-01-05T17:48:58Z"
    status: Unknown
    type: Succeeded
  - lastTransitionTime: "2023-01-05T17:48:59Z"
    message: Pending
    reason: Pending
    severity: Info
    status: Unknown
    type: Succeeded
  - lastTransitionTime: "2023-01-05T17:49:12Z"
    message: Not all Steps in the Task have finished executing
    reason: Running
    severity: Info
    status: Unknown
    type: Succeeded
  extraFields:
    buildRunName: shp-run-1672940937027-ko-build-mghj2
    buildRunNamespace: build-system
  startTime: "2023-01-05T17:48:58Z"

Copy link
Member Author

Choose a reason for hiding this comment

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

Should it only have a single condition? I thought the conditions would be appended thus the last one represents the current state.

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 instance, checking pod for its conditions I found the following:

$ k get pods jenkins-412-7f44fdb94f-mp4t2 -o json |jq '.status.conditions'
[
  {
    "lastProbeTime": null,
    "lastTransitionTime": "2023-01-05T10:42:03Z",
    "status": "True",
    "type": "Initialized"
  },
  {
    "lastProbeTime": null,
    "lastTransitionTime": "2023-01-06T04:31:15Z",
    "status": "True",
    "type": "Ready"
  },
  {
    "lastProbeTime": null,
    "lastTransitionTime": "2023-01-06T04:31:15Z",
    "status": "True",
    "type": "ContainersReady"
  },
  {
    "lastProbeTime": null,
    "lastTransitionTime": "2023-01-05T10:42:03Z",
    "status": "True",
    "type": "PodScheduled"
  }
]

Copy link
Member

Choose a reason for hiding this comment

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

An array of conditions can have multiple entries. But, per type, there should only be one.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense. Let me amend 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.

Please consider the latest changes, I found out a knative helper to keep the conditions based on its type.

otaviof and others added 2 commits February 2, 2023 20:33
Watches over Tekton Run instances pointing to Shipwright Builds, and
issues BuildRuns accordinly.

Co-authored-by: Sascha Schwarze <schwarzs@de.ibm.com>
@otaviof
Copy link
Member Author

otaviof commented Feb 2, 2023

@SaschaSchwarze0 please consider.

Including a few modifications to avoid leaking objects.
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 2, 2023
@openshift-merge-robot openshift-merge-robot merged commit 00e4b45 into shipwright-io:main Feb 2, 2023
@otaviof otaviof deleted the BUILD-476 branch February 3, 2023 06:34
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. lgtm Indicates that a PR is ready to be merged. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants