https://github.com/hirosassa/ksnotify
A CLI command to parse kubectl diff result and notify it to GitLab
https://github.com/hirosassa/ksnotify
ci gitlab gitlab-ci kubectl kustomize skaffold
Last synced: about 2 months ago
JSON representation
A CLI command to parse kubectl diff result and notify it to GitLab
- Host: GitHub
- URL: https://github.com/hirosassa/ksnotify
- Owner: hirosassa
- License: mit
- Created: 2021-09-08T20:28:30.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-05-04T23:35:07.000Z (about 2 months ago)
- Last Synced: 2025-05-05T03:00:03.096Z (about 2 months ago)
- Topics: ci, gitlab, gitlab-ci, kubectl, kustomize, skaffold
- Language: Rust
- Homepage:
- Size: 68.4 KB
- Stars: 10
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ksnotify
[](https://github.com/hirosassa/ksnotify/actions/workflows/test.yaml)
[](https://codecov.io/gh/hirosassa/ksnotify)
[](https://github.com/hirosassa/ksnotify/blob/main/LICENSE)A CLI command to parse `kubectl diff` result and notify it to GitLab/GitHub
## What ksnotify does
1. Parse the execution result of `kubectl diff`
1. Notify it to GitLab/GitHubThe comment posted by ksnotify is as follows:
------------
## Plan result[CI link]( https://example.com )
* updated
* apps.v1.Deployment.test.test-appDetails (Click me)
## apps.v1.Deployment.jasmine.test-app
```diff
@@ -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:
```------------
## Install
### GitHub Releases
Download the prebuilt binary from [GitHub Releases](https://github.com/hirosassa/ksnotify/releases) and install it to $PATH.
### aqua
Install ksnotify with [aqua](https://aquaproj.github.io/), which is a declarative CLI Version Manager.
```console
$ aqua g -i hirosassa/ksnotify
```## Usage
### prerequisites#### For GitLab
Create and export GitLab access token to environmental variables as follows:
```console
export KSNOTIFY_GITLAB_TOKEN="xxxxxx"
```
ref: [Project access tokens | GitLab](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html)#### For GitHub
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`.ref: [Permissions required for fine-grained personal access tokens](https://docs.github.com/en/rest/authentication/permissions-required-for-fine-grained-personal-access-tokens?apiVersion=2022-11-28)
### Post diff results to GitLab/GitHub
Basic usage is as follows:
```console
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
```console
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
```console
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](https://github.com/hirosassa/ksnotify/tree/main/example).
## For developers
To run `ksnotify` locally, use local option for debug.
For local mode, `ksnotify` just renders contents on stdout.```console
skaffold render -p dev | kubectl diff -f - 2> /dev/null | path/to/ksnotify --ci local --notifier gitlab --suppress-skaffold> ## Plan result
> [CI link]( )
>
> * updated
> blah
> blah
```