FEAT(bin): add get_app_history.py
This commit is contained in:
parent
d46afb0296
commit
a9120f2475
1 changed files with 47 additions and 0 deletions
47
bin/get_app_history.py
Executable file
47
bin/get_app_history.py
Executable file
|
@ -0,0 +1,47 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- encoding: utf-8; py-indent-offset: 4 -*-
|
||||
|
||||
# Author: Sebastian Mark
|
||||
# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
|
||||
# for civil use only
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from dateutil.parser import parse
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def kubectl(cmd: str) -> str:
|
||||
cmd = f"kubectl -n argocd {cmd}"
|
||||
return os.popen(cmd).read()
|
||||
|
||||
|
||||
def get_history(appname: str) -> dict:
|
||||
app = kubectl(f"get applications {appname} -o yaml")
|
||||
app_dict = yaml.safe_load(app)
|
||||
revisions = {}
|
||||
if app_dict:
|
||||
for rev in app_dict["status"]["history"]:
|
||||
revisions[rev["deployedAt"]] = rev["revision"]
|
||||
return revisions
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
appname = sys.argv[1]
|
||||
except IndexError:
|
||||
print("Usage: get_app_history.py <application name>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
history = get_history(appname)
|
||||
if len(history):
|
||||
print(f"History for {appname}")
|
||||
for k, v in history.items():
|
||||
date = parse(k).strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f"{date}: {v}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue