def __init__(self, kubernetes_namespace): self.client = apps_v1_api.AppsV1Api() self.core_client = core_v1_api.CoreV1Api() self.kubernetes_config_map = KubernetesConfigMap() self.kubernetes_namespace = kubernetes_namespace
def __init__(self, kubernetes_namespace: KubernetesNamespace) -> None: self.client: apps_v1_api.AppsV1Api = apps_v1_api.AppsV1Api() self.core_client: core_v1_api.CoreV1Api = core_v1_api.CoreV1Api() self.kubernetes_config_map: KubernetesConfigMap = KubernetesConfigMap() self.kubernetes_namespace: KubernetesNamespace = kubernetes_namespace
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 __init__(self, config_file=None) -> None: self.log = getLogger(f'{__name__}.{self.__class__.__name__}') if config_file is None: try: config.load_kube_config() except: config.load_incluster_config() self.api = client.AppsV1Api() else: self.api = apps_v1_api.AppsV1Api(api_client.ApiClient(configuration=config_file))
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)