Merge ~nikolay.vinogradov/charm-nrpe:lp2008926 into charm-nrpe:master

Proposed by Nikolay Vinogradov
Status: Merged
Approved by: Erhan Sunar
Approved revision: fa9402ff622c20a8783c05d64bb0900036dc9895
Merged at revision: 2a396fcb7f8c3f1e9775b18a30c37c654f2b21fe
Proposed branch: ~nikolay.vinogradov/charm-nrpe:lp2008926
Merge into: charm-nrpe:master
Diff against target: 74 lines (+25/-8)
2 files modified
hooks/nrpe_helpers.py (+12/-7)
tests/unit/test_nrpe_helpers.py (+13/-1)
Reviewer Review Type Date Requested Status
Sudeep Bhandari Approve
Erhan Sunar (community) Approve
Andrea Ieri Approve
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
BootStack Reviewers Pending
Review via email: mp+438754@code.launchpad.net

Commit message

Exclude mounted Kubernetes PVs from the check_space check.

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andrea Ieri (aieri) wrote :

get_partitions_to_check() is already producing the list of mountpoints that need to be checked, filtering out the ones that need to be skipped. Wouldn't it be better to handle skipping pod mountpoints there?

review: Needs Fixing
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andrea Ieri (aieri) wrote :

in-line comment

review: Needs Fixing
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andrea Ieri (aieri) wrote :

Thanks, this looks good, we're only missing test cases. I see we have a TestDiskSpaceCheck class where we should plug a test or two. Apologies for not mentioning this in my previous review...

review: Needs Fixing
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andrea Ieri (aieri) wrote :

lgtm, although I've submitted MP#440218 to slightly improve the test

review: Approve
Revision history for this message
Erhan Sunar (esunar) :
review: Approve
Revision history for this message
Sudeep Bhandari (sudeephb) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 2a396fcb7f8c3f1e9775b18a30c37c654f2b21fe

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/nrpe_helpers.py b/hooks/nrpe_helpers.py
2index 3aa9238..b485822 100644
3--- a/hooks/nrpe_helpers.py
4+++ b/hooks/nrpe_helpers.py
5@@ -818,6 +818,11 @@ def is_valid_partition(device):
6 return True
7
8
9+def is_kubernetes_pv(mountpoint):
10+ """Check if a mountpoint is Kubernetes persistent volume."""
11+ return mountpoint.startswith("/var/lib/kubelet/pods")
12+
13+
14 def get_partitions_to_check():
15 """Get a list of partitions to be checked by check_disk."""
16 lsblk_cmd = "lsblk -J".split()
17@@ -828,18 +833,18 @@ def get_partitions_to_check():
18 for dev in block_devices:
19 if not is_valid_partition(dev):
20 continue
21- if dev.get("mountpoint", ""):
22- partitions_to_check.add(dev.get("mountpoint"))
23+ mnt = dev.get("mountpoint", "")
24+ if mnt and not is_kubernetes_pv(mnt):
25+ partitions_to_check.add(mnt)
26 for child in dev.get("children", []):
27 if not is_valid_partition(child):
28 continue
29- if child.get("mountpoint", ""):
30- partitions_to_check.add(child.get("mountpoint"))
31 # Jammy returns a list of "mountpoints" instead of a single value
32 # in the key "mountpoint"
33- for mountpoint in child.get("mountpoints", []):
34- if mountpoint:
35- partitions_to_check.add(mountpoint)
36+ mountpoints = child.get("mountpoints", []) or [child.get("mountpoint")]
37+ for mnt in filter(bool, mountpoints):
38+ if not is_kubernetes_pv(mnt):
39+ partitions_to_check.add(mnt)
40
41 skipped_partitions = {"[SWAP]", "/boot/efi"}
42
43diff --git a/tests/unit/test_nrpe_helpers.py b/tests/unit/test_nrpe_helpers.py
44index d9ea79a..9f48f17 100644
45--- a/tests/unit/test_nrpe_helpers.py
46+++ b/tests/unit/test_nrpe_helpers.py
47@@ -279,7 +279,16 @@ class TestDiskSpaceCheck(unittest.TestCase):
48 ]
49 }
50 ]
51- }
52+ },
53+ {
54+ "name":"vdb",
55+ "maj:min":"252:16",
56+ "rm":false,
57+ "size":"1G",
58+ "ro":false,
59+ "type":"disk",
60+ "mountpoint": "/var/lib/kubelet/pods/../k..s.io~csi/pvc../mount"
61+ }
62 ]
63 }"""
64
65@@ -292,6 +301,9 @@ class TestDiskSpaceCheck(unittest.TestCase):
66 self.assertEqual("/" in result, True)
67 self.assertEqual("/srv/instances" in result, True)
68 self.assertEqual("/srv/jammy" in result, True)
69+ self.assertEqual(
70+ "/var/lib/kubelet/pods/../k..s.io~csi/pvc../mount" in result, False
71+ )
72
73
74 def load_default_config():

Subscribers

People subscribed via source and target branches

to all changes: