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

Commit 95af6a5

Browse files
authored
Add pre-commit hooks (#82)
* code formatting to match pre-commit hooks * use latest reorder dependency * bump deps, add pre-commit dep * bump poetry deps * pre-commit autoupdate
1 parent 8350694 commit 95af6a5

20 files changed

+368
-133
lines changed

.pre-commit-config.yaml

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
minimum_pre_commit_version: 1.21.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.9.0
17+
hooks:
18+
- id: reorder-python-imports
19+
20+
- repo: https://github.com/ambv/black
21+
rev: 19.10b0
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.26.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: 5.0.2
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.20.0
74+
hooks:
75+
- id: yamllint
76+
args: ["--strict", "-d", "{rules: {line-length: {max: 180}}}"]
77+
#
78+
exclude: >
79+
(?x)^(
80+
^{{.*}}.*\.yaml$|
81+
^helm-chart/templates/.*$
82+
)
83+
#
84+
85+
- repo: https://github.com/pre-commit/mirrors-mypy
86+
rev: v0.761
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.4.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.4
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

+7-5
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_downscaler
16-
poetry run mypy --ignore-missing-imports kube_downscaler
13+
.PHONY: lint
14+
lint: install
15+
poetry run pre-commit run --all-files
16+
17+
18+
test: lint install
1719
poetry run coverage run --source=kube_downscaler -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-chart/CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
0.1.0 - 10/03/2018
22
---
33
- Initial chart
4-

helm-chart/Chart.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ keywords:
88
- scheduled lifecycle
99
sources:
1010
- https://github.com/hjacobs/kube-downscaler
11-

helm-chart/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The diagram below depicts how a Kube-downscaler agent control applications.
1717
![Alt text](images/architecture.png?raw=true "Kube Kube-downscaler diagram")
1818

1919
## Quick Start
20-
Below are instructions to quickly install and configure Kube-downscaler.
20+
Below are instructions to quickly install and configure Kube-downscaler.
2121

2222
### Installing Kube-downscaler
2323

@@ -66,7 +66,7 @@ kubectl get events -w
6666

6767

6868
### Deploying sample applications using Kube-downscaler
69-
In this tutorial we will show how to deploy Kube-downscaler and test with sample Flask application.
69+
In this tutorial we will show how to deploy Kube-downscaler and test with sample Flask application.
7070

7171
1. Deploy Flask applications:
7272
```

kube_downscaler/cmd.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import os
2-
31
import argparse
2+
import os
43

54
VALID_RESOURCES = frozenset(["deployments", "statefulsets", "stacks", "cronjobs"])
65

kube_downscaler/helper.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import datetime
12
import os
3+
import re
4+
from typing import Match
25

3-
import datetime
46
import pykube
57
import pytz
6-
import re
78

89
WEEKDAYS = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
910

@@ -39,7 +40,7 @@ def matches_time_spec(time: datetime.datetime, spec: str):
3940
return False
4041

4142

42-
def _matches_recurring_time_spec(time: datetime.datetime, match: re.Match):
43+
def _matches_recurring_time_spec(time: datetime.datetime, match: Match):
4344
tz = pytz.timezone(match.group("tz"))
4445
local_time = tz.fromutc(time.replace(tzinfo=tz))
4546
day_from = WEEKDAYS.index(match.group(1).upper())
@@ -52,7 +53,7 @@ def _matches_recurring_time_spec(time: datetime.datetime, match: re.Match):
5253
return day_matches and time_matches
5354

5455

55-
def _matches_absolute_time_spec(time: datetime.datetime, match: re.Match):
56+
def _matches_absolute_time_spec(time: datetime.datetime, match: Match):
5657
time_from = datetime.datetime.fromisoformat(match.group(1))
5758
time_to = datetime.datetime.fromisoformat(match.group(2))
5859
return time_from <= time <= time_to

kube_downscaler/main.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env python3
2-
3-
import time
4-
52
import logging
3+
import time
64

7-
from kube_downscaler import __version__, cmd, shutdown
5+
from kube_downscaler import __version__
6+
from kube_downscaler import cmd
7+
from kube_downscaler import shutdown
88
from kube_downscaler.scaler import scale
99

1010
logger = logging.getLogger("downscaler")

kube_downscaler/resources/stack.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from pykube.objects import NamespacedAPIObject, ReplicatedMixin, ScalableMixin
1+
from pykube.objects import NamespacedAPIObject
2+
from pykube.objects import ReplicatedMixin
3+
from pykube.objects import ScalableMixin
24

35

46
class Stack(NamespacedAPIObject, ReplicatedMixin, ScalableMixin):
5-
"""
6-
Support the Stack resource (https://github.com/zalando-incubator/stackset-controller)
7-
"""
7+
8+
"""Support the Stack resource (https://github.com/zalando-incubator/stackset-controller)."""
89

910
version = "zalando.org/v1"
1011
endpoint = "stacks"

kube_downscaler/scaler.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import datetime
22
import logging
3-
import pykube
43
from typing import FrozenSet
54

5+
import pykube
6+
from pykube import CronJob
7+
from pykube import Deployment
8+
from pykube import StatefulSet
9+
610
from kube_downscaler import helper
7-
from pykube import Deployment, StatefulSet, CronJob
811
from kube_downscaler.resources.stack import Stack
912

1013
logger = logging.getLogger(__name__)
@@ -27,7 +30,7 @@ def within_grace_period(deploy, grace_period: int, now: datetime.datetime):
2730

2831

2932
def pods_force_uptime(api, namespace: str):
30-
"""Returns True if there are any running pods which require the deployments to be scaled back up"""
33+
"""Return True if there are any running pods which require the deployments to be scaled back up."""
3134
for pod in pykube.Pod.objects(api).filter(namespace=(namespace or pykube.all)):
3235
if pod.obj.get("status", {}).get("phase") in ("Succeeded", "Failed"):
3336
continue

kube_downscaler/shutdown.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import sys
2-
31
import contextlib
42
import signal
3+
import sys
54

65

76
class GracefulShutdown:

0 commit comments

Comments
 (0)