diff --git a/kubelet/datadog_checks/kubelet/common.py b/kubelet/datadog_checks/kubelet/common.py index bcb4f37f3d230..d947bee1f96af 100644 --- a/kubelet/datadog_checks/kubelet/common.py +++ b/kubelet/datadog_checks/kubelet/common.py @@ -118,6 +118,9 @@ def is_excluded(self, cid, pod_uid=None): :param pod_uid: pod UID for static pod detection :return: bool """ + if not cid: + return True + if cid in self.cache: return self.cache[cid] diff --git a/kubelet/tests/test_common.py b/kubelet/tests/test_common.py index e0ccdf85627b7..9f7a21df5adaf 100644 --- a/kubelet/tests/test_common.py +++ b/kubelet/tests/test_common.py @@ -38,6 +38,16 @@ def test_container_filter(monkeypatch): assert short_cid in filter.containers is_excluded.assert_not_called() + # Test cid == None + is_excluded.reset_mock() + assert filter.is_excluded(None) is True + is_excluded.assert_not_called() + + # Test cid == "" + is_excluded.reset_mock() + assert filter.is_excluded("") is True + is_excluded.assert_not_called() + # Test non-existing container is_excluded.reset_mock() assert filter.is_excluded("invalid") is True