-
Notifications
You must be signed in to change notification settings - Fork 33
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
Garden Linux OS configuration from shoot manifest #63
Conversation
* introduces API types to OperatingSystemConfiguration to * configure cgroup version in Garden Linux * configure the Linux Security Module (LSM) in Garden Linux * deploys appropriate scripts into Garden Linux that reconfigure the settings given above and places systemd units to make them start before the kubelet comes up * deploys a script that can reboot the system if a configuration script requires it (and will do nothing if it detects a running kubelet) * places systemd unit drop-ins that will change the configuration files of containerd and kubelet (before they get started) to make them use systemd as cgroup driver on cgroup v2 enabled systems
/invite @vpnachev |
function get_fs_of_directory { | ||
[ -z "$1" -o ! -d "$1" ] && return | ||
echo -n "$(stat -c %T -f "$1")" | ||
} | ||
|
||
function check_current_cgroup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible these functions to be moved to a library alike script which is sourced here and in the other scripts where they are used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I moved these functions which were present in three different scripts into a separate file g_functions.sh
which is then sourced by the other scripts. Makes total sense to avoid this kind of code duplication.
|
||
{{- if not .Bootstrap }} | ||
{{- range $_, $unitname := .AdditionalValues.unitsToEnable }} | ||
systemctl enable {{ $unitname }} && systemctl restart {{ $unitname }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already done here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only for units which are in extensionsv1alpha1.OperatingSystemConfig
, but I am adding these units to generator.OperatingSystemConfig
before feeding it into the cloud-init generator and units added here are not covered by the code you linked to.
pkg/generator/gardenlinux/cgroups.go
Outdated
return nil, err | ||
} | ||
|
||
shootKubernetesAtLeast119, err := version.CompareVersions(shoot.Spec.Kubernetes.Version, ">=", "1.19") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you will need to check also the k8s version of the worker pool as it could differ from the control plane k8s version, ref: https://github.com/gardener/gardener/blob/master/docs/usage/worker_pool_k8s_versions.md
The worker pool name is set in a label in the OSC resource (ref: gardener/gardener#5256), so you should be able to easily find the worker config for the given operatingSystemConfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gardener/gardener-maintainers what do you think about deprecating and removing support for k8s <=1.18 for shoot cluster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you will need to check also the k8s version of the worker pool as it could differ from the control plane k8s version, ref: https://github.com/gardener/gardener/blob/master/docs/usage/worker_pool_k8s_versions.md
The worker pool name is set in a label in the OSC resource (ref: gardener/gardener#5256), so you should be able to easily find the worker config for the given operatingSystemConfig.
That has been taken care of.
07e269d
to
30628c7
Compare
I have some comments on the cgroupsv2 story: Cgroupsv2 is clearly the way forward and is gradually replacing cgroupsv1. Support for cgroupsv2 in K8s was introduced as alpha almost 2 years ago and is up for beta graduation next. What would be better from my POV: Ideally: build cgroupsv1 and cgroupsv2 versions of Gardenlinux so that no restart is required. Offer both versions in the Cloudprofile.
Advantage:
Also supporting the migration of an existing node from cgroupvs1 to cgroupsv2 does not seem to be necessary. It should be simpler to just force new node rollouts when switching to cgroupsv2. If different Gardenlinux OS versions are not wanted: reverse the approach: using cgroupsv1 instead of cgroupsv2 is possible but requires a restart |
I think it is too much overhead to do this, especially now when k8s 1.18 is out of maintenance since long time. Such temporary enhancement of the cloudprofile API could be easily avoided by simply dropping support for shoots with k8s < 1.19. |
Are you implying to only build and use cgroupsv2 images for Shoots > 1.18 - |
Thanks for the explanation. It sounds better with the prospect of getting rid of the restart eventually.
I think only if this configuration is OS-specific - which is probably not the case.
WDYT in general about a set of attributes (map[string]string) in the Cloudprofile for each image version? This allows for better validation for features that rely on OS image pre-installed binaries/configuration
On top of validation, it can be used for any kind of decision that has to be made based on binary versions installed on the OS (such as the ones we see in this PR). |
5a78f2b
to
6add263
Compare
6add263
to
fd8a9fa
Compare
This works only for really immutable distributions, for example Ubuntu installs containerd and docker on start-up, ref. Maintaining such information will be cumbersome. I think the current approach checking configs and package versions directly on the node is the better approach. |
I would be in line with @vpnachev. It creates the additional burden of maintaining these values and can create a lot of confusion should a mistake occur. I think it should be preferred obtaining any of these values from the OS itself as it does not involve constant maintenance effort and reduces the possibility for error. |
fd8a9fa
to
f93febb
Compare
Could someone ptal after I incorporated the review feedback? |
|
||
// LinuxSecurityModule allows to configure default Linux Security Module for Garden Linux. | ||
// +optional | ||
LinuxSecurityModule LinuxSecurityModule `json:"linuxSecurityModule,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional APIs have pointer types. Same below.
If it is non-optional then remove // +optional
and omitempty
tags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intended them to be optional and changed them to pointers. PTAL.
It would be cool, if the review of this PR could continue. We would like to deliver the next Garden Linux release with cgroup v2 enabled by default and without these changes, we would break the compatibility with any K8S cluster |
After some offline discussion it became apparent that changing between cgroup v1 and v2 from the Shoot manifest or as dependency from the Kubernetes version used might become irrelevant in the future as Kubernetes versions without cgroup v2 support (i.e. |
update alpine base image to 3.15.4
How to categorize this PR?
/area os
/kind api-change
/kind enhancement
/os garden-linux
What this PR does / why we need it:
Garden Linux runs with AppArmor as a default Linux Security Module (lsm). While some K8S workloads require AppArmor to be present on the worker nodes, some other workloads might require SELinux. It therefore should be possible to configure the LSM to be used on worker nodes within the Shoot manifest when creating a cluster.
Likewise, Garden Linux so far runs with systemd and the (old) non-unified cgroup hierarchy, aka cgroup v1. Some users might want to use cgroup v2 instead which requires reconfiguring the operating system and switching containerd and the kubelet to use
systemd
as a cgroup driver.With this PR, the Garden Linux OS extension will be able to understand the following provider configuration:
This allows configuring the
linuxSecurityModule
and thecgroupVersion
within the Shoot manifest. The extension will place shell scripts that will take care of configuring these settings on a Garden Linux node into/opt/bin/gardener
and will deploy systemd units that will run these scripts as one-shot during system boot before the kubelet comes up.Changing these settings unfortunately requires a reboot. If any of the configuration scripts finds out that the desired setting is different from the current setting, it will place the file
/var/run/gardener/restart-required
. Another script that gets deployed by the extension (along with another systemd unit that will start it) will check if this file is present and will reboot the system but only if the kubelet is found not to be running.Changing the cgroup version to
v2
will be prevented for Shoots with Kubernetes version<1.19
,v1
will be enforced on such systems.Which issue(s) this PR fixes:
It does not entirely fix them but it lays the groundworks to get rid of #47, #50 and Garden Linux #310.
Special notes for your reviewer:
An admission controller that will check for valid inputs to the configuration settings will follow in a separate PR to keep this PR reasonable in size.
Release note: