def test_get_pod_by_metric_label(monkeypatch): check = KubeletCheck('kubelet', None, {}, [{}]) monkeypatch.setattr( check, 'retrieve_pod_list', mock.Mock(return_value=json.loads(mock_from_file('pods.json')))) check.pod_list = check.retrieve_pod_list() assert len(check.pod_list) == 4 kube_proxy = check._get_pod_by_metric_label([ Label("container_name", value="POD"), Label( "id", value="/kubepods/burstable/" "pod260c2b1d43b094af6d6b4ccba082c2db/" "0bce0ef7e6cd073e8f9cec3027e1c0057ce1baddce98113d742b816726a95ab1" ), ]) fluentd = check._get_pod_by_metric_label([ Label("container_name", value="POD"), Label( "id", value="/kubepods/burstable/" "pod2edfd4d9-10ce-11e8-bd5a-42010af00137/" "7990c0e549a1a578b1313475540afc53c91081c32e735564da6244ddf0b86030" ), ]) assert kube_proxy["metadata"][ "name"] == "kube-proxy-gke-haissam-default-pool-be5066f1-wnvn" assert fluentd["metadata"]["name"] == "fluentd-gcp-v2.0.10-9q9t4"
def test_is_static_pending_pod(monkeypatch): check = KubeletCheck('kubelet', None, {}, [{}]) monkeypatch.setattr( check, 'retrieve_pod_list', mock.Mock(return_value=json.loads(mock_from_file('pods.json')))) check.pod_list = check.retrieve_pod_list() assert len(check.pod_list) == 4 static_pod = check._get_pod_by_metric_label([ Label("container_name", value="POD"), Label( "id", value="/kubepods/burstable/" "pod260c2b1d43b094af6d6b4ccba082c2db/" "0bce0ef7e6cd073e8f9cec3027e1c0057ce1baddce98113d742b816726a95ab1" ), ]) api_pod = check._get_pod_by_metric_label([ Label("container_name", value="POD"), Label( "id", value="/kubepods/burstable/" "pod2edfd4d9-10ce-11e8-bd5a-42010af00137/" "7990c0e549a1a578b1313475540afc53c91081c32e735564da6244ddf0b86030" ), ]) assert check._is_static_pending_pod(static_pod) is True assert check._is_static_pending_pod(api_pod) is False