Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from p1nkun1c0rns/finalise2v1
Browse files Browse the repository at this point in the history
from 0.0.1 to 1.0.0
  • Loading branch information
steinbrueckri authored Apr 15, 2020
2 parents 3e47a62 + 75f707b commit 5201532
Show file tree
Hide file tree
Showing 16 changed files with 328 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 1
update_configs:
- package_manager: "docker"
directory: "/"
update_schedule: "weekly"
automerged_updates:
- match:
dependency_type: "all"
update_type: "all"
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @steinbrueckri
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Test"
on:
pull_request:
push:
branches-ignore:
- 'dependabot/*'
schedule:
- cron: '22 22 * * 5'

jobs:
lint:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v2

- name: Markdown Lint
uses: actionshub/[email protected]

- name: YAML Lint
uses: karancode/yamllint-github-action@master
with:
yamllint_file_or_dir: action.yml

- name: Dockerfile Lint
uses: burdzwastaken/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HADOLINT_ACTION_DOCKERFILE_FOLDER: .
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Run CI script
run: ./test/ci-test.sh

- name: Run action
uses: ./
with:
path: "./test/test_data/good_case_1"
file_extension: "*.yaml"
exclude: "skip"
1 change: 1 addition & 0 deletions .mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules "~MD013,~MD024,~MD033"
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2019 Richard SteinbrΓΌck and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# prometheus-operator-lint-action
# prometheus-operator-lint-action

[![Test](https://github.com/p1nkun1c0rns/prometheus-operator-lint-action/workflows/Test/badge.svg)](https://github.com/p1nkun1c0rns/prometheus-operator-lint-action/actions?query=workflow%3ATest)

This action ...

## Contributions

- Contributions are welcome!
- Give :star: - if you want to encourage me to work on a project
- Don't hesitate create issue for new feature you dream of or if you suspect some bug

## Project versioning

Project use [Semantic Versioning](https://semver.org/).
We recommended to use the latest and specific release version.

In order to keep your project dependencies up to date you can watch this repository *(Releases only)*
or use automatic tools like [Dependabot](https://dependabot.com/).

## Usage

See [action.yml](action.yml)

### Simple

```yml
steps:
- uses: p1nkun1c0rns/prometheus-operator-lint-action@master
```
### Advanced
```yml
steps:
- uses: p1nkun1c0rns/prometheus-operator-lint-action@master
with:
path: "./"
file_extension: "*.yaml"
exclude: "foobar"
```
## License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
name: 'Prometheus Operator Lint Action'
author: 'Richard Steinbrueck'
description: 'Run po-lint on your yaml files'
inputs:
path:
description: 'Path to scan for files within the directory (and nested directories)'
description: 'Path to files within the repo (and nested directories)'
required: false
default: './'
file_extension:
Expand Down
27 changes: 23 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
#!/bin/sh

INPUT_PATH=$1
if [[ -z "$INPUT_PATH" ]]; then
echo "ERROR: input variable 'path' is not set"
exit 1
fi

if [[ ! -d "$INPUT_PATH" ]]; then
echo "ERROR: path '$INPUT_PATH' dont exist"
exit 1
fi

INPUT_FILES=$2
if [[ -z "$INPUT_FILES" ]]; then
echo "ERROR: input variable 'files' is not set"
exit 1
fi

INPUT_EXCLUDE=$3

echo "Linting '${INPUT_FILES}' files in directory '${INPUT_PATH}'..."
had_errors=0
for file in $(find ${INPUT_PATH} -name ${INPUT_FILES}); do
# Exclude Grafana dashboards
if echo "${file}" | grep -q ${INPUT_EXCLUDE}
then
echo "skip -> ${file}"
continue

# do not grep for null ;)
if [[ ! -z "${INPUT_EXCLUDE}" ]]; then
if echo "${file}" | grep -q ${INPUT_EXCLUDE}
then
echo "skip -> ${file}"
continue
fi
fi

po-lint "${file}"
Expand Down
69 changes: 69 additions & 0 deletions test/ci-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

docker build -t prometheus-operator-lint-action .

error_count=0

# good case 1 #################################################################
###############################################################################
TESTCASE="good_case_1"
INPUT_PATH="/mnt/$TESTCASE"
INPUT_FILES="*.yaml"
INPUT_EXCLUDE="skip"

docker run --rm \
-v $(pwd)/test/test_data:/mnt/ \
prometheus-operator-lint-action $INPUT_PATH $INPUT_FILES $INPUT_EXCLUDE

RESULT=$?
if [ $RESULT == 0 ]; then
echo "βœ… $TESTCASE test passed"
else
echo "❌ $TESTCASE test failed"
error_count=$((error_count+1))
fi

unset TESTCASE

# good case 2 #################################################################
###############################################################################
TESTCASE="good_case_2"
INPUT_PATH="/mnt/$TESTCASE"
INPUT_FILES="*.yaml"
INPUT_EXCLUDE=""

docker run --rm \
-v $(pwd)/test/test_data:/mnt/ \
prometheus-operator-lint-action $INPUT_PATH $INPUT_FILES $INPUT_EXCLUDE

RESULT=$?
if [ $RESULT == 0 ]; then
echo "βœ… $TESTCASE test passed"
else
echo "❌ $TESTCASE test failed"
error_count=$((error_count+1))
fi

# test the bad case ###########################################################
###############################################################################
TESTCASE="bad_case_1"
INPUT_PATH="/mnt/$TESTCASE"
INPUT_FILES="*.yaml"
INPUT_EXCLUDE="skip"

docker run --rm \
-v $(pwd)/test/test_data:/mnt/ \
prometheus-operator-lint-action $INPUT_PATH $INPUT_FILES $INPUT_EXCLUDE

RESULT=$?
if [ $RESULT == 0 ]; then
echo "❌ $TESTCASE test failed"
error_count=$((error_count+1))
else
echo "βœ… $TESTCASE test passed"
fi

###############################################################################
# exit
###############################################################################
exit $error_count
21 changes: 21 additions & 0 deletions test/test_data/bad_case_1/rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
creationTimestamp: null
labels:
app: prometheus-operator
release: prometheus-operator
name: redis
namespace: monitoring
spec:
groups:
- name: redis.memory
rules:
- alerts: RedisMemoryAlmostFull
annotations:
messages: 'Redis memory is at {{ $value | humanizePercentage }} of maximum for 2 days in a row'
expr: redis_memory_used_bytes/redis_memory_max_bytes > 0.8
f0r: 2d
labels:
severity: warning
16 changes: 16 additions & 0 deletions test/test_data/bad_case_1/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: karma
namespace: monitoring
spec:
jobLabel: karma
select0r:
matchLabels:
app.kubernetes.io/instance: karma
namespaceSelector:
matchNames:
- monitoring
endpoints:
- path: /alerts/metrics
21 changes: 21 additions & 0 deletions test/test_data/good_case_1/rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
creationTimestamp: null
labels:
app: prometheus-operator
release: prometheus-operator
name: redis
namespace: monitoring
spec:
groups:
- name: redis.memory
rules:
- alert: RedisMemoryAlmostFull
annotations:
message: 'Redis memory is at {{ $value | humanizePercentage }} of maximum for 2 days in a row'
expr: redis_memory_used_bytes/redis_memory_max_bytes > 0.8
for: 2d
labels:
severity: warning
16 changes: 16 additions & 0 deletions test/test_data/good_case_1/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: karma
namespace: monitoring
spec:
jobLabel: karma
selector:
matchLabels:
app.kubernetes.io/instance: karma
namespaceSelector:
matchNames:
- monitoring
endpoints:
- path: /alerts/metrics
3 changes: 3 additions & 0 deletions test/test_data/good_case_1/skip/skip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©
πŸ’©πŸ’© skip πŸ’©πŸ’©
πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©πŸ’©
21 changes: 21 additions & 0 deletions test/test_data/good_case_2/rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
creationTimestamp: null
labels:
app: prometheus-operator
release: prometheus-operator
name: redis
namespace: monitoring
spec:
groups:
- name: redis.memory
rules:
- alert: RedisMemoryAlmostFull
annotations:
message: 'Redis memory is at {{ $value | humanizePercentage }} of maximum for 2 days in a row'
expr: redis_memory_used_bytes/redis_memory_max_bytes > 0.8
for: 2d
labels:
severity: warning
16 changes: 16 additions & 0 deletions test/test_data/good_case_2/servicemonitor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: karma
namespace: monitoring
spec:
jobLabel: karma
selector:
matchLabels:
app.kubernetes.io/instance: karma
namespaceSelector:
matchNames:
- monitoring
endpoints:
- path: /alerts/metrics

0 comments on commit 5201532

Please sign in to comment.