Skip to main content

Pull request delivery

With pull request delivery, SKE opens a pull request for each change to a GitStateStore instead of pushing to its branch directly. To enable pull request delivery for a GitStateStore, see Set up pull request delivery.

Configuring​

apiVersion: platform.kratix.io/v1alpha1
kind: GitStateStore
metadata:
name: production
spec:
# url, branch, authMethod and secretRef as usual
delivery:
mode: pullRequest
config:
provider: github
checkInterval: 30s
apiURL: https://github.example.com/api/v3

The delivery block has the following fields.

mode​

Required. Set it to pullRequest.

config​

The settings for the Git server that SKE opens pull requests on.

provider​

Required. One of:

  • github, for github.com and GitHub Enterprise Server.
  • azureDevOps
  • gitlab

Each provider expects a particular spec.url and credentials on the GitStateStore:

  • github: authenticate with basicAuth or githubApp.
  • azureDevOps: set spec.url to https://dev.azure.com/<ORGANISATION>/<PROJECT>/_git/<REPOSITORY> or https://<ORGANISATION>.visualstudio.com/<PROJECT>/_git/<REPOSITORY>. Authenticate with basicAuth, using a personal access token as the password and any username that is not empty.
  • gitlab: set spec.url to https://<HOST>/<GROUP>/<PROJECT>, with any number of subgroups. Authenticate with basicAuth, using an access token as the password and any username that is not empty. The token needs the api and write_repository scopes, and its user needs at least the Developer role on the project. Deploy tokens do not work, because they cannot call GitLab's API.

checkInterval (default: 30s)​

How often SKE checks each open pull request, as a duration such as 30s or 2m. SKE notices a merged or closed pull request at its next check.

apiURL​

GitHub and GitLab only. The provider's API address. It must be on the same host as spec.url.

  • On GitHub, it defaults to https://api.github.com for github.com, and https://<host>/api/v3 for any other host.
  • On GitLab, it defaults to https://<host>/api/v4. Set it when GitLab is installed under a path, for example https://git.example.com/gitlab/api/v4.

Limitations​

  • authMethod: ssh is not supported, because SKE needs a token to call the provider's API.
  • Destinations with filepath.mode: aggregatedYAML are not supported.

Turning it on and off​

  • Adding the delivery block to a GitStateStore that already has requests opens a pull request only for requests whose files differ from the Destination's branch.
  • Removing the delivery block makes SKE write every request straight to the Destination's branch again, including requests waiting for approval or rejected. A rejected removal stays rejected (see Deleting). SKE does not close the pull requests that were open. You must close them yourself.

Status​

The request's STATUS column shows a summary of the change, cut to 120 characters. kubectl describe shows the full text in the Reconciled and WorksSucceeded conditions.

STATUSMeaning
Waiting for approval: <URL>A pull request is open.
Rejected in <URL>: "<COMMENT>"A reviewer closed the pull request with a comment.
Rejected in <URL> with no commentA reviewer closed the pull request without a comment.
Waiting for approval to remove: <URL>The request was deleted and its removal pull request is open.
Removal rejected; the workloads are still on <DESTINATION>. Rejected in <URL>...A reviewer closed the removal pull request without merging it.

SKE quotes the comment the reviewer left when closing the pull request, up to 500 characters:

  • On GitHub, it quotes the Close with comment text. It does not quote review comments.
  • On Azure DevOps, it quotes the latest comment by the person who abandoned the pull request, written within a minute before or after they abandoned it.
  • On GitLab, it quotes the latest comment by the person who closed the merge request, written within a minute before or after they closed it.

Anyone who can read the resource request can read the quote and the link, even without access to the repository.

The condition reasons are:

ResourceConditionOpenMergedClosed without merging
Resource requestReconciledWorksAwaitingDeliveryReconciledWorksRejected
WorkWriteSucceededWorkplacementsAwaitingDeliveryWorkplacementsWrittenWorkplacementsRejected
WorkPlacementWriteSucceededWorkloadsAwaitingDeliveryWorkloadsWrittenToStateStoreWorkloadsRejected

The condition's status is Unknown while a pull request is open, True once merged, and False once closed without merging. Each WorkPlacement also holds its pull request's link in status.deliveryURL, and status.deliveryRemoval is true when it is a removal. A Work's status.workPlacementStatuses lists each WorkPlacement with its Destination, status and deliveryURL.

How SKE handles pull requests​

SKE opens each pull request from a kratix/<WORKPLACEMENT_NAME> branch into the Destination's branch, and checks it every checkInterval. Azure DevOps calls a merged pull request completed, and one closed without merging abandoned. GitLab calls a pull request a merge request.

WhenSKE
The pull request is mergedMarks the change as done, and runs the request's next pipeline.
The pull request is closed without mergingMarks the request as rejected, and does not run its later pipelines. It does not open a pull request for the same files again until you retry.
The request changes and produces different filesCloses the open pull request and opens a new one. Reviews do not carry over.
The request changes but produces the same filesKeeps the open pull request and its reviews.
The request changes back to what is already mergedCloses the pull request, because it is no longer needed. The request becomes ready.
The pull request has merge conflictsRebuilds it on top of the latest Destination's branch, keeping its number and link. Depending on your branch rules, existing approvals may be dismissed. See Rebuilding a pull request.
Someone changes a kratix/<WORKPLACEMENT_NAME> branchOverrides the changes.
Someone changes SKE's files on the Destination's branchOpens a new pull request to put them back.

To retry a rejected change, label the request's Work with kratix.io/redeliver=true. After a rejected pull request, SKE opens a new one. After a rejected removal, it opens a new removal pull request. Otherwise it does nothing, unless the files on the Destination's branch have changed.

Rebuilding a pull request​

SKE rebuilds a pull request only when it has merge conflicts. It does not touch a pull request that is only behind, has failing checks, or whose conflicts you resolved yourself.

When SKE rebuilds a pull request, it force-pushes the kratix/<WORKPLACEMENT_NAME> branch. Your branch rules decide whether existing approvals stay, and whether SKE can push at all:

  • On GitHub, the "Dismiss stale pull request approvals when new commits are pushed" setting dismisses existing approvals.
  • On Azure DevOps, the "When new changes are pushed" policy dismisses existing approvals. SKE needs permission to force-push its branches. The branch's creator has it unless a branch permission removes it.
  • On GitLab, the "Remove all approvals" approval setting dismisses existing approvals. A protected branch rule that covers kratix/* must allow force pushes.

Deleting​

Deleting a request opens a pull request that removes its files from the Destination's branch. The request is only removed when that pull request is merged. If the request still has an open pull request, SKE closes it. If none of the request's files were ever merged, the request is removed straight away.

Deleting a Promise waits for the removal pull request of every request, and one rejected removal keeps the Promise.

Deleting a Destination with cleanup: all waits for a removal pull request for each of its WorkPlacements. With cleanup: none, SKE leaves the files on the branch.

If a reviewer closes a removal pull request without merging it, the request stays and its workloads keep running. To retry, use the kratix.io/redeliver label. To remove the request and leave its files on the Destination's branch, remove the finalizers from its WorkPlacements:

kubectl get workplacements --all-namespaces \
-o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,REQUEST:.spec.resourceName \
| grep <RESOURCE_NAME>

kubectl patch workplacement <WORKPLACEMENT_NAME> -n <NAMESPACE> \
--type=json -p='[{"op": "remove", "path": "/metadata/finalizers"}]'