Coverage for ocp_resources/daemonset.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-30 10:48 +0200

1import kubernetes 

2 

3from ocp_resources.utils.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES 

4from ocp_resources.resource import NamespacedResource 

5from timeout_sampler import TimeoutSampler 

6 

7 

8class DaemonSet(NamespacedResource): 

9 """ 

10 DaemonSet object. 

11 """ 

12 

13 api_group = NamespacedResource.ApiGroup.APPS 

14 

15 def wait_until_deployed(self, timeout=TIMEOUT_4MINUTES): 

16 """ 

17 Wait until all Pods are deployed and ready. 

18 

19 Args: 

20 timeout (int): Time to wait for the Daemonset. 

21 

22 Raises: 

23 TimeoutExpiredError: If not all the pods are deployed. 

24 """ 

25 self.logger.info(f"Wait for {self.kind} {self.name} to deploy all desired pods") 

26 samples = TimeoutSampler( 

27 wait_timeout=timeout, 

28 sleep=1, 

29 exceptions_dict=PROTOCOL_ERROR_EXCEPTION_DICT, 

30 func=self.api.get, 

31 field_selector=f"metadata.name=={self.name}", 

32 namespace=self.namespace, 

33 ) 

34 for sample in samples: 

35 if sample.items: 

36 status = sample.items[0].status 

37 desired_number_scheduled = status.desiredNumberScheduled 

38 number_ready = status.numberReady 

39 if desired_number_scheduled > 0 and desired_number_scheduled == number_ready: 

40 return 

41 

42 def delete(self, wait=False, timeout=TIMEOUT_4MINUTES, body=None): 

43 """ 

44 Delete Daemonset 

45 

46 Args: 

47 wait (bool): True to wait for Daemonset to be deleted. 

48 timeout (int): Time to wait for resource deletion 

49 body (dict): Content to send for delete() 

50 

51 Returns: 

52 bool: True if delete succeeded, False otherwise. 

53 """ 

54 return super().delete( 

55 wait=wait, 

56 timeout=timeout, 

57 body=kubernetes.client.V1DeleteOptions(propagation_policy="Foreground"), 

58 )