Exemplo n.º 1
0
 def mock_kube_get_kubernetes_config(obj):
     config = Configuration()
     config.host = FAKE_API_ENDPOINT
     config.ssl_ca_cert = self.ssl_ca_file.name
     config.cert_file = self.cert_file.name
     config.key_file = self.key_file.name
     return config
Exemplo n.º 2
0
    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)