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

feat: Map hostmount volumes through to config.toml #12

Conversation

chickenandpork
Copy link
Contributor

@chickenandpork chickenandpork commented Nov 2, 2022

This PR allows the gitlab-runner to have host paths mapped through to the container as runners.kubernetes.volumes.host_path blocks.

For example, I wanted Datadog UDS (/var/run/datadog/dsd.socket) to report metrics:

  ...

  build_job_hostmounts = {
    dogstatsd = { host_path = "/var/run/datadog" }
  }

  ...

This of course creates the config.toml section, with intentionally the same path:

 [[runners.kubernetes.volumes.host_path]]
        name = "dogstatsd"
        mount_path = "/var/run/datadog"
        host_path = "/var/run/datadog"
        read_only = false

Of course this is https://docs.gitlab.com/runner/executors/kubernetes.html#host-path-volumes in the docs.

@chickenandpork
Copy link
Contributor Author

@MeNsaaH can I ask approval to begin the workflows to pre-qualify this PR?

This is the first of three PRs I'd like to submit to extend the coverage of TF over the runner config if you're willing to accept them. Thanks!

config.tf Outdated
%{~for name, config in var.build_job_hostmounts~}
[[runners.kubernetes.volumes.host_path]]
name = "${name}"
mount_path = "${config.path}"
Copy link
Contributor

Choose a reason for hiding this comment

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

@chickenandpork I'm thinking of cases where someone wants to mount a host path to a different path in the container. Would it be better to make this config.container_path and config.host_path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that makes sense and is quick to add

@@ -105,6 +105,11 @@ variable "local_cache_dir" {
description = "Path on nodes for caching"
}

variable "build_job_hostmounts" {
description = "A map of name:path for which each named path will cause the host path to be mounted at the identical mountpoint in the build container."
default = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

THis should be a list of maps

Copy link
Contributor

Choose a reason for hiding this comment

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

@chickenandpork
this should be

default = []
type = list(map(any))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intent was to allow the key become the name of the map; this gives a somewhat trivial self-documenting of which rule creates a given hostmount (in case it's not obvious) and -- for me -- allows tying back a config piece to a related feature or function (in my example, "dogstatsd" is the key, and the host mount is used to host mount to get access to the dogstatsd Unix Domain Socket)

If optional types were permitted, I'd use this:

variable "build_job_hostmounts" {
  ...
  default     = {}
  type = map(object({
     host_path      = string
     container_path = optional(string)
     read_only      = optional(bool)
  }))
}

This allows me to write:

  build_job_hostmounts = {
    dogstatsd = {
      host_path = "/var/run/datadog"
    },
    some_other_mount = {
      host_path = "/some/path"
      container_path = "/other/path"
      read_only = true
    },
  }

The dogstatsd appears in the config.toml as:

                          [[runners.kubernetes.volumes.host_path]]
                            name = "dogstatsd"
                            mount_path = "/var/run/datadog"
                            host_path = "/var/run/datadog"
                            read_only = false

Copy link
Contributor

Choose a reason for hiding this comment

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

that makes more sense. But optional vars I think were added 0.14; so we cannot use that. In that case, add an example in the README of using this and also we'll have to make the description as explanatory as possible.

The description says list, but ideally should be a map of maps. We could set the type as:

type = map(map(string))

although, I'm not sure if that'll work.

@chickenandpork
Copy link
Contributor Author

chickenandpork commented Nov 8, 2022

Hi @MeNsaaH; thanks again for taking a look. Based on your suggestions,I have :

  • split the host/container paths
  • (defaulted the container_path to the host_path if it's not given)
  • fixed the documentation (and added a bit), and
  • regenerated the README.md for the doc change

Copy link
Contributor

@MeNsaaH MeNsaaH left a comment

Choose a reason for hiding this comment

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

Can you also rebase your branch from master. I fixed the CI

@@ -105,6 +105,11 @@ variable "local_cache_dir" {
description = "Path on nodes for caching"
}

variable "build_job_hostmounts" {
description = "A map of name:path for which each named path will cause the host path to be mounted at the identical mountpoint in the build container."
default = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

@chickenandpork
this should be

default = []
type = list(map(any))

@MeNsaaH MeNsaaH changed the title Map hostmount volumes through to config.toml feat: Map hostmount volumes through to config.toml Nov 8, 2022
@MeNsaaH
Copy link
Contributor

MeNsaaH commented Nov 9, 2022

CI for fmt is failing. Do you have precommit installed as defined here?

@chickenandpork
Copy link
Contributor Author

CI for fmt is failing. Do you have precommit installed as defined here?

Yes, but the version of https://github.com/antonbabenko/pre-commit-terraform isn't compatible with an unmodified MacOS (realpath doesn't exist in shell nor path). I was running terraform fit manually. I use pre-commit aggressively in my daily workflows.

I notice that the updated pre-commit-terraform works fine; I cut a PR for that to keep on-change-per-PR at #14

@chickenandpork chickenandpork force-pushed the 20220707-map-hostmount-volumes-for-great-justice branch from e0f4964 to a28c0d8 Compare November 10, 2022 07:33
@chickenandpork chickenandpork force-pushed the 20220707-map-hostmount-volumes-for-great-justice branch from a28c0d8 to 939fb63 Compare November 10, 2022 07:35
Copy link
Contributor

@MeNsaaH MeNsaaH left a comment

Choose a reason for hiding this comment

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

LGTM

@MeNsaaH MeNsaaH merged commit 8641b32 into DeimosCloud:master Nov 10, 2022
@MeNsaaH
Copy link
Contributor

MeNsaaH commented Nov 10, 2022

@chickenandpork thank you for you contribution

MeNsaaH pushed a commit that referenced this pull request Nov 10, 2022
## [1.5.0](v1.4.0...v1.5.0) (2022-11-10)

### Features

* Map hostmount volumes through to config.toml ([#12](#12)) ([8641b32](8641b32))
@MeNsaaH
Copy link
Contributor

MeNsaaH commented Nov 10, 2022

This PR is included in version 1.5.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants