New Feature - Downscaling Jobs Using Admission Controller (Kyverno And Gatekeeper) #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Hey everyone!
This pull request will add the possibility to also downscale jobs, the only requirement is to have an admission controller installed inside the cluster (Gatakeeper or Kyverno). The pull request comes with a new argument --admission-controller which is required only if the user supply "jobs" inside the "--include-resources" arg.
Code reviews are welcomed. I tried to develop this feature in the separate way in order with a slightly different logic here and there. This choice was made to keep all the previously developed features compatible with jobs as well
This is an example of how the feature looks like:
The error displayed to the user is the following:
Error from server (Forbidden): error when creating "jobtest.yaml": admission webhook "validation.gatekeeper.sh" denied the request: [test-namespace] Job creation is not allowed in this namespace during a kube-downscaler downtime period.
Once the downscaling period ends, the following lines appear in the logs
Changes
with the newest commits:
--admission-controller
. User can choose the admission controller they want (Kyverno or Gatekeeper)downscaler/exclude
anddowscaler/exclude-until
at job levelEXCLUDE_DEPLOYMENTS
environment variable and--exclude-deployments
argument for jobsjobs
is specified inside--include-resources
argument andcronjobs
is not specified inside--include-resources
argument. So the user is able to downscale jobs and cronjobs separately if neededTests done
Built a dedicated image to test. Unit and Mock tests available inside test_scaler.py, test_resources.py and test_cmd.py
TODO