A CLI command to parse kubectl diff
result and notify it to GitLab/GitHub
- Parse the execution result of
kubectl diff
- Notify it to GitLab/GitHub
The comment posted by ksnotify is as follows:
- updated
- apps.v1.Deployment.test.test-app
Details (Click me)
@@ -5,7 +5,6 @@
deployment.kubernetes.io/revision: "3"
+ labels:
+ app: test-app
name: test-app
namespace: test
spec:
@@ -27,7 +26,6 @@
creationTimestamp: null
labels:
app: test-app
- skaffold.dev/run-id: 1234
spec:
containers:
- args:
Download the prebuilt binary from GitHub Releases and install it to $PATH.
Install ksnotify with aqua, which is a declarative CLI Version Manager.
$ aqua g -i hirosassa/ksnotify
Create and export GitLab access token to environmental variables as follows:
export KSNOTIFY_GITLAB_TOKEN="xxxxxx"
ref: Project access tokens | GitLab
If you run ksnotify
on GitHub Actions, ksnotify
use GITHUB_TOKEN
by default.
If you run ksnotify
locally, you should set PAT to GITHUB_TOKEN
environment variable.
ref: Permissions required for fine-grained personal access tokens
If you simplify the configuration of setup ksnotify
in GitHub Actions, you can use setup-ksnotify.
Basic usage for GitLab is as follows:
skaffold render -p dev | kubectl diff -f - 2> /dev/null | ksnotify --ci gitlab
Of course, you can use ksnotify
with GitHub as well.
skaffold render -p dev | kubectl diff -f - 2> /dev/null | ksnotify --ci github
If you want to update the existing comment instead of create a new comment, you should add --patch
flag like
skaffold render -p dev | kubectl diff -f - 2> /dev/null | ksnotify --ci gitlab --patch
To suppress skaffold
labels like skaffold.dev/run-id: 1234
automatically added by skaffold
, you should add --suppress-skaffold
flag like
skaffold render -p dev | kubectl diff -f - 2> /dev/null | ksnotify --ci gitlab --suppress-skaffold
The concrete example of GitLab CI configuration is shown in example.
To run ksnotify
locally, use local option for debug.
For local mode, ksnotify
just renders contents on stdout.
skaffold render -p dev | kubectl diff -f - 2> /dev/null | path/to/ksnotify --ci local --suppress-skaffold
> ## Plan result
> [CI link]( )
>
> * updated
> blah
> blah