import os import argparse parser = argparse.ArgumentParser(description='check shoot certificate expiration') parser.add_argument('--kubeconfig', type=str) parser.add_argument('--instance', type=str) parser.add_argument('--pod', type=str) parser.add_argument('--oom', dest='oom', action='store_false') parser.add_argument('--cpuoverload', dest='cpuoverload', action='store_false') args = parser.parse_args() print(args.kubeconfig, args.instance, args.pod) def exec_commands(kubeconfig, namespace, pod_name, execCommand): print("begin to exec") os.system("cp /root/.kube/config /root/.kube/config_tmp") os.system("cp {0} /root/.kube/config".format(kubeconfig)) os.system("kubectl exec -it {0} -n {1} chmod +x /{2}".format(pod_name, namespace, execCommand)) print('kubectl exec -it {0} -n {1} -- sh -c "nohup ./{2} &" '.format(pod_name, namespace, execCommand)) os.system('kubectl exec -it {0} -n {1} -- sh -c "nohup ./{2} &" '.format(pod_name, namespace, execCommand)) os.system("cp /root/.kube/config_tmp /root/.kube/config") print("copy file done") def copy_file_inside_pod(kubeconfig, pod_name, source_file, namespace='default'): print("begin to copy file") os.system("cp /root/.kube/config /root/.kube/config_tmp") os.system("cp {0} /root/.kube/config".format(kubeconfig)) os.system("/usr/bin/kubectl cp {0} {1}/{2}:/{3}".format(source_file, namespace, pod_name, source_file)) os.system("cp /root/.kube/config_tmp /root/.kube/config") print("copy file done") if args.oom: print("make pod oom") copy_file_inside_pod(args.kubeconfig, args.pod, "oom", args.instance) exec_commands(args.kubeconfig, args.instance, args.pod, "oom") elif args.cpuoverload: print("make cpu overload") copy_file_inside_pod(args.kubeconfig, args.pod, "cpuoverload", args.instance) exec_commands(args.kubeconfig, args.instance, args.pod, "cpuoverload") print("test done")