blob: 8ffb4d1f100fd7f48ace2c20f74e0c84f821cd4f [file] [log] [blame]
Artem Panchenko0594cd72017-06-12 13:25:26 +03001# Copyright 2017 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13
14
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040015import kubernetes
16from kubernetes import client
Artem Panchenko0594cd72017-06-12 13:25:26 +030017
18from tcp_tests.managers.k8s.componentstatuses import \
19 K8sComponentStatusManager
20from tcp_tests.managers.k8s.daemonsets import K8sDaemonSetManager
21from tcp_tests.managers.k8s.deployments import K8sDeploymentManager
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040022from tcp_tests.managers.k8s.endpoints import K8sEndpointsManager
Artem Panchenko0594cd72017-06-12 13:25:26 +030023from tcp_tests.managers.k8s.events import K8sEventManager
24from tcp_tests.managers.k8s.horizontalpodautoscalers import \
25 K8sHorizontalPodAutoscalerManager
26from tcp_tests.managers.k8s.ingresses import K8sIngressManager
27from tcp_tests.managers.k8s.jobs import K8sJobManager
28from tcp_tests.managers.k8s.limitranges import K8sLimitRangeManager
29from tcp_tests.managers.k8s.namespaces import K8sNamespaceManager
30from tcp_tests.managers.k8s.nodes import K8sNodeManager
31from tcp_tests.managers.k8s.persistentvolumeclaims import \
32 K8sPersistentVolumeClaimManager
33from tcp_tests.managers.k8s.persistentvolumes import \
34 K8sPersistentVolumeManager
35from tcp_tests.managers.k8s.pods import K8sPodManager
36from tcp_tests.managers.k8s.replicationcontrollers import \
37 K8sReplicationControllerManager
38from tcp_tests.managers.k8s.resourcequotas import K8sResourceQuotaManager
39from tcp_tests.managers.k8s.secrets import K8sSecretManager
40from tcp_tests.managers.k8s.serviceaccounts import \
41 K8sServiceAccountManager
42from tcp_tests.managers.k8s.services import K8sServiceManager
43from tcp_tests.managers.k8s.replicasets import K8sReplicaSetManager
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040044from tcp_tests.managers.k8s.networkpolicies import K8sNetworkPolicyManager
Artem Panchenko0594cd72017-06-12 13:25:26 +030045
46
47class K8sCluster(object):
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040048 def __init__(self, schema="https", user=None, password=None, ca=None,
Artem Panchenko0594cd72017-06-12 13:25:26 +030049 host='localhost', port='443', default_namespace='default'):
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040050 self.default_namespace = default_namespace
Artem Panchenko0594cd72017-06-12 13:25:26 +030051
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040052 api_server = '{0}://{1}:{2}'.format(schema, host, port)
Artem Panchenko0594cd72017-06-12 13:25:26 +030053
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040054 config_data = {
55 'apiVersion': 'v1',
56 'kind': 'Config',
57 'preferences': {},
58 'current-context': 'cluster-remote',
59 'clusters': [{
60 'name': 'cluster',
61 'cluster': {
62 'server': api_server,
63 'certificate-authority-data': ca,
64 },
65 }],
66 'users': [{
67 'name': 'remote',
68 'user': {
69 'password': password,
70 'username': user,
71 },
72 }],
73 'contexts': [{
74 'name': 'cluster-remote',
75 'context': {
76 'cluster': 'cluster',
77 'user': 'remote',
78 },
79 }],
80 }
81
82 configuration = type.__call__(client.Configuration)
83 loader = kubernetes.config.kube_config.KubeConfigLoader(config_data)
84 loader.load_and_set(configuration)
85 api_client = client.ApiClient(configuration=configuration)
86
87 self.api_core = client.CoreV1Api(api_client)
88 self.api_apps = client.AppsV1Api(api_client)
89 self.api_extensions = client.ExtensionsV1beta1Api(api_client)
90 self.api_autoscaling = client.AutoscalingV1Api(api_client)
91 self.api_batch = client.BatchV1Api(api_client)
92
93 self.nodes = K8sNodeManager(self)
94 self.pods = K8sPodManager(self)
95 self.endpoints = K8sEndpointsManager(self)
96 self.namespaces = K8sNamespaceManager(self)
97 self.services = K8sServiceManager(self)
98 self.serviceaccounts = K8sServiceAccountManager(self)
99 self.secrets = K8sSecretManager(self)
100 self.events = K8sEventManager(self)
101 self.limitranges = K8sLimitRangeManager(self)
102 self.jobs = K8sJobManager(self)
103 self.daemonsets = K8sDaemonSetManager(self)
104 self.ingresses = K8sIngressManager(self)
105 self.deployments = K8sDeploymentManager(self)
106 self.horizontalpodautoscalers = K8sHorizontalPodAutoscalerManager(self)
107 self.componentstatuses = K8sComponentStatusManager(self)
108 self.resourcequotas = K8sResourceQuotaManager(self)
109 self.replicationcontrollers = K8sReplicationControllerManager(self)
110 self.pvolumeclaims = K8sPersistentVolumeClaimManager(self)
111 self.pvolumes = K8sPersistentVolumeManager(self)
112 self.replicasets = K8sReplicaSetManager(self)
113 self.networkpolicies = K8sNetworkPolicyManager(self)