def kube(kubeconfig, kubecontext, request) -> TestClient: """Return a client for managing a Kubernetes cluster for testing.""" if request.session.config.getoption("in_cluster"): kubernetes.config.load_incluster_config() else: if kubeconfig: kubernetes.config.load_kube_config( config_file=os.path.expandvars(os.path.expanduser(kubeconfig)), context=kubecontext, ) else: log.error( "unable to interact with cluster: kube fixture used without kube config " "set. the config may be set with the flags --kube-config or --in-cluster or by" "an env var KUBECONFIG or custom kubeconfig fixture definition." ) raise errors.SetupError("no kube config defined for test run") test_case = manager.get_test(request.node.nodeid) if test_case is None: log.error( f'No kubetest client found for test using the "kube" fixture. ({request.node.nodeid})', # noqa ) raise errors.SetupError("error generating test client") # Setup the test case. This will create the namespace and any other # objects (e.g. role bindings) that the test case will need. test_case.setup() return test_case.client
def kube(kubeconfig, request): """Return a client for managing a Kubernetes cluster for testing.""" if not kubeconfig: log.error( 'kube fixture used when no --kube-config is set; unable to install test ' 'resources onto a cluster.') raise errors.SetupError('--kube-config not set') test_case = manager.get_test(request.node.nodeid) if test_case is None: log.error( 'No kubetest client found for test using the "kube" fixture. ({})'. format(request.node.nodeid, )) raise errors.SetupError('error generating test client') # Setup the test case. This will create the namespace and any other # objects (e.g. role bindings) that the test case will need. kubernetes.config.load_kube_config( config_file=os.path.expandvars(os.path.expanduser(kubeconfig)), context=request.session.config.getoption('kube_context'), ) test_case.setup() return test_case.client
def kube_module(request): """Return a client for managing a Kubernetes cluster for testing.""" kubeconfig = request.session.config.getoption("kube_config") if not kubeconfig: log.error( "kube fixture used when no --kube-config is set; unable to install test " "resources onto a cluster.") raise errors.SetupError("--kube-config not set") module_environment = manager.new_test(request.node.nodeid, "kube_module") if module_environment is None: log.error( 'No kubetest client found for test using the "kube_module" fixture. ({})' .format(request.node.nodeid)) raise errors.SetupError("error generating test client") # Setup the test case. This will create the namespace and any other # objects (e.g. role bindings) that the test case will need. kubernetes.config.load_kube_config( config_file=os.path.expandvars(os.path.expanduser(kubeconfig)), context=request.session.config.getoption("kube_context"), ) module_environment.setup() return module_environment.client