Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 1 | # 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 Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 15 | import kubernetes |
| 16 | from kubernetes import client |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 17 | |
| 18 | from tcp_tests.managers.k8s.componentstatuses import \ |
| 19 | K8sComponentStatusManager |
| 20 | from tcp_tests.managers.k8s.daemonsets import K8sDaemonSetManager |
| 21 | from tcp_tests.managers.k8s.deployments import K8sDeploymentManager |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 22 | from tcp_tests.managers.k8s.endpoints import K8sEndpointsManager |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 23 | from tcp_tests.managers.k8s.events import K8sEventManager |
| 24 | from tcp_tests.managers.k8s.horizontalpodautoscalers import \ |
| 25 | K8sHorizontalPodAutoscalerManager |
| 26 | from tcp_tests.managers.k8s.ingresses import K8sIngressManager |
| 27 | from tcp_tests.managers.k8s.jobs import K8sJobManager |
| 28 | from tcp_tests.managers.k8s.limitranges import K8sLimitRangeManager |
| 29 | from tcp_tests.managers.k8s.namespaces import K8sNamespaceManager |
| 30 | from tcp_tests.managers.k8s.nodes import K8sNodeManager |
| 31 | from tcp_tests.managers.k8s.persistentvolumeclaims import \ |
| 32 | K8sPersistentVolumeClaimManager |
| 33 | from tcp_tests.managers.k8s.persistentvolumes import \ |
| 34 | K8sPersistentVolumeManager |
| 35 | from tcp_tests.managers.k8s.pods import K8sPodManager |
| 36 | from tcp_tests.managers.k8s.replicationcontrollers import \ |
| 37 | K8sReplicationControllerManager |
| 38 | from tcp_tests.managers.k8s.resourcequotas import K8sResourceQuotaManager |
| 39 | from tcp_tests.managers.k8s.secrets import K8sSecretManager |
| 40 | from tcp_tests.managers.k8s.serviceaccounts import \ |
| 41 | K8sServiceAccountManager |
| 42 | from tcp_tests.managers.k8s.services import K8sServiceManager |
| 43 | from tcp_tests.managers.k8s.replicasets import K8sReplicaSetManager |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 44 | from tcp_tests.managers.k8s.networkpolicies import K8sNetworkPolicyManager |
Vladimir Jigulin | 57ecae9 | 2018-09-10 22:51:15 +0400 | [diff] [blame] | 45 | from tcp_tests.managers.k8s.clusterrolebindings import \ |
| 46 | K8sClusterRoleBindingManager |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 47 | |
| 48 | |
| 49 | class K8sCluster(object): |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 50 | def __init__(self, schema="https", user=None, password=None, ca=None, |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 51 | host='localhost', port='443', default_namespace='default'): |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 52 | self.default_namespace = default_namespace |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 53 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 54 | api_server = '{0}://{1}:{2}'.format(schema, host, port) |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 55 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 56 | config_data = { |
| 57 | 'apiVersion': 'v1', |
| 58 | 'kind': 'Config', |
| 59 | 'preferences': {}, |
| 60 | 'current-context': 'cluster-remote', |
| 61 | 'clusters': [{ |
| 62 | 'name': 'cluster', |
| 63 | 'cluster': { |
| 64 | 'server': api_server, |
| 65 | 'certificate-authority-data': ca, |
| 66 | }, |
| 67 | }], |
| 68 | 'users': [{ |
| 69 | 'name': 'remote', |
| 70 | 'user': { |
| 71 | 'password': password, |
| 72 | 'username': user, |
| 73 | }, |
| 74 | }], |
| 75 | 'contexts': [{ |
| 76 | 'name': 'cluster-remote', |
| 77 | 'context': { |
| 78 | 'cluster': 'cluster', |
| 79 | 'user': 'remote', |
| 80 | }, |
| 81 | }], |
| 82 | } |
| 83 | |
| 84 | configuration = type.__call__(client.Configuration) |
| 85 | loader = kubernetes.config.kube_config.KubeConfigLoader(config_data) |
| 86 | loader.load_and_set(configuration) |
| 87 | api_client = client.ApiClient(configuration=configuration) |
| 88 | |
| 89 | self.api_core = client.CoreV1Api(api_client) |
| 90 | self.api_apps = client.AppsV1Api(api_client) |
| 91 | self.api_extensions = client.ExtensionsV1beta1Api(api_client) |
| 92 | self.api_autoscaling = client.AutoscalingV1Api(api_client) |
| 93 | self.api_batch = client.BatchV1Api(api_client) |
Vladimir Jigulin | 57ecae9 | 2018-09-10 22:51:15 +0400 | [diff] [blame] | 94 | self.api_rbac_auth = client.RbacAuthorizationV1Api(api_client) |
Dennis Dmitriev | 445b432 | 2018-10-08 14:32:07 +0300 | [diff] [blame] | 95 | self.api_version = client.VersionApi(api_client) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 96 | |
| 97 | self.nodes = K8sNodeManager(self) |
| 98 | self.pods = K8sPodManager(self) |
| 99 | self.endpoints = K8sEndpointsManager(self) |
| 100 | self.namespaces = K8sNamespaceManager(self) |
| 101 | self.services = K8sServiceManager(self) |
| 102 | self.serviceaccounts = K8sServiceAccountManager(self) |
| 103 | self.secrets = K8sSecretManager(self) |
| 104 | self.events = K8sEventManager(self) |
| 105 | self.limitranges = K8sLimitRangeManager(self) |
| 106 | self.jobs = K8sJobManager(self) |
| 107 | self.daemonsets = K8sDaemonSetManager(self) |
| 108 | self.ingresses = K8sIngressManager(self) |
| 109 | self.deployments = K8sDeploymentManager(self) |
| 110 | self.horizontalpodautoscalers = K8sHorizontalPodAutoscalerManager(self) |
| 111 | self.componentstatuses = K8sComponentStatusManager(self) |
| 112 | self.resourcequotas = K8sResourceQuotaManager(self) |
| 113 | self.replicationcontrollers = K8sReplicationControllerManager(self) |
| 114 | self.pvolumeclaims = K8sPersistentVolumeClaimManager(self) |
| 115 | self.pvolumes = K8sPersistentVolumeManager(self) |
| 116 | self.replicasets = K8sReplicaSetManager(self) |
| 117 | self.networkpolicies = K8sNetworkPolicyManager(self) |
Vladimir Jigulin | 57ecae9 | 2018-09-10 22:51:15 +0400 | [diff] [blame] | 118 | self.clusterrolebindings = K8sClusterRoleBindingManager(self) |