A CLI command to parse kubectl diff
result and notify it to GitLab
- Parse the execution result of
kubectl diff
- Notify it to GitLab
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
Basic usage is as follows:
skaffold render -p dev | kubectl diff -f - 2> /dev/null | | ksnotify --notifier gitlab --ci gitlab
If you want to update 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 --notifier gitlab --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 --notifier gitlab --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 | ~/Dev/ksnotify/ksnotify --ci local --notifier gitlab --suppress-skaffold
> ## Plan result
> [CI link]( )
>
> * updated
> blah
> blah