Skip to content

Commit

Permalink
Merge pull request #106 from samuel-esp/timeout
Browse files Browse the repository at this point in the history
New Feature: Introduced An Argument To Customize Timeout When Contacting API Server
  • Loading branch information
samuel-esp authored Nov 7, 2024
2 parents 2d5d965 + f6ff4db commit a8720cd
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 37 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ Supported Admission Controllers are
> Make sure to read the [Scaling Jobs With Admission Controller](#scaling-jobs-with-admission-controller) section
> to understand how to use the `--admission-controller` feature correctly
`--api-server-timeout`
: Optional: This is an advanced option that allows setting a timeout duration for all
calls made by Kube Downscaler to the Kubernetes API Server. It can only take integer values
(default: 10). This setting should only be added to Kube Downscaler arguments if timeout
issues are observed in the logs.
### Constrained Mode (Limited Access Mode)
The Constrained Mode (also known as Limited Access Mode) is designed for users who do not have full cluster access.
Expand Down
6 changes: 6 additions & 0 deletions kube_downscaler/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def get_parser():
help="Grace period in seconds for deployments before scaling down (default: 15min)",
default=os.getenv("GRACE_PERIOD", 900),
)
parser.add_argument(
"--api-server-timeout",
type=int,
help="Timeout to be used when kubedownscaler performs call to the Kubernetes API Server (default: 10s)",
default=os.getenv("API_SERVER_TIMEOUT", 10),
)
upscale_group.add_argument(
"--upscale-period",
help="Default time period to scale up once (default: never)",
Expand Down
3 changes: 3 additions & 0 deletions kube_downscaler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def main(args=None):
args.interval,
args.upscale_target_only,
args.dry_run,
args.api_server_timeout,
args.downtime_replicas,
args.deployment_time_annotation,
args.enable_events,
Expand All @@ -64,6 +65,7 @@ def run_loop(
interval,
upscale_target_only,
dry_run,
api_server_timeout,
downtime_replicas,
deployment_time_annotation=None,
enable_events=False,
Expand Down Expand Up @@ -99,6 +101,7 @@ def run_loop(
grace_period=grace_period,
admission_controller=admission_controller,
constrained_downscaler=constrained_downscaler,
api_server_timeout=api_server_timeout,
downtime_replicas=downtime_replicas,
deployment_time_annotation=deployment_time_annotation,
enable_events=enable_events,
Expand Down
2 changes: 2 additions & 0 deletions kube_downscaler/scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ def scale(
grace_period: int,
admission_controller: str,
constrained_downscaler: bool,
api_server_timeout: int,
downtime_replicas: int = 0,
deployment_time_annotation: Optional[str] = None,
enable_events: bool = False,
Expand All @@ -1360,6 +1361,7 @@ def scale(

now = datetime.datetime.now(datetime.timezone.utc)
forced_uptime = pods_force_uptime(api, namespaces)
pykube.http.DEFAULT_HTTP_TIMEOUT=api_server_timeout

for clazz in RESOURCE_CLASSES:
plural = clazz.endpoint
Expand Down
77 changes: 41 additions & 36 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Henning Jacobs <[email protected]>"]

[tool.poetry.dependencies]
python = ">=3.8,<4"
new-pykube = "^24.7.0"
new-pykube = "^24.10.0"
pytz = "*"

[tool.poetry.dev-dependencies]
Expand Down
Loading

0 comments on commit a8720cd

Please sign in to comment.