Skip to content

Commit

Permalink
Merge pull request #18 from djjudas21/colours
Browse files Browse the repository at this point in the history
Add colour output
  • Loading branch information
djjudas21 authored Dec 16, 2024
2 parents 486c18e + da6f141 commit fbe628b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
14 changes: 11 additions & 3 deletions kubedownscaler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import argparse
from kubernetes import client, config
from kubernetes.client.rest import ApiException

from termcolor import cprint

def annotate(api, kind: str, name: str, namespace: str, value: str):
'''
Expand Down Expand Up @@ -47,8 +47,16 @@ def scale(api, kind: str, name: str, namespace: str, from_replicas: int, to_repl
'''
Scale a kube resource to a new number of replicas
'''
print(
f"Scaling {kind} {namespace}/{name} from {from_replicas} to {to_replicas} replicas")

if to_replicas > from_replicas:
colour = 'green'
elif to_replicas < from_replicas:
colour = 'red'
else:
colour = 'yellow'

cprint(
f"Scaling {kind} {namespace}/{name} from {from_replicas} to {to_replicas} replicas", colour)

body = {"spec": {"replicas": to_replicas}}

Expand Down
17 changes: 15 additions & 2 deletions poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ kubectl-downscale = 'kubedownscaler.main:main'
python = "^3.10"
kubernetes = "^19.15.0"
argparse = "^1.4.0"
termcolor = "^2.3.0"

[tool.poetry.dev-dependencies]
autopep8 = "^1.6.0"
Expand Down

0 comments on commit fbe628b

Please sign in to comment.