def test_ocp_virtual_machine_custom_subresource_config(get_kubeconfig, vm_name, vm_namespace): config = Configuration() config.debug = True resource = OcpVirtualMachines(get_kubeconfig, subresources_config=config) client = resource._get_subresources_client(vm_name, vm_namespace) assert client.config == config
def __init__(self): # Create Kubernetes config. load_incluster_config() config = Configuration() config.debug = Settings.KUBERNETES_SERVICE_DEBUG self.api_client = client.ApiClient(config) # Re-usable API client instances. self.core_api = client.CoreV1Api(self.api_client) self.custom_objects_api = client.CustomObjectsApi(self.api_client) self.extensions_api = client.ApiextensionsV1beta1Api(self.api_client) self.apps_api = client.AppsV1beta1Api(self.api_client)
def testDefaultConfiguration(self): # prepare default configuration c1 = Configuration(host="example.com") c1.debug = True Configuration.set_default(c1) # get default configuration c2 = Configuration.get_default_copy() self.assertEqual(c2.host, "example.com") self.assertTrue(c2.debug) self.assertNotEqual(id(c1.api_key), id(c2.api_key)) self.assertNotEqual(id(c1.api_key_prefix), id(c2.api_key_prefix))
def test___init__(self, client_mock): KubernetesService() config = Configuration() config.debug = False expected = [ call.ApiClient(config), call.CoreV1Api(client_mock.ApiClient.return_value), call.CustomObjectsApi(client_mock.ApiClient.return_value), call.ApiextensionsV1beta1Api(client_mock.ApiClient.return_value), call.AppsV1beta1Api(client_mock.ApiClient.return_value), ] with patch("kubernetes.client.configuration.Configuration.__eq__", dict_eq): self.assertEqual(expected, client_mock.mock_calls)
def init_k8s_client(kube_context: str) -> client.CoreV1Api: env = os.environ if kube_context: # config.load_kube_config() config.load_kube_config(kube_context) configuration = Configuration() configuration.verify_ssl = bool( strtobool((env.get("KUBERNETES_VERIFY_SSL", "false")))) api_client = client.ApiClient(configuration) return client.CoreV1Api(api_client) elif env.get("CHAOSTOOLKIT_IN_POD") == "true": config.load_incluster_config() proxy_url = os.getenv('HTTP_PROXY', None) if proxy_url: configuration = Configuration() configuration.proxy = proxy_url api_client = client.ApiClient(configuration) return client.CoreV1Api(api_client) else: api = client.ApiClient() return client.CoreV1Api(api) else: configuration = client.Configuration() configuration.debug = True configuration.host = os.environ.get("KUBERNETES_HOST", "http://localhost") configuration.verify_ssl = bool( strtobool((env.get("KUBERNETES_VERIFY_SSL", "false")))) configuration.cert_file = os.environ.get("KUBERNETES_CA_CERT_FILE") if "KUBERNETES_CERT_FILE" in env: configuration.cert_file = os.environ.get( "KUBERNETES_CERT_FILE") configuration.key_file = os.environ.get("KUBERNETES_KEY_FILE") elif "KUBERNETES_USERNAME" in env: configuration.username = os.environ.get("KUBERNETES_USERNAME") configuration.password = os.environ.get( "KUBERNETES_PASSWORD", "") proxy_url = os.getenv('HTTP_PROXY', None) if proxy_url: configuration.proxy = proxy_url api = client.ApiClient(configuration) return client.CoreV1Api(api)