import os
import sys

# apply or delete config
kube_command = 'apply'
if len(sys.argv) == 2:
    kube_command = sys.argv[1]

paths = []
for p, _, f in os.walk('./'):
    for file in f:
        if 'deployment.yml' == file:
            paths.append(os.path.normpath(p))

error:int = 0
for path in paths:
    exit_val = os.system(f"kubectl {kube_command} -f {path}")
    if exit_val != 0:
        error = exit_val

sys.exit(1 if error > 0 else 0)