def test_create_deployment(self): client = api_client.ApiClient('http://127.0.0.1:8080/') api = extensions_v1beta1_api.ExtensionsV1beta1Api(client) name = 'nginx-deployment-' + str(uuid.uuid4()) deployment = '''apiVersion: extensions/v1beta1 kind: Deployment metadata: name: %s spec: replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 ''' resp = api.create_namespaced_deployment(body=yaml.load(deployment % name), namespace="default") resp = api.read_namespaced_deployment(name, 'default') self.assertIsNotNone(resp) options = v1_delete_options.V1DeleteOptions() resp = api.delete_namespaced_deployment(name, 'default', body=options)
def test_create_deployment(self): client = api_client.ApiClient(configuration=self.config) api = apps_v1_api.AppsV1Api(client) name = 'nginx-deployment-' + str(uuid.uuid4()) deployment = '''apiVersion: apps/v1 kind: Deployment metadata: name: %s spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.15.4 ports: - containerPort: 80 ''' resp = api.create_namespaced_deployment(body=yaml.safe_load( deployment % name), namespace="default") resp = api.read_namespaced_deployment(name, 'default') self.assertIsNotNone(resp) options = v1_delete_options.V1DeleteOptions() resp = api.delete_namespaced_deployment(name, 'default', body=options)
def delete(deployment_name, namespace='default', propagation_policy='Foreground', wait_for_completion=False, timeout_sec=120): api = api_manager.get_apps_v1_api() print('\nDeleting Deployment with namespace={} deploymentname={}'.format( namespace, deployment_name)) options = v1_delete_options.V1DeleteOptions( propagation_policy="Foreground", grace_period_seconds=5) api.delete_namespaced_deployment(deployment_name, namespace, body=options) if wait_for_completion: _teardown_wait(deployment_name, namespace, timeout_sec) return True
def test_create_daemonset(self): client = api_client.ApiClient(configuration=self.config) api = apps_v1_api.AppsV1Api(client) name = 'nginx-app-' + str(uuid.uuid4()) daemonset = { 'apiVersion': 'apps/v1', 'kind': 'DaemonSet', 'metadata': { 'labels': { 'app': 'nginx' }, 'name': '%s' % name, }, 'spec': { 'selector': { 'matchLabels': { 'app': 'nginx' }, }, 'template': { 'metadata': { 'labels': { 'app': 'nginx' }, 'name': name }, 'spec': { 'containers': [ { 'name': 'nginx-app', 'image': 'nginx:1.15.4' }, ], }, }, 'updateStrategy': { 'type': 'RollingUpdate', }, } } resp = api.create_namespaced_daemon_set('default', body=daemonset) resp = api.read_namespaced_daemon_set(name, 'default') self.assertIsNotNone(resp) options = v1_delete_options.V1DeleteOptions() resp = api.delete_namespaced_daemon_set(name, 'default', body=options)
def test_create_daemonset(self): client = api_client.ApiClient('http://127.0.0.1:8080/') api = extensions_v1beta1_api.ExtensionsV1beta1Api(client) name = 'nginx-app-' + str(uuid.uuid4()) daemonset = { 'apiVersion': 'extensions/v1beta1', 'kind': 'DaemonSet', 'metadata': { 'labels': { 'app': 'nginx' }, 'name': '%s' % name, }, 'spec': { 'template': { 'metadata': { 'labels': { 'app': 'nginx' }, 'name': name }, 'spec': { 'containers': [ { 'name': 'nginx-app', 'image': 'nginx:1.10' }, ], }, }, 'updateStrategy': { 'type': 'RollingUpdate', }, } } resp = api.create_namespaced_daemon_set('default', body=daemonset) resp = api.read_namespaced_daemon_set(name, 'default') self.assertIsNotNone(resp) options = v1_delete_options.V1DeleteOptions() resp = api.delete_namespaced_daemon_set(name, 'default', body=options)
from kubernetes import client from kubernetes import config as kube_config from kubernetes.client.models import v1_delete_options try: kube_config.load_kube_config() except: pass deployment_api = client.AppsV1beta1Api() job_api = client.BatchV1Api() service_api = client.CoreV1Api() options = v1_delete_options.V1DeleteOptions() from server3.constants import NAMESPACE def get_deployment_status(served_model): if check_deployment_condition(served_model.deploy_name, 'Available'): served_model.status = 'serving' else: served_model.status = 'terminated' return served_model def get_job_status(job_info, job_name): if check_job_condition(job_name, 'Complete'): job_info['kube_status'] = 'Completed' elif check_job_condition(job_name, 'Progressing'): job_info['kube_status'] = 'Running' else: