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

Enable templating within systemd unit files #351

Merged
merged 7 commits into from
Oct 1, 2024
Merged

Conversation

AverageMarcus
Copy link
Member

@AverageMarcus AverageMarcus commented Sep 27, 2024

What does this PR do?

Fixes giantswarm/roadmap#3691

  • Added support for Service section in custom systemd configuration
  • Added support for After, Requires, Wants and BindsTo within unit section of custom systemd configuration
  • Added support for passing Helm templating from provider chart values through to systemd unit templates

What is the effect of this change to users?

N/A - allows for additional configuration from cluster charts

How does it look like?

N/A

Any background context you can provide?

Required by cluster-cloud-director to allow the customer to provide some custom values that will get added to the ignition

What is needed from the reviewers?

Do the docs need to be updated?

Should this change be mentioned in the release notes?

  • CHANGELOG.md has been updated (if it exists)

@taylorbot
Copy link
Contributor

Hey @AverageMarcus, a test pull request has been created for you in the cluster-aws repo! Go to pull request giantswarm/cluster-aws#872 in order to test your cluster chart changes on AWS.

Signed-off-by: Marcus Noble <[email protected]>
Copy link
Member

@njuettner njuettner left a comment

Choose a reason for hiding this comment

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

LGTM if tested

Copy link
Member

@glitchcrab glitchcrab left a comment

Choose a reason for hiding this comment

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

i have no issues with this, so me likey

@glitchcrab
Copy link
Member

glitchcrab commented Sep 27, 2024

following up to my review, i thought of a helpful addition. as we're making an interface to systemd units here, it would be helpful to have Wants as an option in the [Unit] section please 🙏

edit - i've made these changes but I haven't pushed them yet

@glitchcrab
Copy link
Member

glitchcrab commented Sep 27, 2024

And a further thought - would it be possible to support multiple Unit ordering fields like we already do with WantedBy? e.g. we have some units which have multiple After dependencies

edit - i've made these changes but I haven't pushed them yet

@glitchcrab glitchcrab self-assigned this Sep 30, 2024
@glitchcrab glitchcrab force-pushed the extend-systemd-support branch 2 times, most recently from b156b89 to 511b4ed Compare September 30, 2024 15:00
@glitchcrab
Copy link
Member

this was tested with the following provider values:

global:
  connectivity:
    network:
      staticRoutes:
        - destination: 10.2.3.0/24
          via: 10.9.8.7
        - destination: 10.20.30.0/24
          via: 10.9.8.7

and the following systemd unit values:

                - contents:
                    install:
                      wantedBy:
                        - multi-user.target
                    service:
                      additionalFields: |-
                        ExecStart=/usr/bin/bash -cv 'echo "$("$(find /usr/bin /usr/share/oem -name vmtoolsd -type f -executable 2>/dev/null | head -n 1)" --cmd "info-get guestinfo.ignition.network")" > /opt/bin/set-networkd-units.sh'
                        ExecStart=/usr/bin/bash -cv 'chmod u+x /opt/bin/set-networkd-units.sh'
                        ExecStart=/opt/bin/set-networkd-units.sh
                        {{- if $.global.connectivity.network.staticRoutes }}
                        ExecStart=/usr/bin/bash -cv 'sleep 3'
                        {{- range $.global.connectivity.network.staticRoutes }}
                        ExecStart=/usr/bin/bash -cv 'ip route add {{ .destination }} via {{ .via }}'
                        {{- end }}
                        {{- end }}
                      remainAfterExit: "yes"
                      type: oneshot
                    unit:
                      after:
                        - set-hostname.service
                      description: Install the systemd-networkd unit files and add static routes
                      requires:
                        - coreos-metadata.service

which produced the following unit:

                - name: set-networkd-units.service
                  enabled: true
                  contents: |
                    [Unit]
                    Description=Install the systemd-networkd unit files and add static routes
                    After=set-hostname.service
                    Requires=coreos-metadata.service
                    [Service]
                    Type=oneshot
                    RemainAfterExit=yes

                    ExecStart=/usr/bin/bash -cv 'echo "$("$(find /usr/bin /usr/share/oem -name vmtoolsd -type f -executable 2>/dev/null | head -n 1)" --cmd "info-get guestinfo.ignition.network")" > /opt/bin/set-networkd-units.sh'
                    ExecStart=/usr/bin/bash -cv 'chmod u+x /opt/bin/set-networkd-units.sh'
                    ExecStart=/opt/bin/set-networkd-units.sh
                    ExecStart=/usr/bin/bash -cv 'sleep 3'
                    ExecStart=/usr/bin/bash -cv 'ip route add 10.2.3.0/24 via 10.9.8.7'
                    ExecStart=/usr/bin/bash -cv 'ip route add 10.20.30.0/24 via 10.9.8.7'
                    [Install]
                    WantedBy=multi-user.target

Copy link
Member Author

@AverageMarcus AverageMarcus left a comment

Choose a reason for hiding this comment

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

This is beautiful! 😍 (I can't approve it though as I opened the PR 🤦 )

@Gacko Mind giving this work of art a little ✅ ?

Copy link

github-actions bot commented Oct 1, 2024

There were no differences in the rendered Helm template.

Output
=== Differences when rendered with values file helm/cluster/ci/test-required-values.yaml ===

No difference


=== Differences when rendered with values file helm/cluster/ci/test-zot-mc-and-local-values.yaml ===

No difference


=== Differences when rendered with values file helm/cluster/ci/test-zot-mc-values.yaml ===

No difference


=== Differences when rendered with values file helm/cluster/ci/test-zot-only-local-values.yaml ===

No difference


=== No differences at all ===

@glitchcrab glitchcrab requested a review from Gacko October 1, 2024 09:13
Copy link
Member

@Gacko Gacko left a comment

Choose a reason for hiding this comment

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

LGTM!

@glitchcrab glitchcrab merged commit 0809adf into main Oct 1, 2024
16 checks passed
@glitchcrab glitchcrab deleted the extend-systemd-support branch October 1, 2024 09:30
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.

cluster chart: enable templating in systemd unit files
6 participants