Coverage for ocp_resources/csi_driver.py: 0%

35 statements  

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

1# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md 

2 

3from typing import Any, List, Optional 

4from ocp_resources.resource import Resource 

5 

6 

7class CSIDriver(Resource): 

8 """ 

9 CSIDriver captures information about a Container Storage Interface (CSI) volume driver deployed on the cluster. Kubernetes attach detach controller uses this object to determine whether attach is required. Kubelet uses this object to determine whether pod information needs to be passed on mount. CSIDriver objects are non-namespaced. 

10 """ 

11 

12 api_group: str = Resource.ApiGroup.STORAGE_K8S_IO 

13 

14 def __init__( 

15 self, 

16 attach_required: Optional[bool] = None, 

17 fs_group_policy: Optional[str] = "", 

18 pod_info_on_mount: Optional[bool] = None, 

19 requires_republish: Optional[bool] = None, 

20 se_linux_mount: Optional[bool] = None, 

21 storage_capacity: Optional[bool] = None, 

22 token_requests: Optional[List[Any]] = None, 

23 volume_lifecycle_modes: Optional[List[Any]] = None, 

24 **kwargs: Any, 

25 ) -> None: 

26 """ 

27 Args: 

28 attach_required (bool): attachRequired indicates this CSI volume driver requires an attach 

29 operation (because it implements the CSI ControllerPublishVolume() 

30 method), and that the Kubernetes attach detach controller should 

31 call the attach volume interface which checks the volumeattachment 

32 status and waits until the volume is attached before proceeding to 

33 mounting. The CSI external-attacher coordinates with CSI volume 

34 driver and updates the volumeattachment status when the attach 

35 operation is complete. If the CSIDriverRegistry feature gate is 

36 enabled and the value is specified to false, the attach operation 

37 will be skipped. Otherwise the attach operation will be called. 

38 This field is immutable. 

39 

40 fs_group_policy (str): fsGroupPolicy defines if the underlying volume supports changing 

41 ownership and permission of the volume before being mounted. Refer 

42 to the specific FSGroupPolicy values for additional details. This 

43 field was immutable in Kubernetes < 1.29 and now is mutable. 

44 Defaults to ReadWriteOnceWithFSType, which will examine each 

45 volume to determine if Kubernetes should modify ownership and 

46 permissions of the volume. With the default policy the defined 

47 fsGroup will only be applied if a fstype is defined and the 

48 volume's access mode contains ReadWriteOnce. 

49 

50 pod_info_on_mount (bool): podInfoOnMount indicates this CSI volume driver requires additional 

51 pod information (like podName, podUID, etc.) during mount 

52 operations, if set to true. If set to false, pod information will 

53 not be passed on mount. Default is false. The CSI driver 

54 specifies podInfoOnMount as part of driver deployment. If true, 

55 Kubelet will pass pod information as VolumeContext in the CSI 

56 NodePublishVolume() calls. The CSI driver is responsible for 

57 parsing and validating the information passed in as VolumeContext. 

58 The following VolumeContext will be passed if podInfoOnMount is 

59 set to true. This list might grow, but the prefix will be used. 

60 "csi.storage.k8s.io/pod.name": pod.Name 

61 "csi.storage.k8s.io/pod.namespace": pod.Namespace 

62 "csi.storage.k8s.io/pod.uid": string(pod.UID) 

63 "csi.storage.k8s.io/ephemeral": "true" if the volume is an 

64 ephemeral inline volume defined by 

65 a CSIVolumeSource, otherwise "false" 

66 "csi.storage.k8s.io/ephemeral" is a new feature in Kubernetes 

67 1.16. It is only required for drivers which support both the 

68 "Persistent" and "Ephemeral" VolumeLifecycleMode. Other drivers 

69 can leave pod info disabled and/or ignore this field. As 

70 Kubernetes 1.15 doesn't support this field, drivers can only 

71 support one mode when deployed on such a cluster and the 

72 deployment determines which mode that is, for example via a 

73 command line parameter of the driver. This field was immutable in 

74 Kubernetes < 1.29 and now is mutable. 

75 

76 requires_republish (bool): requiresRepublish indicates the CSI driver wants `NodePublishVolume` 

77 being periodically called to reflect any possible change in the 

78 mounted volume. This field defaults to false. Note: After a 

79 successful initial NodePublishVolume call, subsequent calls to 

80 NodePublishVolume should only update the contents of the volume. 

81 New mount points will not be seen by a running container. 

82 

83 se_linux_mount (bool): seLinuxMount specifies if the CSI driver supports "-o context" mount 

84 option. When "true", the CSI driver must ensure that all volumes 

85 provided by this CSI driver can be mounted separately with 

86 different `-o context` options. This is typical for storage 

87 backends that provide volumes as filesystems on block devices or 

88 as independent shared volumes. Kubernetes will call NodeStage / 

89 NodePublish with "-o context=xyz" mount option when mounting a 

90 ReadWriteOncePod volume used in Pod that has explicitly set 

91 SELinux context. In the future, it may be expanded to other volume 

92 AccessModes. In any case, Kubernetes will ensure that the volume 

93 is mounted only with a single SELinux context. When "false", 

94 Kubernetes won't pass any special SELinux mount options to the 

95 driver. This is typical for volumes that represent subdirectories 

96 of a bigger shared filesystem. Default is "false". 

97 

98 storage_capacity (bool): storageCapacity indicates that the CSI volume driver wants pod 

99 scheduling to consider the storage capacity that the driver 

100 deployment will report by creating CSIStorageCapacity objects with 

101 capacity information, if set to true. The check can be enabled 

102 immediately when deploying a driver. In that case, provisioning 

103 new volumes with late binding will pause until the driver 

104 deployment has published some suitable CSIStorageCapacity object. 

105 Alternatively, the driver can be deployed with the field unset or 

106 false and it can be flipped later when storage capacity 

107 information has been published. This field was immutable in 

108 Kubernetes <= 1.22 and now is mutable. 

109 

110 token_requests (List[Any]): tokenRequests indicates the CSI driver needs pods' service account 

111 tokens it is mounting volume for to do necessary authentication. 

112 Kubelet will pass the tokens in VolumeContext in the CSI 

113 NodePublishVolume calls. The CSI driver should parse and validate 

114 the following VolumeContext: 

115 "csi.storage.k8s.io/serviceAccount.tokens": { "<audience>": { 

116 "token": <token>, "expirationTimestamp": <expiration timestamp 

117 in RFC3339>, }, ... } Note: Audience in each TokenRequest 

118 should be different and at most one token is empty string. To 

119 receive a new token after expiry, RequiresRepublish can be used to 

120 trigger NodePublishVolume periodically. 

121 

122 volume_lifecycle_modes (List[Any]): volumeLifecycleModes defines what kind of volumes this CSI volume 

123 driver supports. The default if the list is empty is "Persistent", 

124 which is the usage defined by the CSI specification and 

125 implemented in Kubernetes via the usual PV/PVC mechanism. The 

126 other mode is "Ephemeral". In this mode, volumes are defined 

127 inline inside the pod spec with CSIVolumeSource and their 

128 lifecycle is tied to the lifecycle of that pod. A driver has to be 

129 aware of this because it is only going to get a NodePublishVolume 

130 call for such a volume. For more information about implementing 

131 this mode, see https://kubernetes-csi.github.io/docs/ephemeral- 

132 local-volumes.html A driver can support one or more of these modes 

133 and more modes may be added in the future. This field is beta. 

134 This field is immutable. 

135 

136 """ 

137 super().__init__(**kwargs) 

138 

139 self.attach_required = attach_required 

140 self.fs_group_policy = fs_group_policy 

141 self.pod_info_on_mount = pod_info_on_mount 

142 self.requires_republish = requires_republish 

143 self.se_linux_mount = se_linux_mount 

144 self.storage_capacity = storage_capacity 

145 self.token_requests = token_requests 

146 self.volume_lifecycle_modes = volume_lifecycle_modes 

147 

148 def to_dict(self) -> None: 

149 super().to_dict() 

150 

151 if not self.kind_dict and not self.yaml_file: 

152 self.res["spec"] = {} 

153 _spec = self.res["spec"] 

154 

155 if self.attach_required is not None: 

156 _spec["attachRequired"] = self.attach_required 

157 

158 if self.fs_group_policy: 

159 _spec["fsGroupPolicy"] = self.fs_group_policy 

160 

161 if self.pod_info_on_mount is not None: 

162 _spec["podInfoOnMount"] = self.pod_info_on_mount 

163 

164 if self.requires_republish is not None: 

165 _spec["requiresRepublish"] = self.requires_republish 

166 

167 if self.se_linux_mount is not None: 

168 _spec["seLinuxMount"] = self.se_linux_mount 

169 

170 if self.storage_capacity is not None: 

171 _spec["storageCapacity"] = self.storage_capacity 

172 

173 if self.token_requests: 

174 _spec["tokenRequests"] = self.token_requests 

175 

176 if self.volume_lifecycle_modes: 

177 _spec["volumeLifecycleModes"] = self.volume_lifecycle_modes 

178 

179 # End of generated code