Set up pull request delivery
A GitStateStore's delivery mode controls how Kratix writes to the Git
repository. By default, Kratix pushes straight to the branch. With pull request
delivery, SKE opens a pull request for each change instead, and the change
reaches the cluster only after someone merges it. SKE never merges the pull
request itself.
Pull request delivery works with GitHub pull requests (github.com and GitHub Enterprise Server), Azure DevOps pull requests, and GitLab merge requests. GitLab calls a pull request a merge request.
What you need
- GitHub
- Azure DevOps
- GitLab
- A
GitStateStoreon GitHub, authenticating with a personal access token (basicAuth) or a GitHub App (githubApp). See GitStateStore authentication. - Read and write access to the repository's Contents and Pull requests for that token or GitHub App.
- A
GitStateStoreon Azure DevOps, authenticating with a personal access token (basicAuth). - The Code (Read & write) scope on that token.
- The Contribute, Create branch and Contribute to pull requests permissions on the repository. The project's Contributors group has them by default.
- A
GitStateStoreon GitLab with anhttpsURL, authenticating with an access token (basicAuth). - The
apiandwrite_repositoryscopes on that token. - At least the Developer role on the project for the token's user.
Use a project access token or a token for a service account, so the token can reach only the projects SKE writes to. A personal access token also works.
GitLab access tokens expire, after 365 days by default. Replace the password
in the Secret before the token expires.
A Destination with filepath.mode: aggregatedYAML cannot use pull request
delivery. Kratix refuses to create or update the Destination or the
GitStateStore if the change would put them together.
Turn it on
Add a delivery block to the GitStateStore:
- GitHub
- Azure DevOps
- GitLab
apiVersion: platform.kratix.io/v1alpha1
kind: GitStateStore
metadata:
name: production
spec:
url: https://github.com/acme/platform-state
branch: main
authMethod: basicAuth
secretRef:
name: git-credentials
namespace: default
delivery:
mode: pullRequest
config:
provider: github
apiVersion: platform.kratix.io/v1alpha1
kind: GitStateStore
metadata:
name: production
spec:
url: https://dev.azure.com/acme/platform/_git/platform-state
branch: main
authMethod: basicAuth
secretRef:
name: git-credentials
namespace: default
delivery:
mode: pullRequest
config:
provider: azureDevOps
apiVersion: platform.kratix.io/v1alpha1
kind: GitStateStore
metadata:
name: production
spec:
url: https://gitlab.com/acme/platform-state.git
branch: main
authMethod: basicAuth
secretRef:
name: git-credentials
namespace: default
delivery:
mode: pullRequest
config:
provider: gitlab
SKE now writes to every Destination that uses this GitStateStore through pull
requests. For the optional settings, see the pull request delivery
reference.
Check it works
Request a resource from a Promise scheduled to one of those Destinations. Its
STATUS links the pull request:
kubectl get <RESOURCE_KIND> <RESOURCE_NAME> -n <NAMESPACE>
- GitHub
- Azure DevOps
- GitLab
NAME MESSAGE STATUS
redis Redis provisioned Waiting for approval: https://github.com/acme/platform-state/pull/42
NAME MESSAGE STATUS
redis Redis provisioned Waiting for approval: https://dev.azure.com/acme/platform/_git/platform-state/pullrequest/42
NAME MESSAGE STATUS
redis Redis provisioned Waiting for approval: https://gitlab.com/acme/platform-state/-/merge_requests/42
Merge the pull request. Within the
checkInterval (default:
30 seconds), the request is ready and any later pipelines run.
Review a change
Each change to a request gets its own pull request, opened from a
kratix/<WORKPLACEMENT_NAME> branch into the Destination's branch.
- GitHub
- Azure DevOps
- GitLab
-
Merge it to write the change to the Destination's branch.
-
Close it without merging to reject the change. The request fails, and if the pull request was closed with Close with comment, the comment is quoted in the
STATUSof the request:NAME MESSAGE STATUSredis Redis provisioned Rejected in https://github.com/acme/platform-state/pull/42: "not during the freeze"
-
Complete it to write the change to the Destination's branch.
-
Abandon it to reject the change. The request fails, and if you comment on the pull request within a minute of abandoning it, before or after, the comment is quoted in the
STATUSof the request:NAME MESSAGE STATUSredis Redis provisioned Rejected in https://dev.azure.com/acme/platform/_git/platform-state/pullrequest/42: "not during the freeze"
-
Merge it to write the change to the Destination's branch.
-
Close merge request to reject the change. The request fails, and if you comment on the merge request within a minute of closing it, before or after, the comment is quoted in the
STATUSof the request:NAME MESSAGE STATUSredis Redis provisioned Rejected in https://gitlab.com/acme/platform-state/-/merge_requests/42: "not during the freeze"
SKE does not open a pull request for the same files again. A new one opens when the request or the Promise produces different files, or when you retry.
Do not commit to the kratix/<WORKPLACEMENT_NAME> branches or edit SKE's files
on the Destination's branch. SKE replaces those commits, or opens a pull request
to undo them. Change the Promise or the request instead.
Retry a rejected change
To force SKE to recreate a pull request, for example when the previous one was
closed without being merged, label the request's Work with
kratix.io/redeliver=true:
kubectl label works -n <NAMESPACE> \
-l kratix.io/promise-name=<PROMISE_NAME>,kratix.io/resource-name=<RESOURCE_NAME> \
kratix.io/redeliver=true
Delete a request
Deleting a request also opens a pull request to remove its files from the State Store. The request is only removed when that pull request is merged. The request's status shows the URL of the pull request:
- GitHub
- Azure DevOps
- GitLab
NAME MESSAGE STATUS
redis Redis provisioned Waiting for approval to remove: https://github.com/acme/platform-state/pull/57
NAME MESSAGE STATUS
redis Redis provisioned Waiting for approval to remove: https://dev.azure.com/acme/platform/_git/platform-state/pullrequest/57
NAME MESSAGE STATUS
redis Redis provisioned Waiting for approval to remove: https://gitlab.com/acme/platform-state/-/merge_requests/57
If a reviewer closes the removal pull request without merging it, the workloads keep running and the request stays on the platform. To retry by opening a new pull request, use the label above. To let the request finish deleting and keep its files, see Deleting.
Related docs
- Pull request delivery reference: configuration, turning the feature off, status fields, and what SKE does when requests change, pull requests conflict, or files are changed by hand.
- GitStateStore
