blob: 1531f0df057279bda5146c23cd38cb2881d8bf41 [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
Vladimir Jigulin57ecae92018-09-10 22:51:15 +040045from tcp_tests.managers.k8s.clusterrolebindings import \
46 K8sClusterRoleBindingManager
Artem Panchenko0594cd72017-06-12 13:25:26 +030047
48
49class K8sCluster(object):
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040050 def __init__(self, schema="https", user=None, password=None, ca=None,
Artem Panchenko0594cd72017-06-12 13:25:26 +030051 host='localhost', port='443', default_namespace='default'):
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040052 self.default_namespace = default_namespace
Artem Panchenko0594cd72017-06-12 13:25:26 +030053
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040054 api_server = '{0}://{1}:{2}'.format(schema, host, port)
Artem Panchenko0594cd72017-06-12 13:25:26 +030055
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040056 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 Jigulin57ecae92018-09-10 22:51:15 +040094 self.api_rbac_auth = client.RbacAuthorizationV1Api(api_client)
Dennis Dmitriev445b4322018-10-08 14:32:07 +030095 self.api_version = client.VersionApi(api_client)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040096
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 Jigulin57ecae92018-09-10 22:51:15 +0400118 self.clusterrolebindings = K8sClusterRoleBindingManager(self)