Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Commit 8373a48

Browse files
authored
introduce pre-commit hook configuration (#53)
* introduce pre-commit hook configuration * add pre-commit as dependency * only exclude Helm YAML templates
1 parent ee73b42 commit 8373a48

19 files changed

+280
-48
lines changed

.pre-commit-config.yaml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
minimum_pre_commit_version: 1.17.0
3+
fail_fast: false
4+
default_stages: [commit, push]
5+
repos:
6+
# meta
7+
8+
- repo: meta
9+
hooks:
10+
- id: check-hooks-apply
11+
- id: check-useless-excludes
12+
13+
# formatters
14+
15+
- repo: https://github.com/asottile/reorder_python_imports
16+
rev: v1.6.0
17+
hooks:
18+
- id: reorder-python-imports
19+
20+
- repo: https://github.com/ambv/black
21+
rev: stable
22+
hooks:
23+
- id: black
24+
25+
# - repo: https://github.com/pre-commit/mirrors-yapf
26+
# rev: v0.28.0
27+
# hooks:
28+
# - id: yapf
29+
30+
- repo: https://github.com/asottile/pyupgrade
31+
rev: v1.12.0
32+
hooks:
33+
- id: pyupgrade
34+
stages: [push]
35+
36+
# linters
37+
38+
- repo: https://github.com/PyCQA/bandit
39+
rev: 1.6.2
40+
hooks:
41+
- id: bandit
42+
args: ["-x", "tests"]
43+
stages: [push]
44+
45+
- repo: https://github.com/PyCQA/pydocstyle
46+
rev: 4.0.0
47+
hooks:
48+
- id: pydocstyle
49+
args: ["--ignore=D10,D21,D202"]
50+
51+
52+
- repo: local
53+
hooks:
54+
55+
- id: safety
56+
name: safety
57+
entry: safety
58+
language: system
59+
pass_filenames: false
60+
args: ["check", "--bare"]
61+
stages: [push]
62+
63+
- id: poetry
64+
name: poetry
65+
description: Validates the structure of the pyproject.toml file
66+
entry: poetry check
67+
language: system
68+
pass_filenames: false
69+
files: ^pyproject.toml$
70+
stages: [push]
71+
72+
- repo: https://github.com/adrienverge/yamllint
73+
rev: v1.16.0
74+
hooks:
75+
- id: yamllint
76+
args: ["--strict", "-d", "{rules: {line-length: {max: 180}}}"]
77+
#
78+
exclude: >
79+
(?x)^(
80+
^{{.*}}.*\.yaml$|
81+
^helm/templates/.*$
82+
)
83+
#
84+
85+
- repo: https://github.com/pre-commit/mirrors-mypy
86+
rev: v0.711
87+
hooks:
88+
- id: mypy
89+
90+
- repo: https://github.com/pryorda/dockerfilelint-precommit-hooks
91+
rev: v0.1.0
92+
hooks:
93+
- id: dockerfilelint
94+
stages: [commit] # required
95+
96+
# miscellaneous
97+
98+
- repo: https://github.com/pre-commit/pre-commit-hooks
99+
rev: v2.0.0
100+
hooks:
101+
- id: check-added-large-files
102+
- id: check-docstring-first
103+
- id: debug-statements
104+
- id: end-of-file-fixer
105+
- id: flake8
106+
additional_dependencies: ["flake8-bugbear"]
107+
- id: trailing-whitespace
108+
- id: check-ast
109+
- id: check-builtin-literals
110+
- id: detect-private-key
111+
- id: mixed-line-ending
112+
- id: name-tests-test
113+
args: ["--django"]
114+
115+
- repo: https://github.com/pre-commit/pygrep-hooks
116+
rev: v1.4.0
117+
hooks:
118+
# - id: rst-backticks
119+
- id: python-use-type-annotations
120+
- id: python-no-log-warn
121+
- id: python-no-eval
122+
- id: python-check-mock-methods
123+
- id: python-check-blanket-noqa
124+
125+
# commit-msg
126+
# http://jorisroovers.com/gitlint/#using-gitlint-through-pre-commit
127+
128+
- repo: https://github.com/jorisroovers/gitlint
129+
rev: v0.12.0
130+
hooks:
131+
- id: gitlint

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ default: docker
1010
install:
1111
poetry install
1212

13-
test: install
14-
poetry run flake8
15-
poetry run black --check kube_janitor
13+
.PHONY: lint
14+
lint:
15+
poetry run pre-commit run --all-files
16+
17+
test: install lint
1618
poetry run mypy --ignore-missing-imports kube_janitor
1719
poetry run coverage run --source=kube_janitor -m py.test -v
1820
poetry run coverage report
1921

20-
docker:
22+
docker:
2123
docker build --build-arg "VERSION=$(VERSION)" -t "$(IMAGE):$(TAG)" .
2224
@echo 'Docker image $(IMAGE):$(TAG) can now be used.'
2325

helm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ Some of the default values are not specified in the `values.yaml` and are instea
3131
| `restartPolicy` | `PodSpec` for pod restarting policy on failure | string | `OnFailure` |
3232
| `nodeSelector` | `PodSpec` for defining nodeSelector to deploy the pod on | map | `{}` |
3333
| `affinity` | `PodSpec` for defining affinity to deploy the pod on | map | `{}` |
34-
| `tolerations` | `PodSpec` for defining tolerations to deploy the pod on | map | `{}` |
34+
| `tolerations` | `PodSpec` for defining tolerations to deploy the pod on | map | `{}` |

helm/templates/cluster-role.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ rules:
1313
verbs: ["create"]
1414
- apiGroups: ["*"]
1515
resources: ["*"]
16-
verbs: ["get", "watch", "list", "delete"]
16+
verbs: ["get", "watch", "list", "delete"]

helm/templates/configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ data:
77
# example rules configuration to set TTL for arbitrary objects
88
# see https://github.com/hjacobs/kube-janitor for details
99
rules:
10-
{{ toYaml .Values.kubejanitor.rules | indent 6 }}
10+
{{ toYaml .Values.kubejanitor.rules | indent 6 }}

helm/templates/cron-job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ spec:
8585
volumes:
8686
- name: {{ template "chart.fullname" . }}-volume
8787
configMap:
88-
name: {{ template "chart.fullname" . }}
88+
name: {{ template "chart.fullname" . }}

kube_janitor/cmd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import os
2-
31
import argparse
2+
import os
43

54
DEFAULT_EXCLUDE_RESOURCES = "events,controllerrevisions"
65
DEFAULT_EXCLUDE_NAMESPACES = "kube-system"

kube_janitor/helper.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import datetime
12
import os
3+
import re
24

3-
import datetime
45
import pykube
5-
import re
66

77

88
TIME_UNIT_TO_SECONDS = {
@@ -54,8 +54,7 @@ def parse_expiry(expiry: str) -> datetime.datetime:
5454

5555

5656
def format_duration(seconds: int) -> str:
57-
"""
58-
Print a given duration in seconds (positive integer) as human readable duration string
57+
"""Print a given duration in seconds (positive integer) as human readable duration string.
5958
6059
>>> format_duration(3900)
6160
1h5m

kube_janitor/janitor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
from collections import Counter
44

55
import pykube
6-
from pykube import Event, Namespace
6+
from pykube import Event
7+
from pykube import Namespace
78

8-
from .helper import format_duration, parse_expiry, parse_ttl
9+
from .helper import format_duration
10+
from .helper import parse_expiry
11+
from .helper import parse_ttl
912
from .resources import get_namespaced_resource_types
1013

1114
logger = logging.getLogger(__name__)

kube_janitor/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python3
2-
3-
import time
42
import logging
3+
import time
54

6-
from kube_janitor import __version__, cmd, shutdown
5+
from kube_janitor import __version__
6+
from kube_janitor import cmd
7+
from kube_janitor import shutdown
78
from kube_janitor.helper import get_kube_api
89
from kube_janitor.janitor import clean_up
910
from kube_janitor.rules import load_rules_from_file

0 commit comments

Comments
 (0)