def test_kubernetes_client_constructor_when_use_cpanel_creds_true(k8s_config): client = KubernetesClient(use_cpanel_creds=True) config = client.api_client.configuration assert config.api_key_prefix["authorization"] == "Bearer" assert config.api_key["authorization"] == SERVICE_ACCOUNT_TEST_TOKEN
def test_kubernetes_client_constructor_when_id_token_passed(k8s_config): id_token = "test-user-id-token" client = KubernetesClient(id_token=id_token) config = client.api_client.configuration assert config.api_key_prefix["authorization"] == "Bearer" assert config.api_key["authorization"] == id_token
def restart(self, id_token): k8s = KubernetesClient(id_token=id_token) return k8s.AppsV1Api.delete_collection_namespaced_replica_set( self.k8s_namespace, label_selector=( f"app={self.chart_name}" # f'-{tool_deployment.tool.version}' ), )
def url(self): k8s = KubernetesClient(use_cpanel_creds=True) repo_name = github_repository_name(self.app.repo_url) ingresses = k8s.ExtensionsV1beta1Api.list_namespaced_ingress( self.APPS_NS, label_selector=f"repo={repo_name}", ).items if len(ingresses) != 1: return None return f"https://{ingresses[0].spec.rules[0].host}"
def test_kubernetes_client__getattr__(k8s_config): id_token = "test-user-id-token" client = KubernetesClient(id_token=id_token) api_client = client.api_client # These are just two examples of k8s APIs k8s_api_1 = client.ExtensionsV1beta1Api k8s_api_2 = client.AppsV1Api assert type(k8s_api_1) == kubernetes.client.api.ExtensionsV1beta1Api assert k8s_api_1.api_client == api_client assert type(k8s_api_2) == kubernetes.client.api.AppsV1Api assert k8s_api_2.api_client == api_client
def get_deployments(cls, user, id_token, search_name=None, search_version=None): deployments = [] k8s = KubernetesClient(id_token=id_token) results = k8s.AppsV1Api.list_namespaced_deployment(user.k8s_namespace) for deployment in results.items: app_name = deployment.metadata.labels["app"] _, version = deployment.metadata.labels["chart"].rsplit("-", 1) if search_name and search_name not in app_name: continue if search_version and not version.startswith(search_version): continue deployments.append(deployment) return deployments
def test_kubernetes_client_constructor_when_use_cpanel_creds_and_id_token_passed( ): with pytest.raises(ValueError): KubernetesClient(id_token="test-token", use_cpanel_creds=True)
def test_kubernetes_client_constructor_when_no_creds_passed(): with pytest.raises(ValueError): KubernetesClient()