def run(self, args): context = choose_context(args.context) arguments = DynamicArgs(context, args, self.get_additional_attr_config()) path = arguments.val("path") tpl_files = arguments.val("files") name = arguments.val("name") if isinstance(tpl_files, str): tpl_files = [ tpl_files, ] for i in tpl_files: print(i) tpl = YamlTemplateRunner(path, str(i), name) if tpl.is_ready(): if confirm( "Do you want to apply the contents of file with kubectl apply -f " + tpl.rendered_tpl + ""): # apply generated file via kubectl apply -f kubectl_cmd = "kubectl apply -f " + tpl.rendered_tpl print("executing:", kubectl_cmd) print("---") subprocess.run(kubectl_cmd, shell=True) print("---") else: print("File is not applied to context", context) else: print("problem with file", i)
def run(self, args): context, namespace = choose_context_and_namespace(args.context, args.namespace) if args.job: remove_job(context, namespace, args.job) wait_for_job_is_away(context, namespace, args.job) else: obj = confirm_job(context, namespace) if obj is not None and confirm("Do you really want to delete Job " + obj + " in namespace " + namespace + "?"): remove_job(context, namespace, obj) wait_for_job_is_away(context, namespace, obj) else: print("No Job removal executed")
def run(self, args): context, namespace = choose_context_and_namespace(args.context, args.namespace) if args.network_policy: remove_network_policy(context, namespace, args.network_policy) wait_for_network_policy_is_away(context, namespace, args.network_policy) else: obj = confirm_network_policy(context, namespace) if obj is not None and confirm("Do you really want to delete NetworkPolicy " + obj + " in namespace " + namespace + "?"): remove_network_policy(context, namespace, obj) wait_for_network_policy_is_away(context, namespace, obj) else: print("No NetworkPolicy removal executed")
def run(self, args): context, namespace = choose_context_and_namespace(args.context, args.namespace) if args.lease: remove_lease(context, namespace, args.lease) wait_for_lease_is_away(context, namespace, args.lease) else: obj = confirm_lease(context, namespace) if obj is not None and confirm("Do you really want to delete Lease " + obj + " in namespace " + namespace + "?"): remove_lease(context, namespace, obj) wait_for_lease_is_away(context, namespace, obj) else: print("No Lease removal executed")
def run(self, args): context, namespace = choose_context_and_namespace(args.context, args.namespace) if args.secret: remove_secret(context, namespace, args.secret) wait_for_secret_is_away(context, namespace, args.secret) else: obj = confirm_secret(context, namespace) if obj is not None and confirm("Do you really want to delete Secret " + obj + " in namespace " + namespace + "?"): remove_secret(context, namespace, obj) wait_for_secret_is_away(context, namespace, obj) else: print("No Secret removal executed")
def run(self, args): context, namespace = choose_context_and_namespace(args.context, args.namespace) if args.horizontal_pod_autoscaler: remove_horizontal_pod_autoscaler(context, namespace, args.horizontal_pod_autoscaler) wait_for_horizontal_pod_autoscaler_is_away(context, namespace, args.horizontal_pod_autoscaler) else: obj = confirm_horizontal_pod_autoscaler(context, namespace) if obj is not None and confirm("Do you really want to delete HorizontalPodAutoscaler " + obj + " in namespace " + namespace + "?"): remove_horizontal_pod_autoscaler(context, namespace, obj) wait_for_horizontal_pod_autoscaler_is_away(context, namespace, obj) else: print("No HorizontalPodAutoscaler removal executed")
def run(self, args): from lib.common import choose_context context = choose_context(args.context) if args.volume_attachment: remove_volume_attachment(context, args.volume_attachment) wait_for_volume_attachment_is_away(context, args.volume_attachment) else: obj = confirm_volume_attachment(context) if obj is not None and confirm("Do you really want to delete VolumeAttachment " + obj + "?"): remove_volume_attachment(context, obj) wait_for_volume_attachment_is_away(context, obj) else: print("No VolumeAttachment removal executed")
def run(self, args): from lib.common import choose_context context = choose_context(args.context) if args.persistent_volume: remove_persistent_volume(context, args.persistent_volume) wait_for_persistent_volume_is_away(context, args.persistent_volume) else: obj = confirm_persistent_volume(context) if obj is not None and confirm("Do you really want to delete PersistentVolume " + obj + "?"): remove_persistent_volume(context, obj) wait_for_persistent_volume_is_away(context, obj) else: print("No PersistentVolume removal executed")
def run(self, args): from lib.common import choose_context context = choose_context(args.context) if args.storage_class: remove_storage_class(context, args.storage_class) wait_for_storage_class_is_away(context, args.storage_class) else: obj = confirm_storage_class(context) if obj is not None and confirm("Do you really want to delete StorageClass " + obj + "?"): remove_storage_class(context, obj) wait_for_storage_class_is_away(context, obj) else: print("No StorageClass removal executed")
def run(self, args): from lib.common import choose_context context = choose_context(args.context) if args.custom_resource_definition: remove_custom_resource_definition(context, args.custom_resource_definition) wait_for_custom_resource_definition_is_away(context, args.custom_resource_definition) else: obj = confirm_custom_resource_definition(context) if obj is not None and confirm("Do you really want to delete CustomResourceDefinition " + obj + "?"): remove_custom_resource_definition(context, obj) wait_for_custom_resource_definition_is_away(context, obj) else: print("No CustomResourceDefinition removal executed")
def run(self, args): context, namespace = choose_context_and_namespace( args.context, args.namespace) if args.namespace: remove_namespace(context, namespace, args.namespace) wait_for_namespace_is_away(context, namespace, args.namespace) else: if namespace is not None and confirm( "Do you really want to delete Namespace " + namespace + "?"): remove_namespace(context, namespace, namespace) wait_for_namespace_is_away(context, namespace, namespace) else: print("No Namespace removal executed")
def run(self, args): from lib.common import choose_context context = choose_context(args.context) if args.cluster_role: remove_cluster_role(context, args.cluster_role) wait_for_cluster_role_is_away(context, args.cluster_role) else: obj = confirm_cluster_role(context) if obj is not None and confirm( "Do you really want to delete ClusterRole " + obj + "?"): remove_cluster_role(context, obj) wait_for_cluster_role_is_away(context, obj) else: print("No ClusterRole removal executed")
def run(self, args): context, namespace = choose_context_and_namespace( args.context, args.namespace) if args.config_map: remove_config_map(context, namespace, args.config_map) wait_for_config_map_is_away(context, namespace, args.config_map) else: obj = confirm_config_map(context, namespace) if obj is not None and confirm( "Do you really want to delete ConfigMap " + obj + " in namespace " + namespace + "?"): remove_config_map(context, namespace, obj) wait_for_config_map_is_away(context, namespace, obj) else: print("No ConfigMap removal executed")
def run(self, args): context, namespace = choose_context_and_namespace( args.context, args.namespace) if args.pod: remove_pod(context, namespace, args.pod) wait_for_pod_is_away(context, namespace, args.pod) else: obj = confirm_pod(context, namespace) if obj is not None and confirm( "Do you really want to delete Pod " + obj + " in namespace " + namespace + "?"): remove_pod(context, namespace, obj) wait_for_pod_is_away(context, namespace, obj) else: print("No Pod removal executed")
def run(self, args): from lib.common import choose_context context = choose_context(args.context) if args.pod_security_policy: remove_pod_security_policy(context, args.pod_security_policy) wait_for_pod_security_policy_is_away(context, args.pod_security_policy) else: obj = confirm_pod_security_policy(context) if obj is not None and confirm( "Do you really want to delete PodSecurityPolicy " + obj + "?"): remove_pod_security_policy(context, obj) wait_for_pod_security_policy_is_away(context, obj) else: print("No PodSecurityPolicy removal executed")
def run(self, args): context, namespace = choose_context_and_namespace( args.context, args.namespace) if args.role_binding: remove_role_binding(context, namespace, args.role_binding) wait_for_role_binding_is_away(context, namespace, args.role_binding) else: obj = confirm_role_binding(context, namespace) if obj is not None and confirm( "Do you really want to delete RoleBinding " + obj + " in namespace " + namespace + "?"): remove_role_binding(context, namespace, obj) wait_for_role_binding_is_away(context, namespace, obj) else: print("No RoleBinding removal executed")
def run(self, args): context, namespace = choose_context_and_namespace( args.context, args.namespace) if args.resource_quota: remove_resource_quota(context, namespace, args.resource_quota) wait_for_resource_quota_is_away(context, namespace, args.resource_quota) else: obj = confirm_resource_quota(context, namespace) if obj is not None and confirm( "Do you really want to delete ResourceQuota " + obj + " in namespace " + namespace + "?"): remove_resource_quota(context, namespace, obj) wait_for_resource_quota_is_away(context, namespace, obj) else: print("No ResourceQuota removal executed")
def run(self, args): context, namespace = choose_context_and_namespace( args.context, args.namespace) if args.controller_revision: remove_controller_revision(context, namespace, args.controller_revision) wait_for_controller_revision_is_away(context, namespace, args.controller_revision) else: obj = confirm_controller_revision(context, namespace) if obj is not None and confirm( "Do you really want to delete ControllerRevision " + obj + " in namespace " + namespace + "?"): remove_controller_revision(context, namespace, obj) wait_for_controller_revision_is_away(context, namespace, obj) else: print("No ControllerRevision removal executed")
def run(self, args): from lib.common import choose_context context = choose_context(args.context) if args.certificate_signing_request: remove_certificate_signing_request( context, args.certificate_signing_request) wait_for_certificate_signing_request_is_away( context, args.certificate_signing_request) else: obj = confirm_certificate_signing_request(context) if obj is not None and confirm( "Do you really want to delete CertificateSigningRequest " + obj + "?"): remove_certificate_signing_request(context, obj) wait_for_certificate_signing_request_is_away(context, obj) else: print("No CertificateSigningRequest removal executed")
def run(self, args): context, namespace = choose_context_and_namespace( args.context, args.namespace) if args.replication_controller: remove_replication_controller(context, namespace, args.replication_controller) wait_for_replication_controller_is_away( context, namespace, args.replication_controller) else: obj = confirm_replication_controller(context, namespace) if obj is not None and confirm( "Do you really want to delete ReplicationController " + obj + " in namespace " + namespace + "?"): remove_replication_controller(context, namespace, obj) wait_for_replication_controller_is_away( context, namespace, obj) else: print("No ReplicationController removal executed")
def run(self, args): context, namespace = choose_context_and_namespace( args.context, args.namespace) if args.persistent_volume_claim: remove_persistent_volume_claim(context, namespace, args.persistent_volume_claim) wait_for_persistent_volume_claim_is_away( context, namespace, args.persistent_volume_claim) else: obj = confirm_persistent_volume_claim(context, namespace) if obj is not None and confirm( "Do you really want to delete PersistentVolumeClaim " + obj + " in namespace " + namespace + "?"): remove_persistent_volume_claim(context, namespace, obj) wait_for_persistent_volume_claim_is_away( context, namespace, obj) else: print("No PersistentVolumeClaim removal executed")
def run(self, args): context, namespace = common.choose_context_and_namespace( args.context, args.namespace) if args.set_type is not None and args.set_name is not None: remove_set(context, namespace, args.set_type, args.set_name) if args.no_wait is None or args.no_wait is False: wait_for_set_is_away(context, namespace, args.set_type, args.set_name) else: set = confirm_set(context, namespace) set_type = common.detect_set_type(set) set_name = set.metadata.name if set_name and confirm("Do you really want to delete set " + set_name + " in namespace " + namespace + "?"): remove_set(context, namespace, set_type, set_name) if args.no_wait is None or args.no_wait is False: wait_for_set_is_away(context, namespace, set_type, set_name) else: print("NO set removal executed")
def run(self, args): print("Starting scaling deployment") context, namespace = choose_context_and_namespace(args.context, args.namespace) if args.deployment is not None: deployment = args.deployment else: deployment = confirm_deployment(context, namespace) api = client.ExtensionsV1beta1Api() ret, status, _ = api.read_namespaced_deployment_scale_with_http_info(deployment, namespace) # detected desired and current state desired_replica_count = "undefined" current_replica_count = "undefined" if hasattr(ret.spec, "replicas") and ret.spec.replicas is not None: desired_replica_count = int(ret.spec.replicas) if hasattr(ret.status, "replicas") and ret.status is not None: current_replica_count = int(ret.status.replicas) print("Deployment %s has %s/%s replicas" % (ret.metadata.name, desired_replica_count, current_replica_count)) replica_count = confirm_number("Please enter a number of replicas for scaling", "Current replicas: %s" % current_replica_count) if confirm( "Do you really want to scale Deployment '%s' in context '%s' from %d to %d replicas?" % (deployment, context, current_replica_count, replica_count)): print("Scaling deployment %s to %d replicas..." % (deployment, replica_count)) ret, status, _ = api.patch_namespaced_deployment_scale_with_http_info(deployment, namespace, { 'spec': { 'replicas': replica_count, }}) print("Finish scale scaling deployment '%s'" % deployment) else: print("No change executed in namespace '%s'." % namespace)