Allow to configure runner volume size limit (#436)
Enable the user to set a limit size on the volume of the runner to avoid some runner pod affecting other resources of the same cluster Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
		
							parent
							
								
									2eeb56d1c8
								
							
						
					
					
						commit
						37c2a62fa8
					
				|  | @ -18,6 +18,7 @@ package v1alpha1 | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
|  | 	"k8s.io/apimachinery/pkg/api/resource" | ||||||
| 
 | 
 | ||||||
| 	corev1 "k8s.io/api/core/v1" | 	corev1 "k8s.io/api/core/v1" | ||||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
|  | @ -98,6 +99,8 @@ type RunnerSpec struct { | ||||||
| 	DockerMTU *int64 `json:"dockerMTU,omitempty"` | 	DockerMTU *int64 `json:"dockerMTU,omitempty"` | ||||||
| 	// +optional
 | 	// +optional
 | ||||||
| 	HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"` | 	HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"` | ||||||
|  | 	// +optional
 | ||||||
|  | 	VolumeSizeLimit *resource.Quantity `json:"volumeSizeLimit,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // ValidateRepository validates repository field.
 | // ValidateRepository validates repository field.
 | ||||||
|  |  | ||||||
|  | @ -713,6 +713,11 @@ func (in *RunnerSpec) DeepCopyInto(out *RunnerSpec) { | ||||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	if in.VolumeSizeLimit != nil { | ||||||
|  | 		in, out := &in.VolumeSizeLimit, &out.VolumeSizeLimit | ||||||
|  | 		x := (*in).DeepCopy() | ||||||
|  | 		*out = &x | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSpec.
 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSpec.
 | ||||||
|  |  | ||||||
|  | @ -809,6 +809,12 @@ spec: | ||||||
|                           - name |                           - name | ||||||
|                         type: object |                         type: object | ||||||
|                       type: array |                       type: array | ||||||
|  |                     volumeSizeLimit: | ||||||
|  |                       anyOf: | ||||||
|  |                         - type: integer | ||||||
|  |                         - type: string | ||||||
|  |                       pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ | ||||||
|  |                       x-kubernetes-int-or-string: true | ||||||
|                     volumes: |                     volumes: | ||||||
|                       items: |                       items: | ||||||
|                         description: Volume represents a named volume in a pod that may be accessed by any container in the pod. |                         description: Volume represents a named volume in a pod that may be accessed by any container in the pod. | ||||||
|  |  | ||||||
|  | @ -809,6 +809,12 @@ spec: | ||||||
|                           - name |                           - name | ||||||
|                         type: object |                         type: object | ||||||
|                       type: array |                       type: array | ||||||
|  |                     volumeSizeLimit: | ||||||
|  |                       anyOf: | ||||||
|  |                         - type: integer | ||||||
|  |                         - type: string | ||||||
|  |                       pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ | ||||||
|  |                       x-kubernetes-int-or-string: true | ||||||
|                     volumes: |                     volumes: | ||||||
|                       items: |                       items: | ||||||
|                         description: Volume represents a named volume in a pod that may be accessed by any container in the pod. |                         description: Volume represents a named volume in a pod that may be accessed by any container in the pod. | ||||||
|  |  | ||||||
|  | @ -774,6 +774,12 @@ spec: | ||||||
|                   - name |                   - name | ||||||
|                 type: object |                 type: object | ||||||
|               type: array |               type: array | ||||||
|  |             volumeSizeLimit: | ||||||
|  |               anyOf: | ||||||
|  |                 - type: integer | ||||||
|  |                 - type: string | ||||||
|  |               pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ | ||||||
|  |               x-kubernetes-int-or-string: true | ||||||
|             volumes: |             volumes: | ||||||
|               items: |               items: | ||||||
|                 description: Volume represents a named volume in a pod that may be accessed by any container in the pod. |                 description: Volume represents a named volume in a pod that may be accessed by any container in the pod. | ||||||
|  |  | ||||||
|  | @ -809,6 +809,12 @@ spec: | ||||||
|                           - name |                           - name | ||||||
|                         type: object |                         type: object | ||||||
|                       type: array |                       type: array | ||||||
|  |                     volumeSizeLimit: | ||||||
|  |                       anyOf: | ||||||
|  |                         - type: integer | ||||||
|  |                         - type: string | ||||||
|  |                       pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ | ||||||
|  |                       x-kubernetes-int-or-string: true | ||||||
|                     volumes: |                     volumes: | ||||||
|                       items: |                       items: | ||||||
|                         description: Volume represents a named volume in a pod that may be accessed by any container in the pod. |                         description: Volume represents a named volume in a pod that may be accessed by any container in the pod. | ||||||
|  |  | ||||||
|  | @ -809,6 +809,12 @@ spec: | ||||||
|                           - name |                           - name | ||||||
|                         type: object |                         type: object | ||||||
|                       type: array |                       type: array | ||||||
|  |                     volumeSizeLimit: | ||||||
|  |                       anyOf: | ||||||
|  |                         - type: integer | ||||||
|  |                         - type: string | ||||||
|  |                       pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ | ||||||
|  |                       x-kubernetes-int-or-string: true | ||||||
|                     volumes: |                     volumes: | ||||||
|                       items: |                       items: | ||||||
|                         description: Volume represents a named volume in a pod that may be accessed by any container in the pod. |                         description: Volume represents a named volume in a pod that may be accessed by any container in the pod. | ||||||
|  |  | ||||||
|  | @ -774,6 +774,12 @@ spec: | ||||||
|                   - name |                   - name | ||||||
|                 type: object |                 type: object | ||||||
|               type: array |               type: array | ||||||
|  |             volumeSizeLimit: | ||||||
|  |               anyOf: | ||||||
|  |                 - type: integer | ||||||
|  |                 - type: string | ||||||
|  |               pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ | ||||||
|  |               x-kubernetes-int-or-string: true | ||||||
|             volumes: |             volumes: | ||||||
|               items: |               items: | ||||||
|                 description: Volume represents a named volume in a pod that may be accessed by any container in the pod. |                 description: Volume represents a named volume in a pod that may be accessed by any container in the pod. | ||||||
|  |  | ||||||
|  | @ -644,12 +644,17 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | ||||||
| 
 | 
 | ||||||
| 	runnerVolumeName := "runner" | 	runnerVolumeName := "runner" | ||||||
| 	runnerVolumeMountPath := "/runner" | 	runnerVolumeMountPath := "/runner" | ||||||
|  | 	runnerVolumeEmptyDir := &corev1.EmptyDirVolumeSource{} | ||||||
|  | 
 | ||||||
|  | 	if runner.Spec.VolumeSizeLimit != nil { | ||||||
|  | 		runnerVolumeEmptyDir.SizeLimit = runner.Spec.VolumeSizeLimit | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	pod.Spec.Volumes = append(pod.Spec.Volumes, | 	pod.Spec.Volumes = append(pod.Spec.Volumes, | ||||||
| 		corev1.Volume{ | 		corev1.Volume{ | ||||||
| 			Name: runnerVolumeName, | 			Name: runnerVolumeName, | ||||||
| 			VolumeSource: corev1.VolumeSource{ | 			VolumeSource: corev1.VolumeSource{ | ||||||
| 				EmptyDir: &corev1.EmptyDirVolumeSource{}, | 				EmptyDir: runnerVolumeEmptyDir, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 	) | 	) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue