Add variants of PodTemplate spec fields into the Runner spec (#7)
Resolves #5 Fixes #11 Fixes #12 Changes: * Added podtemplate spec * Rework pod creation logic * Added most using podspecs * Added copy of podspec * Fixed Github List method * Fixed containers * Added ability to override runner's containers * Added ability to override runner's containers * Added ability to override runner's containers * Update controllers/runner_controller.go Co-Authored-By: Moto Ishizawa <summerwind.jp@gmail.com> * Remove optional restartpolicy * Changed naming convention Co-authored-by: Moto Ishizawa <summerwind.jp@gmail.com>
This commit is contained in:
		
							parent
							
								
									23538d43b3
								
							
						
					
					
						commit
						d4c849ee09
					
				|  | @ -28,10 +28,44 @@ type RunnerSpec struct { | |||
| 	Repository string `json:"repository"` | ||||
| 
 | ||||
| 	// +optional
 | ||||
| 	Image string `json:"image"` | ||||
| 	Containers []corev1.Container `json:"containers,omitempty"` | ||||
| 	// +optional
 | ||||
| 	Resources corev1.ResourceRequirements `json:"resources,omitempty"` | ||||
| 	// +optional
 | ||||
| 	VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` | ||||
| 	// +optional
 | ||||
| 	EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"` | ||||
| 
 | ||||
| 	// +optional
 | ||||
| 	Image string `json:"image"` | ||||
| 	// +optional
 | ||||
| 	Env []corev1.EnvVar `json:"env,omitempty"` | ||||
| 
 | ||||
| 	// +optional
 | ||||
| 	Volumes []corev1.Volume `json:"volumes,omitempty"` | ||||
| 
 | ||||
| 	// +optional
 | ||||
| 	InitContainers []corev1.Container `json:"initContainers,omitempty"` | ||||
| 	// +optional
 | ||||
| 	SidecarContainers []corev1.Container `json:"sidecarContainers,omitempty"` | ||||
| 	// +optional
 | ||||
| 	NodeSelector map[string]string `json:"nodeSelector,omitempty"` | ||||
| 	// +optional
 | ||||
| 	ServiceAccountName string `json:"serviceAccountName,omitempty"` | ||||
| 	// +optional
 | ||||
| 	AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty"` | ||||
| 	// +optional
 | ||||
| 	SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"` | ||||
| 	// +optional
 | ||||
| 	ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` | ||||
| 	// +optional
 | ||||
| 	Affinity *corev1.Affinity `json:"affinity,omitempty"` | ||||
| 	// +optional
 | ||||
| 	Tolerations []corev1.Toleration `json:"tolerations,omitempty"` | ||||
| 	// +optional
 | ||||
| 	EphemeralContainers []corev1.EphemeralContainer `json:"ephemeralContainers,omitempty"` | ||||
| 	// +optional
 | ||||
| 	TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` | ||||
| } | ||||
| 
 | ||||
| // RunnerStatus defines the observed state of Runner
 | ||||
|  |  | |||
|  | @ -277,6 +277,28 @@ func (in *RunnerReplicaSetStatus) DeepCopy() *RunnerReplicaSetStatus { | |||
| // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 | ||||
| func (in *RunnerSpec) DeepCopyInto(out *RunnerSpec) { | ||||
| 	*out = *in | ||||
| 	if in.Containers != nil { | ||||
| 		in, out := &in.Containers, &out.Containers | ||||
| 		*out = make([]v1.Container, len(*in)) | ||||
| 		for i := range *in { | ||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	in.Resources.DeepCopyInto(&out.Resources) | ||||
| 	if in.VolumeMounts != nil { | ||||
| 		in, out := &in.VolumeMounts, &out.VolumeMounts | ||||
| 		*out = make([]v1.VolumeMount, len(*in)) | ||||
| 		for i := range *in { | ||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	if in.EnvFrom != nil { | ||||
| 		in, out := &in.EnvFrom, &out.EnvFrom | ||||
| 		*out = make([]v1.EnvFromSource, len(*in)) | ||||
| 		for i := range *in { | ||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	if in.Env != nil { | ||||
| 		in, out := &in.Env, &out.Env | ||||
| 		*out = make([]v1.EnvVar, len(*in)) | ||||
|  | @ -284,6 +306,73 @@ func (in *RunnerSpec) DeepCopyInto(out *RunnerSpec) { | |||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	if in.Volumes != nil { | ||||
| 		in, out := &in.Volumes, &out.Volumes | ||||
| 		*out = make([]v1.Volume, len(*in)) | ||||
| 		for i := range *in { | ||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	if in.InitContainers != nil { | ||||
| 		in, out := &in.InitContainers, &out.InitContainers | ||||
| 		*out = make([]v1.Container, len(*in)) | ||||
| 		for i := range *in { | ||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	if in.SidecarContainers != nil { | ||||
| 		in, out := &in.SidecarContainers, &out.SidecarContainers | ||||
| 		*out = make([]v1.Container, len(*in)) | ||||
| 		for i := range *in { | ||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	if in.NodeSelector != nil { | ||||
| 		in, out := &in.NodeSelector, &out.NodeSelector | ||||
| 		*out = make(map[string]string, len(*in)) | ||||
| 		for key, val := range *in { | ||||
| 			(*out)[key] = val | ||||
| 		} | ||||
| 	} | ||||
| 	if in.AutomountServiceAccountToken != nil { | ||||
| 		in, out := &in.AutomountServiceAccountToken, &out.AutomountServiceAccountToken | ||||
| 		*out = new(bool) | ||||
| 		**out = **in | ||||
| 	} | ||||
| 	if in.SecurityContext != nil { | ||||
| 		in, out := &in.SecurityContext, &out.SecurityContext | ||||
| 		*out = new(v1.PodSecurityContext) | ||||
| 		(*in).DeepCopyInto(*out) | ||||
| 	} | ||||
| 	if in.ImagePullSecrets != nil { | ||||
| 		in, out := &in.ImagePullSecrets, &out.ImagePullSecrets | ||||
| 		*out = make([]v1.LocalObjectReference, len(*in)) | ||||
| 		copy(*out, *in) | ||||
| 	} | ||||
| 	if in.Affinity != nil { | ||||
| 		in, out := &in.Affinity, &out.Affinity | ||||
| 		*out = new(v1.Affinity) | ||||
| 		(*in).DeepCopyInto(*out) | ||||
| 	} | ||||
| 	if in.Tolerations != nil { | ||||
| 		in, out := &in.Tolerations, &out.Tolerations | ||||
| 		*out = make([]v1.Toleration, len(*in)) | ||||
| 		for i := range *in { | ||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	if in.EphemeralContainers != nil { | ||||
| 		in, out := &in.EphemeralContainers, &out.EphemeralContainers | ||||
| 		*out = make([]v1.EphemeralContainer, len(*in)) | ||||
| 		for i := range *in { | ||||
| 			(*in)[i].DeepCopyInto(&(*out)[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	if in.TerminationGracePeriodSeconds != nil { | ||||
| 		in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds | ||||
| 		*out = new(int64) | ||||
| 		**out = **in | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSpec.
 | ||||
|  |  | |||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -41,6 +41,11 @@ const ( | |||
| 	finalizerName = "runner.actions.summerwind.dev" | ||||
| ) | ||||
| 
 | ||||
| type GitHubRunnerList struct { | ||||
| 	TotalCount int            `json:"total_count"` | ||||
| 	Runners    []GitHubRunner `json:"runners,omitempty"` | ||||
| } | ||||
| 
 | ||||
| type GitHubRunner struct { | ||||
| 	ID     int    `json:"id"` | ||||
| 	Name   string `json:"name"` | ||||
|  | @ -267,7 +272,7 @@ func (r *RunnerReconciler) unregisterRunner(ctx context.Context, repo, name stri | |||
| 	} | ||||
| 
 | ||||
| 	id := 0 | ||||
| 	for _, runner := range runners { | ||||
| 	for _, runner := range runners.Runners { | ||||
| 		if runner.Name == name { | ||||
| 			id = runner.ID | ||||
| 			break | ||||
|  | @ -285,8 +290,8 @@ func (r *RunnerReconciler) unregisterRunner(ctx context.Context, repo, name stri | |||
| 	return true, nil | ||||
| } | ||||
| 
 | ||||
| func (r *RunnerReconciler) listRunners(ctx context.Context, repo string) ([]GitHubRunner, error) { | ||||
| 	runners := []GitHubRunner{} | ||||
| func (r *RunnerReconciler) listRunners(ctx context.Context, repo string) (GitHubRunnerList, error) { | ||||
| 	runners := GitHubRunnerList{} | ||||
| 
 | ||||
| 	req, err := r.GitHubClient.NewRequest("GET", fmt.Sprintf("/repos/%s/actions/runners", repo), nil) | ||||
| 	if err != nil { | ||||
|  | @ -348,12 +353,14 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | |||
| 			Value: runner.Status.Registration.Token, | ||||
| 		}, | ||||
| 	} | ||||
| 	env = append(env, runner.Spec.Env...) | ||||
| 
 | ||||
| 	env = append(env, runner.Spec.Env...) | ||||
| 	pod := corev1.Pod{ | ||||
| 		ObjectMeta: metav1.ObjectMeta{ | ||||
| 			Name:      runner.Name, | ||||
| 			Namespace: runner.Namespace, | ||||
| 			Name:        runner.Name, | ||||
| 			Namespace:   runner.Namespace, | ||||
| 			Labels:      runner.Labels, | ||||
| 			Annotations: runner.Annotations, | ||||
| 		}, | ||||
| 		Spec: corev1.PodSpec{ | ||||
| 			RestartPolicy: "OnFailure", | ||||
|  | @ -363,6 +370,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | |||
| 					Image:           runnerImage, | ||||
| 					ImagePullPolicy: "Always", | ||||
| 					Env:             env, | ||||
| 					EnvFrom:         runner.Spec.EnvFrom, | ||||
| 					VolumeMounts: []corev1.VolumeMount{ | ||||
| 						{ | ||||
| 							Name:      "docker", | ||||
|  | @ -372,6 +380,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | |||
| 					SecurityContext: &corev1.SecurityContext{ | ||||
| 						RunAsGroup: &group, | ||||
| 					}, | ||||
| 					Resources: runner.Spec.Resources, | ||||
| 				}, | ||||
| 				{ | ||||
| 					Name:  "docker", | ||||
|  | @ -398,6 +407,59 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { | |||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| 	if len(runner.Spec.Containers) != 0 { | ||||
| 		pod.Spec.Containers = runner.Spec.Containers | ||||
| 	} | ||||
| 
 | ||||
| 	if len(runner.Spec.VolumeMounts) != 0 { | ||||
| 		pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, runner.Spec.VolumeMounts...) | ||||
| 	} | ||||
| 
 | ||||
| 	if len(runner.Spec.Volumes) != 0 { | ||||
| 		pod.Spec.Volumes = append(runner.Spec.Volumes, runner.Spec.Volumes...) | ||||
| 	} | ||||
| 	if len(runner.Spec.InitContainers) != 0 { | ||||
| 		pod.Spec.InitContainers = append(pod.Spec.InitContainers, runner.Spec.InitContainers...) | ||||
| 	} | ||||
| 
 | ||||
| 	if runner.Spec.NodeSelector != nil { | ||||
| 		pod.Spec.NodeSelector = runner.Spec.NodeSelector | ||||
| 	} | ||||
| 	if runner.Spec.ServiceAccountName != "" { | ||||
| 		pod.Spec.ServiceAccountName = runner.Spec.ServiceAccountName | ||||
| 	} | ||||
| 	if runner.Spec.AutomountServiceAccountToken != nil { | ||||
| 		pod.Spec.AutomountServiceAccountToken = runner.Spec.AutomountServiceAccountToken | ||||
| 	} | ||||
| 
 | ||||
| 	if len(runner.Spec.SidecarContainers) != 0 { | ||||
| 		pod.Spec.Containers = append(pod.Spec.Containers, runner.Spec.SidecarContainers...) | ||||
| 	} | ||||
| 
 | ||||
| 	if runner.Spec.SecurityContext != nil { | ||||
| 		pod.Spec.SecurityContext = runner.Spec.SecurityContext | ||||
| 	} | ||||
| 
 | ||||
| 	if len(runner.Spec.ImagePullSecrets) != 0 { | ||||
| 		pod.Spec.ImagePullSecrets = runner.Spec.ImagePullSecrets | ||||
| 	} | ||||
| 
 | ||||
| 	if runner.Spec.Affinity != nil { | ||||
| 		pod.Spec.Affinity = runner.Spec.Affinity | ||||
| 	} | ||||
| 
 | ||||
| 	if len(runner.Spec.Tolerations) != 0 { | ||||
| 		pod.Spec.Tolerations = runner.Spec.Tolerations | ||||
| 	} | ||||
| 
 | ||||
| 	if len(runner.Spec.EphemeralContainers) != 0 { | ||||
| 		pod.Spec.EphemeralContainers = runner.Spec.EphemeralContainers | ||||
| 	} | ||||
| 
 | ||||
| 	if runner.Spec.TerminationGracePeriodSeconds != nil { | ||||
| 		pod.Spec.TerminationGracePeriodSeconds = runner.Spec.TerminationGracePeriodSeconds | ||||
| 	} | ||||
| 
 | ||||
| 	if err := ctrl.SetControllerReference(&runner, &pod, r.Scheme); err != nil { | ||||
| 		return pod, err | ||||
| 	} | ||||
|  |  | |||
							
								
								
									
										2
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										2
									
								
								go.mod
								
								
								
								
							|  | @ -9,7 +9,7 @@ require ( | |||
| 	github.com/davecgh/go-spew v1.1.1 | ||||
| 	github.com/go-logr/logr v0.1.0 | ||||
| 	github.com/google/go-github v17.0.0+incompatible | ||||
| 	github.com/google/go-github/v29 v29.0.2 | ||||
| 	github.com/google/go-github/v29 v29.0.3 | ||||
| 	github.com/onsi/ginkgo v1.8.0 | ||||
| 	github.com/onsi/gomega v1.5.0 | ||||
| 	github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 | ||||
|  |  | |||
							
								
								
									
										2
									
								
								go.sum
								
								
								
								
							
							
						
						
									
										2
									
								
								go.sum
								
								
								
								
							|  | @ -124,6 +124,8 @@ github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4r | |||
| github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= | ||||
| github.com/google/go-github/v29 v29.0.2 h1:opYN6Wc7DOz7Ku3Oh4l7prmkOMwEcQxpFtxdU8N8Pts= | ||||
| github.com/google/go-github/v29 v29.0.2/go.mod h1:CHKiKKPHJ0REzfwc14QMklvtHwCveD0PxlMjLlzAM5E= | ||||
| github.com/google/go-github/v29 v29.0.3 h1:IktKCTwU//aFHnpA+2SLIi7Oo9uhAzgsdZNbcAqhgdc= | ||||
| github.com/google/go-github/v29 v29.0.3/go.mod h1:CHKiKKPHJ0REzfwc14QMklvtHwCveD0PxlMjLlzAM5E= | ||||
| github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= | ||||
| github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= | ||||
| github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue