diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..89ad1cd --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,131 @@ +--- +minimum_pre_commit_version: 1.21.0 +fail_fast: false +default_stages: [commit, push] +repos: + # meta + + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + + # formatters + + - repo: https://github.com/asottile/reorder_python_imports + rev: v1.9.0 + hooks: + - id: reorder-python-imports + + - repo: https://github.com/ambv/black + rev: 19.10b0 + hooks: + - id: black + + # - repo: https://github.com/pre-commit/mirrors-yapf + # rev: v0.28.0 + # hooks: + # - id: yapf + + - repo: https://github.com/asottile/pyupgrade + rev: v1.26.0 + hooks: + - id: pyupgrade + stages: [push] + + # linters + + - repo: https://github.com/PyCQA/bandit + rev: 1.6.2 + hooks: + - id: bandit + args: ["-x", "tests"] + stages: [push] + + - repo: https://github.com/PyCQA/pydocstyle + rev: 5.0.2 + hooks: + - id: pydocstyle + args: ["--ignore=D10,D21,D202"] + + + - repo: local + hooks: + + - id: safety + name: safety + entry: safety + language: system + pass_filenames: false + args: ["check", "--bare"] + stages: [push] + + - id: poetry + name: poetry + description: Validates the structure of the pyproject.toml file + entry: poetry check + language: system + pass_filenames: false + files: ^pyproject.toml$ + stages: [push] + + - repo: https://github.com/adrienverge/yamllint + rev: v1.20.0 + hooks: + - id: yamllint + args: ["--strict", "-d", "{rules: {line-length: {max: 180}}}"] + # + exclude: > + (?x)^( + ^{{.*}}.*\.yaml$| + ^helm-chart/templates/.*$ + ) + # + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.761 + hooks: + - id: mypy + + - repo: https://github.com/pryorda/dockerfilelint-precommit-hooks + rev: v0.1.0 + hooks: + - id: dockerfilelint + stages: [commit] # required + + # miscellaneous + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: check-added-large-files + - id: check-docstring-first + - id: debug-statements + - id: end-of-file-fixer + - id: flake8 + additional_dependencies: ["flake8-bugbear"] + - id: trailing-whitespace + - id: check-ast + - id: check-builtin-literals + - id: detect-private-key + - id: mixed-line-ending + - id: name-tests-test + args: ["--django"] + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.4.4 + hooks: + # - id: rst-backticks + - id: python-use-type-annotations + - id: python-no-log-warn + - id: python-no-eval + - id: python-check-mock-methods + - id: python-check-blanket-noqa + + # commit-msg + # http://jorisroovers.com/gitlint/#using-gitlint-through-pre-commit + + - repo: https://github.com/jorisroovers/gitlint + rev: v0.12.0 + hooks: + - id: gitlint diff --git a/Makefile b/Makefile index 2394523..6d5c23b 100644 --- a/Makefile +++ b/Makefile @@ -10,14 +10,16 @@ default: docker install: poetry install -test: install - poetry run flake8 - poetry run black --check kube_downscaler - poetry run mypy --ignore-missing-imports kube_downscaler +.PHONY: lint +lint: install + poetry run pre-commit run --all-files + + +test: lint install poetry run coverage run --source=kube_downscaler -m py.test -v poetry run coverage report -docker: +docker: docker build --build-arg "VERSION=$(VERSION)" -t "$(IMAGE):$(TAG)" . @echo 'Docker image $(IMAGE):$(TAG) can now be used.' diff --git a/helm-chart/CHANGELOG.md b/helm-chart/CHANGELOG.md index 82b277d..5aff7d8 100644 --- a/helm-chart/CHANGELOG.md +++ b/helm-chart/CHANGELOG.md @@ -1,4 +1,3 @@ 0.1.0 - 10/03/2018 --- - Initial chart - diff --git a/helm-chart/Chart.yaml b/helm-chart/Chart.yaml index 4d7ad48..87991c1 100644 --- a/helm-chart/Chart.yaml +++ b/helm-chart/Chart.yaml @@ -8,4 +8,3 @@ keywords: - scheduled lifecycle sources: - https://github.com/hjacobs/kube-downscaler - diff --git a/helm-chart/README.md b/helm-chart/README.md index 9530b45..f0ff22b 100644 --- a/helm-chart/README.md +++ b/helm-chart/README.md @@ -17,7 +17,7 @@ The diagram below depicts how a Kube-downscaler agent control applications. ![Alt text](images/architecture.png?raw=true "Kube Kube-downscaler diagram") ## Quick Start -Below are instructions to quickly install and configure Kube-downscaler. +Below are instructions to quickly install and configure Kube-downscaler. ### Installing Kube-downscaler @@ -66,7 +66,7 @@ kubectl get events -w ### Deploying sample applications using Kube-downscaler -In this tutorial we will show how to deploy Kube-downscaler and test with sample Flask application. +In this tutorial we will show how to deploy Kube-downscaler and test with sample Flask application. 1. Deploy Flask applications: ``` diff --git a/kube_downscaler/cmd.py b/kube_downscaler/cmd.py index 053593b..d7aff7a 100644 --- a/kube_downscaler/cmd.py +++ b/kube_downscaler/cmd.py @@ -1,6 +1,5 @@ -import os - import argparse +import os VALID_RESOURCES = frozenset(["deployments", "statefulsets", "stacks", "cronjobs"]) diff --git a/kube_downscaler/helper.py b/kube_downscaler/helper.py index 48c214a..6e09355 100644 --- a/kube_downscaler/helper.py +++ b/kube_downscaler/helper.py @@ -1,9 +1,10 @@ +import datetime import os +import re +from typing import Match -import datetime import pykube import pytz -import re WEEKDAYS = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"] @@ -39,7 +40,7 @@ def matches_time_spec(time: datetime.datetime, spec: str): return False -def _matches_recurring_time_spec(time: datetime.datetime, match: re.Match): +def _matches_recurring_time_spec(time: datetime.datetime, match: Match): tz = pytz.timezone(match.group("tz")) local_time = tz.fromutc(time.replace(tzinfo=tz)) day_from = WEEKDAYS.index(match.group(1).upper()) @@ -52,7 +53,7 @@ def _matches_recurring_time_spec(time: datetime.datetime, match: re.Match): return day_matches and time_matches -def _matches_absolute_time_spec(time: datetime.datetime, match: re.Match): +def _matches_absolute_time_spec(time: datetime.datetime, match: Match): time_from = datetime.datetime.fromisoformat(match.group(1)) time_to = datetime.datetime.fromisoformat(match.group(2)) return time_from <= time <= time_to diff --git a/kube_downscaler/main.py b/kube_downscaler/main.py index 2c52660..903e0e6 100755 --- a/kube_downscaler/main.py +++ b/kube_downscaler/main.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 - -import time - import logging +import time -from kube_downscaler import __version__, cmd, shutdown +from kube_downscaler import __version__ +from kube_downscaler import cmd +from kube_downscaler import shutdown from kube_downscaler.scaler import scale logger = logging.getLogger("downscaler") diff --git a/kube_downscaler/resources/stack.py b/kube_downscaler/resources/stack.py index a79b5ca..0de5b9c 100644 --- a/kube_downscaler/resources/stack.py +++ b/kube_downscaler/resources/stack.py @@ -1,10 +1,11 @@ -from pykube.objects import NamespacedAPIObject, ReplicatedMixin, ScalableMixin +from pykube.objects import NamespacedAPIObject +from pykube.objects import ReplicatedMixin +from pykube.objects import ScalableMixin class Stack(NamespacedAPIObject, ReplicatedMixin, ScalableMixin): - """ - Support the Stack resource (https://github.com/zalando-incubator/stackset-controller) - """ + + """Support the Stack resource (https://github.com/zalando-incubator/stackset-controller).""" version = "zalando.org/v1" endpoint = "stacks" diff --git a/kube_downscaler/scaler.py b/kube_downscaler/scaler.py index a443163..29ef516 100644 --- a/kube_downscaler/scaler.py +++ b/kube_downscaler/scaler.py @@ -1,10 +1,13 @@ import datetime import logging -import pykube from typing import FrozenSet +import pykube +from pykube import CronJob +from pykube import Deployment +from pykube import StatefulSet + from kube_downscaler import helper -from pykube import Deployment, StatefulSet, CronJob from kube_downscaler.resources.stack import Stack logger = logging.getLogger(__name__) @@ -27,7 +30,7 @@ def within_grace_period(deploy, grace_period: int, now: datetime.datetime): def pods_force_uptime(api, namespace: str): - """Returns True if there are any running pods which require the deployments to be scaled back up""" + """Return True if there are any running pods which require the deployments to be scaled back up.""" for pod in pykube.Pod.objects(api).filter(namespace=(namespace or pykube.all)): if pod.obj.get("status", {}).get("phase") in ("Succeeded", "Failed"): continue diff --git a/kube_downscaler/shutdown.py b/kube_downscaler/shutdown.py index cfa1075..3bb93d3 100644 --- a/kube_downscaler/shutdown.py +++ b/kube_downscaler/shutdown.py @@ -1,7 +1,6 @@ -import sys - import contextlib import signal +import sys class GracefulShutdown: diff --git a/poetry.lock b/poetry.lock index 48ec40d..7d52d2a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6,6 +6,17 @@ optional = false python-versions = "*" version = "1.4.3" +[[package]] +category = "dev" +description = "A few extensions to pyyaml." +name = "aspy.yaml" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.3.0" + +[package.dependencies] +pyyaml = "*" + [[package]] category = "dev" description = "Atomic file writes." @@ -57,6 +68,17 @@ optional = false python-versions = "*" version = "2019.11.28" +[[package]] +category = "dev" +description = "Validate configuration and produce human readable error messages." +name = "cfgv" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "2.0.1" + +[package.dependencies] +six = "*" + [[package]] category = "main" description = "Universal encoding detector for Python 2 and 3" @@ -96,10 +118,10 @@ description = "Show coverage stats online via coveralls.io" name = "coveralls" optional = false python-versions = "*" -version = "1.9.2" +version = "1.10.0" [package.dependencies] -coverage = ">=3.6,<5.0" +coverage = ">=3.6,<6.0" docopt = ">=0.6.1" requests = ">=1.0.0" @@ -136,6 +158,17 @@ mccabe = ">=0.6.0,<0.7.0" pycodestyle = ">=2.5.0,<2.6.0" pyflakes = ">=2.1.0,<2.2.0" +[[package]] +category = "dev" +description = "File identification library for Python" +name = "identify" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" +version = "1.4.9" + +[package.extras] +license = ["editdistance"] + [[package]] category = "main" description = "Internationalized Domain Names in Applications (IDNA)" @@ -151,7 +184,7 @@ marker = "python_version < \"3.8\"" name = "importlib-metadata" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" -version = "1.3.0" +version = "1.4.0" [package.dependencies] zipp = ">=0.5" @@ -174,7 +207,7 @@ description = "More routines for operating on iterables, beyond itertools" name = "more-itertools" optional = false python-versions = ">=3.5" -version = "8.0.2" +version = "8.1.0" [[package]] category = "dev" @@ -200,13 +233,21 @@ optional = false python-versions = "*" version = "0.4.3" +[[package]] +category = "dev" +description = "Node.js virtual environment builder" +name = "nodeenv" +optional = false +python-versions = "*" +version = "1.3.4" + [[package]] category = "dev" description = "Core utilities for Python packages" name = "packaging" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "19.2" +version = "20.0" [package.dependencies] pyparsing = ">=2.0.2" @@ -217,8 +258,8 @@ category = "dev" description = "Utility library for gitignore style pattern matching of file paths." name = "pathspec" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "0.6.0" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "0.7.0" [[package]] category = "dev" @@ -236,13 +277,35 @@ version = ">=0.12" [package.extras] dev = ["pre-commit", "tox"] +[[package]] +category = "dev" +description = "A framework for managing and maintaining multi-language pre-commit hooks." +name = "pre-commit" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" +version = "1.21.0" + +[package.dependencies] +"aspy.yaml" = "*" +cfgv = ">=2.0.0" +identify = ">=1.0.0" +nodeenv = ">=0.11.1" +pyyaml = "*" +six = "*" +toml = "*" +virtualenv = ">=15.2" + +[package.dependencies.importlib-metadata] +python = "<3.8" +version = "*" + [[package]] category = "dev" description = "library with cross-python path, ini-parsing, io, code, log facilities" name = "py" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "1.8.0" +version = "1.8.1" [[package]] category = "dev" @@ -265,11 +328,11 @@ category = "main" description = "Python client library for Kubernetes" name = "pykube-ng" optional = false -python-versions = "*" -version = "19.12.0" +python-versions = ">=3.6" +version = "19.12.1" [package.dependencies] -PyYAML = "*" +pyyaml = "*" requests = ">=2.12" [package.extras] @@ -281,7 +344,7 @@ description = "Python parsing module" name = "pyparsing" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" -version = "2.4.5" +version = "2.4.6" [[package]] category = "dev" @@ -336,8 +399,8 @@ category = "main" description = "YAML parser and emitter for Python" name = "pyyaml" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -version = "5.2" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "5.3" [[package]] category = "dev" @@ -345,7 +408,7 @@ description = "Alternative regular expression module, to replace re." name = "regex" optional = false python-versions = "*" -version = "2019.12.20" +version = "2020.1.8" [[package]] category = "main" @@ -409,13 +472,25 @@ version = "1.22" secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"] +[[package]] +category = "dev" +description = "Virtual Python Environment builder" +name = "virtualenv" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" +version = "16.7.9" + +[package.extras] +docs = ["sphinx (>=1.8.0,<2)", "towncrier (>=18.5.0)", "sphinx-rtd-theme (>=0.4.2,<1)"] +testing = ["pytest (>=4.0.0,<5)", "coverage (>=4.5.0,<5)", "pytest-timeout (>=1.3.0,<2)", "six (>=1.10.0,<2)", "pytest-xdist", "pytest-localserver", "pypiserver", "mock", "xonsh"] + [[package]] category = "dev" description = "Measures number of Terminal column cells of wide-character codes" name = "wcwidth" optional = false python-versions = "*" -version = "0.1.7" +version = "0.1.8" [[package]] category = "dev" @@ -434,7 +509,7 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] testing = ["pathlib2", "contextlib2", "unittest2"] [metadata] -content-hash = "4ac96ff5610fb67c01927433d5cd95a46a5d2aecdc0e37993d15b144d3e97728" +content-hash = "e447200c96ef9b3f7513b5cbe07e050446b56c5ff0020986c9980c6e1f693c81" python-versions = ">=3.7" [metadata.files] @@ -442,6 +517,10 @@ appdirs = [ {file = "appdirs-1.4.3-py2.py3-none-any.whl", hash = "sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e"}, {file = "appdirs-1.4.3.tar.gz", hash = "sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92"}, ] +"aspy.yaml" = [ + {file = "aspy.yaml-1.3.0-py2.py3-none-any.whl", hash = "sha256:463372c043f70160a9ec950c3f1e4c3a82db5fca01d334b6bc89c7164d744bdc"}, + {file = "aspy.yaml-1.3.0.tar.gz", hash = "sha256:e7c742382eff2caed61f87a39d13f99109088e5e93f04d76eb8d4b28aa143f45"}, +] atomicwrites = [ {file = "atomicwrites-1.3.0-py2.py3-none-any.whl", hash = "sha256:03472c30eb2c5d1ba9227e4c2ca66ab8287fbfbbda3888aa93dc2e28fc6811b4"}, {file = "atomicwrites-1.3.0.tar.gz", hash = "sha256:75a9445bac02d8d058d5e1fe689654ba5a6556a1dfd8ce6ec55a0ed79866cfa6"}, @@ -458,6 +537,10 @@ certifi = [ {file = "certifi-2019.11.28-py2.py3-none-any.whl", hash = "sha256:017c25db2a153ce562900032d5bc68e9f191e44e9a0f762f373977de9df1fbb3"}, {file = "certifi-2019.11.28.tar.gz", hash = "sha256:25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f"}, ] +cfgv = [ + {file = "cfgv-2.0.1-py2.py3-none-any.whl", hash = "sha256:fbd93c9ab0a523bf7daec408f3be2ed99a980e20b2d19b50fc184ca6b820d289"}, + {file = "cfgv-2.0.1.tar.gz", hash = "sha256:edb387943b665bf9c434f717bf630fa78aecd53d5900d2e05da6ad6048553144"}, +] chardet = [ {file = "chardet-3.0.4-py2.py3-none-any.whl", hash = "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"}, {file = "chardet-3.0.4.tar.gz", hash = "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"}, @@ -513,8 +596,8 @@ coverage = [ {file = "coverage-4.4.2.win32-py3.6.exe", hash = "sha256:f98b461cb59f117887aa634a66022c0bd394278245ed51189f63a036516e32de"}, ] coveralls = [ - {file = "coveralls-1.9.2-py2.py3-none-any.whl", hash = "sha256:25522a50cdf720d956601ca6ef480786e655ae2f0c94270c77e1a23d742de558"}, - {file = "coveralls-1.9.2.tar.gz", hash = "sha256:8e3315e8620bb6b3c6f3179a75f498e7179c93b3ddc440352404f941b1f70524"}, + {file = "coveralls-1.10.0-py2.py3-none-any.whl", hash = "sha256:906e07a12b2ac04b8ad782d06173975fe5ff815fe9df3bfedd2c099bc5791aec"}, + {file = "coveralls-1.10.0.tar.gz", hash = "sha256:2da39aeaef986757653f0a442ba2bef22a8ec602c8bacbc69d39f468dfae12ec"}, ] docopt = [ {file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"}, @@ -527,21 +610,25 @@ flake8 = [ {file = "flake8-3.7.9-py2.py3-none-any.whl", hash = "sha256:49356e766643ad15072a789a20915d3c91dc89fd313ccd71802303fd67e4deca"}, {file = "flake8-3.7.9.tar.gz", hash = "sha256:45681a117ecc81e870cbf1262835ae4af5e7a8b08e40b944a8a6e6b895914cfb"}, ] +identify = [ + {file = "identify-1.4.9-py2.py3-none-any.whl", hash = "sha256:72e9c4ed3bc713c7045b762b0d2e2115c572b85abfc1f4604f5a4fd4c6642b71"}, + {file = "identify-1.4.9.tar.gz", hash = "sha256:6f44e637caa40d1b4cb37f6ed3b262ede74901d28b1cc5b1fc07360871edd65d"}, +] idna = [ {file = "idna-2.8-py2.py3-none-any.whl", hash = "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c"}, {file = "idna-2.8.tar.gz", hash = "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407"}, ] importlib-metadata = [ - {file = "importlib_metadata-1.3.0-py2.py3-none-any.whl", hash = "sha256:d95141fbfa7ef2ec65cfd945e2af7e5a6ddbd7c8d9a25e66ff3be8e3daf9f60f"}, - {file = "importlib_metadata-1.3.0.tar.gz", hash = "sha256:073a852570f92da5f744a3472af1b61e28e9f78ccf0c9117658dc32b15de7b45"}, + {file = "importlib_metadata-1.4.0-py2.py3-none-any.whl", hash = "sha256:bdd9b7c397c273bcc9a11d6629a38487cd07154fa255a467bf704cd2c258e359"}, + {file = "importlib_metadata-1.4.0.tar.gz", hash = "sha256:f17c015735e1a88296994c0697ecea7e11db24290941983b08c9feb30921e6d8"}, ] mccabe = [ {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, ] more-itertools = [ - {file = "more-itertools-8.0.2.tar.gz", hash = "sha256:b84b238cce0d9adad5ed87e745778d20a3f8487d0f0cb8b8a586816c7496458d"}, - {file = "more_itertools-8.0.2-py3-none-any.whl", hash = "sha256:c833ef592a0324bcc6a60e48440da07645063c453880c9477ceb22490aec1564"}, + {file = "more-itertools-8.1.0.tar.gz", hash = "sha256:c468adec578380b6281a114cb8a5db34eb1116277da92d7c46f904f0b52d3288"}, + {file = "more_itertools-8.1.0-py3-none-any.whl", hash = "sha256:1a2a32c72400d365000412fe08eb4a24ebee89997c18d3d147544f70f5403b39"}, ] mypy = [ {file = "mypy-0.761-cp35-cp35m-macosx_10_6_x86_64.whl", hash = "sha256:7f672d02fffcbace4db2b05369142e0506cdcde20cea0e07c7c2171c4fd11dd6"}, @@ -563,20 +650,28 @@ mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, ] +nodeenv = [ + {file = "nodeenv-1.3.4-py2.py3-none-any.whl", hash = "sha256:561057acd4ae3809e665a9aaaf214afff110bbb6a6d5c8a96121aea6878408b3"}, +] packaging = [ - {file = "packaging-19.2-py2.py3-none-any.whl", hash = "sha256:d9551545c6d761f3def1677baf08ab2a3ca17c56879e70fecba2fc4dde4ed108"}, - {file = "packaging-19.2.tar.gz", hash = "sha256:28b924174df7a2fa32c1953825ff29c61e2f5e082343165438812f00d3a7fc47"}, + {file = "packaging-20.0-py2.py3-none-any.whl", hash = "sha256:aec3fdbb8bc9e4bb65f0634b9f551ced63983a529d6a8931817d52fdd0816ddb"}, + {file = "packaging-20.0.tar.gz", hash = "sha256:fe1d8331dfa7cc0a883b49d75fc76380b2ab2734b220fbb87d774e4fd4b851f8"}, ] pathspec = [ - {file = "pathspec-0.6.0.tar.gz", hash = "sha256:e285ccc8b0785beadd4c18e5708b12bb8fcf529a1e61215b3feff1d1e559ea5c"}, + {file = "pathspec-0.7.0-py2.py3-none-any.whl", hash = "sha256:163b0632d4e31cef212976cf57b43d9fd6b0bac6e67c26015d611a647d5e7424"}, + {file = "pathspec-0.7.0.tar.gz", hash = "sha256:562aa70af2e0d434367d9790ad37aed893de47f1693e4201fd1d3dca15d19b96"}, ] pluggy = [ {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, ] +pre-commit = [ + {file = "pre_commit-1.21.0-py2.py3-none-any.whl", hash = "sha256:f92a359477f3252452ae2e8d3029de77aec59415c16ae4189bcfba40b757e029"}, + {file = "pre_commit-1.21.0.tar.gz", hash = "sha256:8f48d8637bdae6fa70cc97db9c1dd5aa7c5c8bf71968932a380628c25978b850"}, +] py = [ - {file = "py-1.8.0-py2.py3-none-any.whl", hash = "sha256:64f65755aee5b381cea27766a3a147c3f15b9b6b9ac88676de66ba2ae36793fa"}, - {file = "py-1.8.0.tar.gz", hash = "sha256:dc639b046a6e2cff5bbe40194ad65936d6ba360b52b3c3fe1d08a82dd50b5e53"}, + {file = "py-1.8.1-py2.py3-none-any.whl", hash = "sha256:c20fdd83a5dbc0af9efd622bee9a5564e278f6380fffcacc43ba6f43db2813b0"}, + {file = "py-1.8.1.tar.gz", hash = "sha256:5e27081401262157467ad6e7f851b7aa402c5852dbcb3dae06768434de5752aa"}, ] pycodestyle = [ {file = "pycodestyle-2.5.0-py2.py3-none-any.whl", hash = "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56"}, @@ -587,12 +682,12 @@ pyflakes = [ {file = "pyflakes-2.1.1.tar.gz", hash = "sha256:d976835886f8c5b31d47970ed689944a0262b5f3afa00a5a7b4dc81e5449f8a2"}, ] pykube-ng = [ - {file = "pykube-ng-19.12.0.tar.gz", hash = "sha256:58a457a72c12fc22fa4c69018450818df7ec3498b67dfe4636cb3b59bcfbc08c"}, - {file = "pykube_ng-19.12.0-py2.py3-none-any.whl", hash = "sha256:260c09afff66e97f036a5fa16942271931e8f5f9e7c996f677aebb84b5cec853"}, + {file = "pykube-ng-19.12.1.tar.gz", hash = "sha256:d8d184a4834e577236508198f0db8d6d46508698512ac742b6861d47de79265c"}, + {file = "pykube_ng-19.12.1-py3-none-any.whl", hash = "sha256:46974ff355d7d18ca9c3722f957e1182fb27a0401c4c06942bdfcd7e11ecffd3"}, ] pyparsing = [ - {file = "pyparsing-2.4.5-py2.py3-none-any.whl", hash = "sha256:20f995ecd72f2a1f4bf6b072b63b22e2eb457836601e76d6e5dfcd75436acc1f"}, - {file = "pyparsing-2.4.5.tar.gz", hash = "sha256:4ca62001be367f01bd3e92ecbb79070272a9d4964dce6a48a82ff0b8bc7e683a"}, + {file = "pyparsing-2.4.6-py2.py3-none-any.whl", hash = "sha256:c342dccb5250c08d45fd6f8b4a559613ca603b57498511740e65cd11a2e7dcec"}, + {file = "pyparsing-2.4.6.tar.gz", hash = "sha256:4c830582a84fb022400b85429791bc551f1f4871c33f23e44f353119e92f969f"}, ] pytest = [ {file = "pytest-5.3.2-py3-none-any.whl", hash = "sha256:e41d489ff43948babd0fad7ad5e49b8735d5d55e26628a58673c39ff61d95de4"}, @@ -607,40 +702,40 @@ pytz = [ {file = "pytz-2019.3.tar.gz", hash = "sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be"}, ] pyyaml = [ - {file = "PyYAML-5.2-cp27-cp27m-win32.whl", hash = "sha256:35ace9b4147848cafac3db142795ee42deebe9d0dad885ce643928e88daebdcc"}, - {file = "PyYAML-5.2-cp27-cp27m-win_amd64.whl", hash = "sha256:ebc4ed52dcc93eeebeae5cf5deb2ae4347b3a81c3fa12b0b8c976544829396a4"}, - {file = "PyYAML-5.2-cp35-cp35m-win32.whl", hash = "sha256:38a4f0d114101c58c0f3a88aeaa44d63efd588845c5a2df5290b73db8f246d15"}, - {file = "PyYAML-5.2-cp35-cp35m-win_amd64.whl", hash = "sha256:483eb6a33b671408c8529106df3707270bfacb2447bf8ad856a4b4f57f6e3075"}, - {file = "PyYAML-5.2-cp36-cp36m-win32.whl", hash = "sha256:7f38e35c00e160db592091751d385cd7b3046d6d51f578b29943225178257b31"}, - {file = "PyYAML-5.2-cp36-cp36m-win_amd64.whl", hash = "sha256:0e7f69397d53155e55d10ff68fdfb2cf630a35e6daf65cf0bdeaf04f127c09dc"}, - {file = "PyYAML-5.2-cp37-cp37m-win32.whl", hash = "sha256:e4c015484ff0ff197564917b4b4246ca03f411b9bd7f16e02a2f586eb48b6d04"}, - {file = "PyYAML-5.2-cp37-cp37m-win_amd64.whl", hash = "sha256:4b6be5edb9f6bb73680f5bf4ee08ff25416d1400fbd4535fe0069b2994da07cd"}, - {file = "PyYAML-5.2-cp38-cp38-win32.whl", hash = "sha256:8100c896ecb361794d8bfdb9c11fce618c7cf83d624d73d5ab38aef3bc82d43f"}, - {file = "PyYAML-5.2-cp38-cp38-win_amd64.whl", hash = "sha256:2e9f0b7c5914367b0916c3c104a024bb68f269a486b9d04a2e8ac6f6597b7803"}, - {file = "PyYAML-5.2.tar.gz", hash = "sha256:c0ee8eca2c582d29c3c2ec6e2c4f703d1b7f1fb10bc72317355a746057e7346c"}, + {file = "PyYAML-5.3-cp27-cp27m-win32.whl", hash = "sha256:940532b111b1952befd7db542c370887a8611660d2b9becff75d39355303d82d"}, + {file = "PyYAML-5.3-cp27-cp27m-win_amd64.whl", hash = "sha256:059b2ee3194d718896c0ad077dd8c043e5e909d9180f387ce42012662a4946d6"}, + {file = "PyYAML-5.3-cp35-cp35m-win32.whl", hash = "sha256:4fee71aa5bc6ed9d5f116327c04273e25ae31a3020386916905767ec4fc5317e"}, + {file = "PyYAML-5.3-cp35-cp35m-win_amd64.whl", hash = "sha256:dbbb2379c19ed6042e8f11f2a2c66d39cceb8aeace421bfc29d085d93eda3689"}, + {file = "PyYAML-5.3-cp36-cp36m-win32.whl", hash = "sha256:e3a057b7a64f1222b56e47bcff5e4b94c4f61faac04c7c4ecb1985e18caa3994"}, + {file = "PyYAML-5.3-cp36-cp36m-win_amd64.whl", hash = "sha256:74782fbd4d4f87ff04159e986886931456a1894c61229be9eaf4de6f6e44b99e"}, + {file = "PyYAML-5.3-cp37-cp37m-win32.whl", hash = "sha256:24521fa2890642614558b492b473bee0ac1f8057a7263156b02e8b14c88ce6f5"}, + {file = "PyYAML-5.3-cp37-cp37m-win_amd64.whl", hash = "sha256:1cf708e2ac57f3aabc87405f04b86354f66799c8e62c28c5fc5f88b5521b2dbf"}, + {file = "PyYAML-5.3-cp38-cp38-win32.whl", hash = "sha256:70024e02197337533eef7b85b068212420f950319cc8c580261963aefc75f811"}, + {file = "PyYAML-5.3-cp38-cp38-win_amd64.whl", hash = "sha256:cb1f2f5e426dc9f07a7681419fe39cee823bb74f723f36f70399123f439e9b20"}, + {file = "PyYAML-5.3.tar.gz", hash = "sha256:e9f45bd5b92c7974e59bcd2dcc8631a6b6cc380a904725fce7bc08872e691615"}, ] regex = [ - {file = "regex-2019.12.20-cp27-cp27m-win32.whl", hash = "sha256:7bbbdbada3078dc360d4692a9b28479f569db7fc7f304b668787afc9feb38ec8"}, - {file = "regex-2019.12.20-cp27-cp27m-win_amd64.whl", hash = "sha256:a83049eb717ae828ced9cf607845929efcb086a001fc8af93ff15c50012a5716"}, - {file = "regex-2019.12.20-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:27d1bd20d334f50b7ef078eba0f0756a640fd25f5f1708d3b5bed18a5d6bced9"}, - {file = "regex-2019.12.20-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:1768cf42a78a11dae63152685e7a1d90af7a8d71d2d4f6d2387edea53a9e0588"}, - {file = "regex-2019.12.20-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:4850c78b53acf664a6578bba0e9ebeaf2807bb476c14ec7e0f936f2015133cae"}, - {file = "regex-2019.12.20-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:78b3712ec529b2a71731fbb10b907b54d9c53a17ca589b42a578bc1e9a2c82ea"}, - {file = "regex-2019.12.20-cp36-cp36m-win32.whl", hash = "sha256:8d9ef7f6c403e35e73b7fc3cde9f6decdc43b1cb2ff8d058c53b9084bfcb553e"}, - {file = "regex-2019.12.20-cp36-cp36m-win_amd64.whl", hash = "sha256:faad39fdbe2c2ccda9846cd21581063086330efafa47d87afea4073a08128656"}, - {file = "regex-2019.12.20-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:adc35d38952e688535980ae2109cad3a109520033642e759f987cf47fe278aa1"}, - {file = "regex-2019.12.20-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ef0b828a7e22e58e06a1cceddba7b4665c6af8afeb22a0d8083001330572c147"}, - {file = "regex-2019.12.20-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:0e6cf1e747f383f52a0964452658c04300a9a01e8a89c55ea22813931b580aa8"}, - {file = "regex-2019.12.20-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:032fdcc03406e1a6485ec09b826eac78732943840c4b29e503b789716f051d8d"}, - {file = "regex-2019.12.20-cp37-cp37m-win32.whl", hash = "sha256:77ae8d926f38700432807ba293d768ba9e7652df0cbe76df2843b12f80f68885"}, - {file = "regex-2019.12.20-cp37-cp37m-win_amd64.whl", hash = "sha256:c29a77ad4463f71a506515d9ec3a899ed026b4b015bf43245c919ff36275444b"}, - {file = "regex-2019.12.20-cp38-cp38-manylinux1_i686.whl", hash = "sha256:57eacd38a5ec40ed7b19a968a9d01c0d977bda55664210be713e750dd7b33540"}, - {file = "regex-2019.12.20-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:724eb24b92fc5fdc1501a1b4df44a68b9c1dda171c8ef8736799e903fb100f63"}, - {file = "regex-2019.12.20-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:d508875793efdf6bab3d47850df8f40d4040ae9928d9d80864c1768d6aeaf8e3"}, - {file = "regex-2019.12.20-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:cfd31b3300fefa5eecb2fe596c6dee1b91b3a05ece9d5cfd2631afebf6c6fadd"}, - {file = "regex-2019.12.20-cp38-cp38-win32.whl", hash = "sha256:29b20f66f2e044aafba86ecf10a84e611b4667643c42baa004247f5dfef4f90b"}, - {file = "regex-2019.12.20-cp38-cp38-win_amd64.whl", hash = "sha256:d3ee0b035816e0520fac928de31b6572106f0d75597f6fa3206969a02baba06f"}, - {file = "regex-2019.12.20.tar.gz", hash = "sha256:106e25a841921d8259dcef2a42786caae35bc750fb996f830065b3dfaa67b77e"}, + {file = "regex-2020.1.8-cp27-cp27m-win32.whl", hash = "sha256:4e8f02d3d72ca94efc8396f8036c0d3bcc812aefc28ec70f35bb888c74a25161"}, + {file = "regex-2020.1.8-cp27-cp27m-win_amd64.whl", hash = "sha256:e6c02171d62ed6972ca8631f6f34fa3281d51db8b326ee397b9c83093a6b7242"}, + {file = "regex-2020.1.8-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:4eae742636aec40cf7ab98171ab9400393360b97e8f9da67b1867a9ee0889b26"}, + {file = "regex-2020.1.8-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:bd25bb7980917e4e70ccccd7e3b5740614f1c408a642c245019cff9d7d1b6149"}, + {file = "regex-2020.1.8-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:3e77409b678b21a056415da3a56abfd7c3ad03da71f3051bbcdb68cf44d3c34d"}, + {file = "regex-2020.1.8-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:07b39bf943d3d2fe63d46281d8504f8df0ff3fe4c57e13d1656737950e53e525"}, + {file = "regex-2020.1.8-cp36-cp36m-win32.whl", hash = "sha256:23e2c2c0ff50f44877f64780b815b8fd2e003cda9ce817a7fd00dea5600c84a0"}, + {file = "regex-2020.1.8-cp36-cp36m-win_amd64.whl", hash = "sha256:27429b8d74ba683484a06b260b7bb00f312e7c757792628ea251afdbf1434003"}, + {file = "regex-2020.1.8-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:0e182d2f097ea8549a249040922fa2b92ae28be4be4895933e369a525ba36576"}, + {file = "regex-2020.1.8-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e3cd21cc2840ca67de0bbe4071f79f031c81418deb544ceda93ad75ca1ee9f7b"}, + {file = "regex-2020.1.8-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:ecc6de77df3ef68fee966bb8cb4e067e84d4d1f397d0ef6fce46913663540d77"}, + {file = "regex-2020.1.8-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:26ff99c980f53b3191d8931b199b29d6787c059f2e029b2b0c694343b1708c35"}, + {file = "regex-2020.1.8-cp37-cp37m-win32.whl", hash = "sha256:7bcd322935377abcc79bfe5b63c44abd0b29387f267791d566bbb566edfdd146"}, + {file = "regex-2020.1.8-cp37-cp37m-win_amd64.whl", hash = "sha256:10671601ee06cf4dc1bc0b4805309040bb34c9af423c12c379c83d7895622bb5"}, + {file = "regex-2020.1.8-cp38-cp38-manylinux1_i686.whl", hash = "sha256:98b8ed7bb2155e2cbb8b76f627b2fd12cf4b22ab6e14873e8641f266e0fb6d8f"}, + {file = "regex-2020.1.8-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:6a6ba91b94427cd49cd27764679024b14a96874e0dc638ae6bdd4b1a3ce97be1"}, + {file = "regex-2020.1.8-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:6a6ae17bf8f2d82d1e8858a47757ce389b880083c4ff2498dba17c56e6c103b9"}, + {file = "regex-2020.1.8-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:0932941cdfb3afcbc26cc3bcf7c3f3d73d5a9b9c56955d432dbf8bbc147d4c5b"}, + {file = "regex-2020.1.8-cp38-cp38-win32.whl", hash = "sha256:d58e4606da2a41659c84baeb3cfa2e4c87a74cec89a1e7c56bee4b956f9d7461"}, + {file = "regex-2020.1.8-cp38-cp38-win_amd64.whl", hash = "sha256:e7c7661f7276507bce416eaae22040fd91ca471b5b33c13f8ff21137ed6f248c"}, + {file = "regex-2020.1.8.tar.gz", hash = "sha256:d0f424328f9822b0323b3b6f2e4b9c90960b24743d220763c7f07071e0778351"}, ] requests = [ {file = "requests-2.22.0-py2.py3-none-any.whl", hash = "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31"}, @@ -686,9 +781,13 @@ urllib3 = [ {file = "urllib3-1.22-py2.py3-none-any.whl", hash = "sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b"}, {file = "urllib3-1.22.tar.gz", hash = "sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f"}, ] +virtualenv = [ + {file = "virtualenv-16.7.9-py2.py3-none-any.whl", hash = "sha256:55059a7a676e4e19498f1aad09b8313a38fcc0cdbe4fdddc0e9b06946d21b4bb"}, + {file = "virtualenv-16.7.9.tar.gz", hash = "sha256:0d62c70883c0342d59c11d0ddac0d954d0431321a41ab20851facf2b222598f3"}, +] wcwidth = [ - {file = "wcwidth-0.1.7-py2.py3-none-any.whl", hash = "sha256:f4ebe71925af7b40a864553f761ed559b43544f8f71746c2d756c7fe788ade7c"}, - {file = "wcwidth-0.1.7.tar.gz", hash = "sha256:3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e"}, + {file = "wcwidth-0.1.8-py2.py3-none-any.whl", hash = "sha256:8fd29383f539be45b20bd4df0dc29c20ba48654a41e661925e612311e9f3c603"}, + {file = "wcwidth-0.1.8.tar.gz", hash = "sha256:f28b3e8a6483e5d49e7f8949ac1a78314e740333ae305b4ba5defd3e74fb37a8"}, ] zipp = [ {file = "zipp-0.6.0-py2.py3-none-any.whl", hash = "sha256:f06903e9f1f43b12d371004b4ac7b06ab39a44adc747266928ae6debfa7b3335"}, diff --git a/pyproject.toml b/pyproject.toml index 58d3cd3..86f8a63 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,3 +18,4 @@ pytest = "*" pytest-cov = "*" black = "^19.10b0" mypy = "^0.761" +pre-commit = "^1.21.0" diff --git a/tests/test_autoscale_resource.py b/tests/test_autoscale_resource.py index 9a899bc..e903f0d 100644 --- a/tests/test_autoscale_resource.py +++ b/tests/test_autoscale_resource.py @@ -1,21 +1,20 @@ import json -import pykube -import pytest import logging +from datetime import datetime +from datetime import timezone +from unittest.mock import MagicMock -from datetime import datetime, timezone +import pykube +import pytest from pykube import Deployment -from unittest.mock import MagicMock -from kube_downscaler.scaler import ( - autoscale_resource, - EXCLUDE_ANNOTATION, - ORIGINAL_REPLICAS_ANNOTATION, - DOWNTIME_REPLICAS_ANNOTATION, - UPSCALE_PERIOD_ANNOTATION, - DOWNSCALE_PERIOD_ANNOTATION, -) from kube_downscaler.resources.stack import Stack +from kube_downscaler.scaler import autoscale_resource +from kube_downscaler.scaler import DOWNSCALE_PERIOD_ANNOTATION +from kube_downscaler.scaler import DOWNTIME_REPLICAS_ANNOTATION +from kube_downscaler.scaler import EXCLUDE_ANNOTATION +from kube_downscaler.scaler import ORIGINAL_REPLICAS_ANNOTATION +from kube_downscaler.scaler import UPSCALE_PERIOD_ANNOTATION @pytest.fixture @@ -200,8 +199,7 @@ def test_scale_up(resource): def test_scale_up_downtime_replicas_annotation(resource): - """Cli argument downtime-replicas is 1, but for 1 specific deployment we want 0. - """ + """Cli argument downtime-replicas is 1, but for 1 specific deployment we want 0.""" resource.annotations = { DOWNTIME_REPLICAS_ANNOTATION: "0", ORIGINAL_REPLICAS_ANNOTATION: "1", diff --git a/tests/test_grace_period.py b/tests/test_grace_period.py index 31f79a7..5717cf6 100644 --- a/tests/test_grace_period.py +++ b/tests/test_grace_period.py @@ -1,5 +1,9 @@ -from datetime import datetime, timedelta, timezone +from datetime import datetime +from datetime import timedelta +from datetime import timezone + from pykube import Deployment + from kube_downscaler.scaler import within_grace_period diff --git a/tests/test_main.py b/tests/test_main.py index 668986e..9b004d4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,9 +1,8 @@ -import pytest - import os.path - from unittest.mock import MagicMock +import pytest + from kube_downscaler.main import main diff --git a/tests/test_pods_force_uptime.py b/tests/test_pods_force_uptime.py index d377f8b..b716586 100644 --- a/tests/test_pods_force_uptime.py +++ b/tests/test_pods_force_uptime.py @@ -1,6 +1,8 @@ -from unittest.mock import patch, MagicMock +from unittest.mock import MagicMock +from unittest.mock import patch -from kube_downscaler.scaler import pods_force_uptime, FORCE_UPTIME_ANNOTATION +from kube_downscaler.scaler import FORCE_UPTIME_ANNOTATION +from kube_downscaler.scaler import pods_force_uptime @patch("pykube.Pod") diff --git a/tests/test_resources.py b/tests/test_resources.py index ebeea9a..64cf713 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -1,8 +1,9 @@ from unittest.mock import MagicMock +from pykube import Deployment +from pykube import StatefulSet from pykube.objects import NamespacedAPIObject -from pykube import Deployment, StatefulSet from kube_downscaler.resources.stack import Stack diff --git a/tests/test_scaler.py b/tests/test_scaler.py index bd2ed79..72a4cc3 100644 --- a/tests/test_scaler.py +++ b/tests/test_scaler.py @@ -1,12 +1,10 @@ import json from unittest.mock import MagicMock -from kube_downscaler.scaler import ( - scale, - ORIGINAL_REPLICAS_ANNOTATION, - EXCLUDE_ANNOTATION, - DOWNTIME_REPLICAS_ANNOTATION, -) +from kube_downscaler.scaler import DOWNTIME_REPLICAS_ANNOTATION +from kube_downscaler.scaler import EXCLUDE_ANNOTATION +from kube_downscaler.scaler import ORIGINAL_REPLICAS_ANNOTATION +from kube_downscaler.scaler import scale def test_scaler_always_up(monkeypatch): @@ -599,9 +597,7 @@ def get(url, version, **kwargs): ] } elif url == "namespaces/default": - data = { - "metadata": {"annotations": {"downscaler/uptime": "never"}} - } + data = {"metadata": {"annotations": {"downscaler/uptime": "never"}}} # data = {'metadata': {}} else: raise Exception(f"unexpected call: {url}, {version}, {kwargs}") @@ -669,10 +665,12 @@ def get(url, version, **kwargs): } elif url == "namespaces/default": data = { - "metadata": {"annotations": { - "downscaler/uptime": "always", - "downscaler/downtime": "never" - }} + "metadata": { + "annotations": { + "downscaler/uptime": "always", + "downscaler/downtime": "never", + } + } } # data = {'metadata': {}} else: @@ -711,9 +709,6 @@ def get(url, version, **kwargs): "creationTimestamp": "2019-03-01T16:38:00Z", "annotations": {ORIGINAL_REPLICAS_ANNOTATION: None}, }, - "spec": { - "suspend": False, - "startingDeadlineSeconds": 0, - }, + "spec": {"suspend": False, "startingDeadlineSeconds": 0}, } assert json.loads(api.patch.call_args[1]["data"]) == patch_data diff --git a/tests/test_time.py b/tests/test_time.py index eab8248..a8fb9a2 100644 --- a/tests/test_time.py +++ b/tests/test_time.py @@ -1,6 +1,8 @@ +from datetime import datetime +from datetime import timezone + import pytest -from datetime import datetime, timezone from kube_downscaler.helper import matches_time_spec