Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set the MTU size of the docker in docker container #385

Merged
merged 3 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/v1alpha1/runner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ spec:
type: array
dockerEnabled:
type: boolean
dockerMTU:
format: int64
type: integer
dockerdContainerResources:
description: ResourceRequirements describes the compute resource requirements.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ spec:
type: array
dockerEnabled:
type: boolean
dockerMTU:
format: int64
type: integer
dockerdContainerResources:
description: ResourceRequirements describes the compute resource requirements.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ spec:
type: array
dockerEnabled:
type: boolean
dockerMTU:
format: int64
type: integer
dockerdContainerResources:
description: ResourceRequirements describes the compute resource requirements.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ spec:
type: array
dockerEnabled:
type: boolean
dockerMTU:
format: int64
type: integer
dockerdContainerResources:
description: ResourceRequirements describes the compute resource requirements.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ spec:
type: array
dockerEnabled:
type: boolean
dockerMTU:
format: int64
type: integer
dockerdContainerResources:
description: ResourceRequirements describes the compute resource requirements.
properties:
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/actions.summerwind.dev_runners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ spec:
type: array
dockerEnabled:
type: boolean
dockerMTU:
format: int64
type: integer
dockerdContainerResources:
description: ResourceRequirements describes the compute resource requirements.
properties:
Expand Down
5 changes: 5 additions & 0 deletions controllers/runner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
},
}

if dockerdInRunner {
pod.Spec.Containers[0].Command = []string{"startup.sh", fmt.Sprintf("--mtu %d", *runner.Spec.DockerMTU)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like to fail when DockerMTU is nil. Probably we'd better enclose this inside a if block?

Suggested change
pod.Spec.Containers[0].Command = []string{"startup.sh", fmt.Sprintf("--mtu %d", *runner.Spec.DockerMTU)}
if mtu := runner.Spec.DockerMTU; mtu != nil {
pod.Spec.Containers[0].Command = []string{"startup.sh", fmt.Sprintf("--mtu %d", *runner.Spec.DockerMTU)}
}

}

if !dockerdInRunner && dockerEnabled {
runnerVolumeName := "runner"
runnerVolumeMountPath := "/runner"
Expand Down Expand Up @@ -600,6 +604,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
MountPath: "/certs/client",
},
},
Args: []string{fmt.Sprintf("--mtu %d", *runner.Spec.DockerMTU)},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be easier to just set MTU via an envvar, not over --mtu flag?

Env: []corev1.EnvVar{
				{
					Name:  "MTU",
					Value: fmt.Sprintf("%d", *Zrunner.Spec.DockerMTU),
				},
			},

Env: []corev1.EnvVar{
{
Name: "DOCKER_TLS_CERTDIR",
Expand Down
23 changes: 23 additions & 0 deletions runner/startup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#!/bin/bash
source /opt/bash-utils/logger.sh

POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
-m|--mtu)
MTU="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters

function wait_for_process () {
local max_time_wait=30
local process_name="$1"
Expand Down Expand Up @@ -33,5 +52,9 @@ for process in "${processes[@]}"; do
fi
done

if [ -z "${MTU}" ]; then
ifconfig docker0 mtu ${MTU} up
fi

# Wait processes to be running
entrypoint.sh