diff --git a/kubedownscaler/main.py b/kubedownscaler/main.py index 6c983a5..0386b84 100644 --- a/kubedownscaler/main.py +++ b/kubedownscaler/main.py @@ -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): ''' @@ -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}} diff --git a/poetry.lock b/poetry.lock index 021f7fd..246a019 100644 --- a/poetry.lock +++ b/poetry.lock @@ -458,7 +458,6 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -572,6 +571,20 @@ files = [ {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, ] +[[package]] +name = "termcolor" +version = "2.5.0" +description = "ANSI color formatting for output in terminal" +optional = false +python-versions = ">=3.9" +files = [ + {file = "termcolor-2.5.0-py3-none-any.whl", hash = "sha256:37b17b5fc1e604945c2642c872a3764b5d547a48009871aea3edd3afa180afb8"}, + {file = "termcolor-2.5.0.tar.gz", hash = "sha256:998d8d27da6d48442e8e1f016119076b690d962507531df4890fcd2db2ef8a6f"}, +] + +[package.extras] +tests = ["pytest", "pytest-cov"] + [[package]] name = "toml" version = "0.10.2" @@ -731,4 +744,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "62e039a662d13635f847ec11c81bec3a3bb4de80b63d097f56b97550d898979f" +content-hash = "c447c21287bc8f39ff369d3c8f592f24e9966db58bcf78692054853d57dc09e1" diff --git a/pyproject.toml b/pyproject.toml index f9b2113..3d32852 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"