From 2273b198a162bdbb602ffbc158748ad063ecc145 Mon Sep 17 00:00:00 2001 From: Brandon Kimbrough <53441835+bkimbrough88@users.noreply.github.com> Date: Thu, 11 Mar 2021 18:44:49 -0500 Subject: [PATCH] Add ability to set the MTU size of the docker in docker container (#385) * adding abilitiy to set docker in docker MTU size * safeguards to only set MTU env var if it is set --- api/v1alpha1/runner_types.go | 2 ++ api/v1alpha1/zz_generated.deepcopy.go | 5 +++++ ...tions.summerwind.dev_runnerdeployments.yaml | 3 +++ ...tions.summerwind.dev_runnerreplicasets.yaml | 3 +++ .../crds/actions.summerwind.dev_runners.yaml | 3 +++ ...tions.summerwind.dev_runnerdeployments.yaml | 3 +++ ...tions.summerwind.dev_runnerreplicasets.yaml | 3 +++ .../bases/actions.summerwind.dev_runners.yaml | 3 +++ controllers/runner_controller.go | 18 ++++++++++++++++++ runner/startup.sh | 4 ++++ 10 files changed, 47 insertions(+) diff --git a/api/v1alpha1/runner_types.go b/api/v1alpha1/runner_types.go index 614d734d..9a1d06aa 100644 --- a/api/v1alpha1/runner_types.go +++ b/api/v1alpha1/runner_types.go @@ -92,6 +92,8 @@ type RunnerSpec struct { DockerdWithinRunnerContainer *bool `json:"dockerdWithinRunnerContainer,omitempty"` // +optional DockerEnabled *bool `json:"dockerEnabled,omitempty"` + // +optional + DockerMTU *int64 `json:"dockerMTU,omitempty"` } // ValidateRepository validates repository field. diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index f5752e73..b2c5ea52 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -689,6 +689,11 @@ func (in *RunnerSpec) DeepCopyInto(out *RunnerSpec) { *out = new(bool) **out = **in } + if in.DockerMTU != nil { + in, out := &in.DockerMTU, &out.DockerMTU + *out = new(int64) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RunnerSpec. diff --git a/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerdeployments.yaml b/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerdeployments.yaml index 17c05808..9c2cba09 100644 --- a/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerdeployments.yaml +++ b/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerdeployments.yaml @@ -433,6 +433,9 @@ spec: type: array dockerEnabled: type: boolean + dockerMTU: + format: int64 + type: integer dockerdContainerResources: description: ResourceRequirements describes the compute resource requirements. properties: diff --git a/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerreplicasets.yaml b/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerreplicasets.yaml index c23bfe9a..d3580df5 100644 --- a/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerreplicasets.yaml +++ b/charts/actions-runner-controller/crds/actions.summerwind.dev_runnerreplicasets.yaml @@ -433,6 +433,9 @@ spec: type: array dockerEnabled: type: boolean + dockerMTU: + format: int64 + type: integer dockerdContainerResources: description: ResourceRequirements describes the compute resource requirements. properties: diff --git a/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml b/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml index 4e5e947b..090f1af6 100644 --- a/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml +++ b/charts/actions-runner-controller/crds/actions.summerwind.dev_runners.yaml @@ -398,6 +398,9 @@ spec: type: array dockerEnabled: type: boolean + dockerMTU: + format: int64 + type: integer dockerdContainerResources: description: ResourceRequirements describes the compute resource requirements. properties: diff --git a/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml b/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml index 17c05808..9c2cba09 100644 --- a/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml +++ b/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml @@ -433,6 +433,9 @@ spec: type: array dockerEnabled: type: boolean + dockerMTU: + format: int64 + type: integer dockerdContainerResources: description: ResourceRequirements describes the compute resource requirements. properties: diff --git a/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml b/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml index c23bfe9a..d3580df5 100644 --- a/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml +++ b/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml @@ -433,6 +433,9 @@ spec: type: array dockerEnabled: type: boolean + dockerMTU: + format: int64 + type: integer dockerdContainerResources: description: ResourceRequirements describes the compute resource requirements. properties: diff --git a/config/crd/bases/actions.summerwind.dev_runners.yaml b/config/crd/bases/actions.summerwind.dev_runners.yaml index 4e5e947b..090f1af6 100644 --- a/config/crd/bases/actions.summerwind.dev_runners.yaml +++ b/config/crd/bases/actions.summerwind.dev_runners.yaml @@ -398,6 +398,9 @@ spec: type: array dockerEnabled: type: boolean + dockerMTU: + format: int64 + type: integer dockerdContainerResources: description: ResourceRequirements describes the compute resource requirements. properties: diff --git a/controllers/runner_controller.go b/controllers/runner_controller.go index 99056212..02c512bf 100644 --- a/controllers/runner_controller.go +++ b/controllers/runner_controller.go @@ -530,6 +530,15 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { }, } + if mtu := runner.Spec.DockerMTU; mtu != nil && dockerdInRunner { + pod.Spec.Containers[0].Env = append(pod.Spec.Containers[0].Env, []corev1.EnvVar{ + { + Name: "MTU", + Value: fmt.Sprintf("%d", *runner.Spec.DockerMTU), + }, + }...) + } + if !dockerdInRunner && dockerEnabled { runnerVolumeName := "runner" runnerVolumeMountPath := "/runner" @@ -612,6 +621,15 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { Resources: runner.Spec.DockerdContainerResources, }) + if mtu := runner.Spec.DockerMTU; mtu != nil { + pod.Spec.Containers[1].Env = append(pod.Spec.Containers[1].Env, []corev1.EnvVar{ + { + Name: "DOCKERD_ROOTLESS_ROOTLESSKIT_MTU", + Value: fmt.Sprintf("%d", *runner.Spec.DockerMTU), + }, + }...) + } + } if len(runner.Spec.Containers) != 0 { diff --git a/runner/startup.sh b/runner/startup.sh index fc4cf51b..0fcb1eaa 100644 --- a/runner/startup.sh +++ b/runner/startup.sh @@ -33,5 +33,9 @@ for process in "${processes[@]}"; do fi done +if [ -n "${MTU}" ]; then + ifconfig docker0 mtu ${MTU} up +fi + # Wait processes to be running entrypoint.sh