From 146d669bd83b0e465c79a384fc49bf96e041af2a Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 13 Nov 2024 14:26:41 +0100 Subject: [PATCH 01/45] refactor: updated pre-commit-config.yaml --- .pre-commit-config.yaml | 42 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 72b5396..5142c6c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,3 @@ -minimum_pre_commit_version: 1.21.0 repos: # meta @@ -7,38 +6,38 @@ repos: - id: check-hooks-apply - id: check-useless-excludes - - repo: https://codeberg.org/hjacobs/kube-manifest-lint - rev: 0.2.0 + - repo: https://github.com/gruntwork-io/pre-commit + rev: v0.1.24 hooks: - - id: kube-manifest-lint + - id: helmlint # formatters - repo: https://github.com/asottile/reorder_python_imports - rev: v3.8.2 + rev: v3.14.0 hooks: - id: reorder-python-imports - repo: https://github.com/ambv/black - rev: 22.8.0 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/asottile/pyupgrade - rev: v2.37.3 + rev: v3.19.0 hooks: - id: pyupgrade - stages: [push] + stages: [pre-push] # linters - repo: https://github.com/PyCQA/bandit - rev: 1.7.4 + rev: 1.7.10 hooks: - id: bandit args: ["-x", "tests"] - stages: [push] + stages: [pre-push] - repo: https://github.com/PyCQA/pydocstyle - rev: 6.1.1 + rev: 6.3.0 hooks: - id: pydocstyle args: ["--ignore=D10,D21,D202"] @@ -51,7 +50,7 @@ repos: language: system pass_filenames: false args: ["check", "--bare"] - stages: [push] + stages: [pre-push] - id: poetry name: poetry @@ -60,10 +59,10 @@ repos: language: system pass_filenames: false files: ^pyproject.toml$ - stages: [push] + stages: [pre-push] - repo: https://github.com/adrienverge/yamllint - rev: v1.28.0 + rev: v1.35.1 hooks: - id: yamllint args: ["--strict", "-d", "{rules: {line-length: {max: 180}}}"] @@ -71,12 +70,11 @@ repos: exclude: > (?x)^( ^{{.*}}.*\.yaml$| - ^unsupported/helm-chart/templates/.*$ ) # - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.971 + rev: v1.13.0 hooks: - id: mypy additional_dependencies: [types-pytz] @@ -85,16 +83,16 @@ repos: rev: v0.1.0 hooks: - id: dockerfilelint - stages: [commit] # required + stages: [pre-commit] # required # miscellaneous - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + - repo: https://github.com/PyCQA/flake8 + rev: 7.1.1 hooks: - id: flake8 - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: check-docstring-first @@ -109,7 +107,7 @@ repos: args: ["--django"] - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.9.0 + rev: v1.10.0 hooks: # - id: rst-backticks - id: python-use-type-annotations @@ -122,6 +120,6 @@ repos: # http://jorisroovers.com/gitlint/#using-gitlint-through-pre-commit - repo: https://github.com/jorisroovers/gitlint - rev: v0.17.0 + rev: v0.19.1 hooks: - id: gitlint From 1ffa16349bf738b1897ab6a6e9f3f1198bd636e4 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 13 Nov 2024 14:27:06 +0100 Subject: [PATCH 02/45] refactor: adjusted makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 90946de..1958d58 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: test docker push -IMAGE ?= hjacobs/kube-downscaler +IMAGE ?= caas-team/py-kube-downscaler VERSION ?= $(shell git describe --tags --always --dirty) TAG ?= $(VERSION) From ee1b27c4389e0528649202b58c1a00828c8bf70a Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 13 Nov 2024 15:34:52 +0100 Subject: [PATCH 03/45] adjusted pre-commit config --- .pre-commit-config.yaml | 134 ++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5142c6c..8874878 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +fail_fast: true repos: # meta @@ -6,44 +7,45 @@ repos: - id: check-hooks-apply - id: check-useless-excludes - - repo: https://github.com/gruntwork-io/pre-commit - rev: v0.1.24 - hooks: - - id: helmlint - - # formatters - - repo: https://github.com/asottile/reorder_python_imports - rev: v3.14.0 - hooks: - - id: reorder-python-imports - - - repo: https://github.com/ambv/black - rev: 24.10.0 - hooks: - - id: black - - - repo: https://github.com/asottile/pyupgrade - rev: v3.19.0 - hooks: - - id: pyupgrade - stages: [pre-push] - - # linters - - repo: https://github.com/PyCQA/bandit - rev: 1.7.10 - hooks: - - id: bandit - args: ["-x", "tests"] - stages: [pre-push] - - - repo: https://github.com/PyCQA/pydocstyle - rev: 6.3.0 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 hooks: - - id: pydocstyle - args: ["--ignore=D10,D21,D202"] + - id: end-of-file-fixer + - id: trailing-whitespace + - id: no-commit-to-branch + args: [--branch, main] + - id: check-added-large-files + - id: check-docstring-first + - id: debug-statements + - id: check-ast + - id: check-builtin-literals + - id: detect-private-key + - id: mixed-line-ending + - id: name-tests-test + args: ["--django"] - repo: local hooks: + - id: prevent-todo-comments + name: prevent todo comments + entry: '# *(TODO|FIXME)\b' # matches a python comment beginning with "TODO" or "FIXME" + language: pygrep + files: \.py$ + - id: prevent-too-small-headings + name: prevent too small headings + entry: "^#{5,} " # matches a h5 or smaller markdown heading + language: pygrep + files: \.md$ + - id: prevent-overly-nested-hierarchy + name: prevent overly nested hierarchy + entry: "^( ){2,}- " # matches a markdown list with 2 or more indentations + language: pygrep + files: \.md$ + - id: prevent-invalid-alert-types + name: prevent invalid alert types + entry: '(?i)^> \[!(?!\b(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION)\b).+\]' # matches a github markdown callout/alert that doesn't use one of the supported keywords + language: pygrep + files: \.md$ - id: safety name: safety entry: safety @@ -51,7 +53,6 @@ repos: pass_filenames: false args: ["check", "--bare"] stages: [pre-push] - - id: poetry name: poetry description: Validates the structure of the pyproject.toml file @@ -61,17 +62,33 @@ repos: files: ^pyproject.toml$ stages: [pre-push] - - repo: https://github.com/adrienverge/yamllint - rev: v1.35.1 + - repo: https://github.com/gruntwork-io/pre-commit + rev: v0.1.24 + hooks: + - id: helmlint + + # formatters + - repo: https://github.com/asottile/reorder_python_imports + rev: v3.14.0 hooks: - - id: yamllint - args: ["--strict", "-d", "{rules: {line-length: {max: 180}}}"] - # - exclude: > - (?x)^( - ^{{.*}}.*\.yaml$| - ) - # + - id: reorder-python-imports + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.3 + hooks: + # Run the linter. + - id: ruff + args: [--fix] + # Run the formatter. + - id: ruff-format + + # linters + - repo: https://github.com/PyCQA/bandit + rev: 1.7.10 + hooks: + - id: bandit + args: ["-x", "tests"] + stages: [pre-push] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.13.0 @@ -86,38 +103,21 @@ repos: stages: [pre-commit] # required # miscellaneous - - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 - hooks: - - id: flake8 - - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 - hooks: - - id: check-added-large-files - - id: check-docstring-first - - id: debug-statements - - id: end-of-file-fixer - - 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.10.0 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/pre-commit/mirrors-prettier + rev: v3.1.0 + hooks: + - id: prettier + files: \.md$ - repo: https://github.com/jorisroovers/gitlint rev: v0.19.1 From 9c280d25a368c258116ee72d422cc48ef77598da Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 13 Nov 2024 15:35:52 +0100 Subject: [PATCH 04/45] fix: fixed end of file lines --- .github/workflows/end2end.yml | 1 - .github/workflows/python-tests.yml | 2 +- chart/templates/configmap.yaml | 2 +- tests/test_resources.py | 2 +- tests/test_scaler.py | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/end2end.yml b/.github/workflows/end2end.yml index 5891a3f..c3056d5 100644 --- a/.github/workflows/end2end.yml +++ b/.github/workflows/end2end.yml @@ -65,4 +65,3 @@ jobs: exit 1 fi echo "Deployment py-kube-downscaler OK" - diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index e349c12..a7dce6f 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -30,4 +30,4 @@ jobs: - uses: actions/upload-artifact@v4 with: name: coverage - path: coverage.xml \ No newline at end of file + path: coverage.xml diff --git a/chart/templates/configmap.yaml b/chart/templates/configmap.yaml index 4d0624a..14e6034 100644 --- a/chart/templates/configmap.yaml +++ b/chart/templates/configmap.yaml @@ -7,4 +7,4 @@ data: EXCLUDE_NAMESPACES: '{{- join "," .Values.excludedNamespaces }}' {{- if .Values.extraConfig }} {{- tpl .Values.extraConfig . | nindent 2 }} - {{- end }} \ No newline at end of file + {{- end }} diff --git a/tests/test_resources.py b/tests/test_resources.py index 3394d78..8a2a05c 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -75,4 +75,4 @@ def test_kubedownscalerjobspolicy(): api_mock.obj = MagicMock(name="APIObjMock") d = KubeDownscalerJobsPolicy.create_job_policy("policy") assert d['metadata']['name'] == "kube-downscaler-jobs-policy" - assert d['metadata']['namespace'] == "policy" \ No newline at end of file + assert d['metadata']['namespace'] == "policy" diff --git a/tests/test_scaler.py b/tests/test_scaler.py index 7295514..4b9d290 100644 --- a/tests/test_scaler.py +++ b/tests/test_scaler.py @@ -3431,4 +3431,4 @@ def get(url, version, **kwargs): } } } - assert json.loads(api.patch.call_args[1]["data"]) == patch_data \ No newline at end of file + assert json.loads(api.patch.call_args[1]["data"]) == patch_data From 75209436ab392f7231517e63f2c7599e4f5a64f3 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 13 Nov 2024 15:36:27 +0100 Subject: [PATCH 05/45] fixed trailing whitespaces --- README.md | 32 +++++++++---------- .../resources/constrainttemplate.py | 2 +- kube_downscaler/scaler.py | 4 +-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 6c8c58a..1135113 100644 --- a/README.md +++ b/README.md @@ -283,8 +283,8 @@ Each time specification can be in one of two formats: where each `