def check_exec(host, command, label, namespace): # Just in case something is not ready yet, we make sure we can find # candidates before trying further def _wait_for_pods(): assert len(kube_utils.get_pods(host, label, namespace)) > 0 utils.retry(_wait_for_pods, times=10, wait=3, name="wait for pod labeled '{}'".format(label)) candidates = kube_utils.get_pods(host, label, namespace) assert len(candidates) == 1, ( "Expected only one Pod with label {l}, found {f}").format( l=label, f=len(candidates)) pod = candidates[0] with host.sudo(): host.check_output( 'kubectl --kubeconfig=/etc/kubernetes/admin.conf ' 'exec --namespace %s %s %s', namespace, pod['metadata']['name'], command, )
def check_pod_state(host, label, state): pods = kube_utils.get_pods( host, label, namespace="kube-system", status_phase="Running", ) assert len(pods) > 0, "No {} pod with label '{}' found".format( state.lower(), label )
def _check_pods_count(): pods = kube_utils.get_pods( host, label, namespace="kube-system", status_phase="Running", ) assert len(pods) >= min_pods_count
def _check_pods_count(): pods = kube_utils.get_pods( k8s_client, ssh_config, label, node, namespace=namespace, state="Running", ) assert len(pods) == pods_count
def check_pod_state(request, host, k8s_client, label, state): ssh_config = request.config.getoption('--ssh-config') pods = kube_utils.get_pods( k8s_client, ssh_config, label, namespace="kube-system", state="Running", ) assert pods, "No {} pod with label '{}' found".format( state.lower(), label )
def _wait_for_status(): pods = kube_utils.get_pods( k8s_client, ssh_config, label, namespace=namespace ) assert pods for pod in pods: # If really not ready, status may not have been pushed yet. if pod.status.conditions is None: assert expected_status == 'NotReady' continue for condition in pod.status.conditions: if condition.type == 'Ready': break assert kube_utils.MAP_STATUS[condition.status] == expected_status return pods
def check_exec(request, host, k8s_client, command, label, namespace): ssh_config = request.config.getoption('--ssh-config') # Just in case something is not ready yet, we make sure we can find # candidates before trying further def _wait_for_pods(): pods = kube_utils.get_pods( k8s_client, ssh_config, label, namespace=namespace ) assert len(pods) > 0 utils.retry( _wait_for_pods, times=10, wait=3, name="wait for pod labeled '{}'".format(label) ) candidates = kube_utils.get_pods( k8s_client, ssh_config, label, namespace=namespace ) assert len(candidates) == 1, ( "Expected only one Pod with label {l}, found {f}" ).format(l=label, f=len(candidates)) pod = candidates[0] with host.sudo(): host.check_output( 'kubectl --kubeconfig=/etc/kubernetes/admin.conf ' 'exec --namespace %s %s %s', namespace, pod.metadata.name, command, )
def _wait_for_pods(): assert len(kube_utils.get_pods(host, label, namespace)) > 0
def _wait_for_pods(): pods = kube_utils.get_pods( k8s_client, ssh_config, label, namespace=namespace ) assert len(pods) > 0