-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This also creates a generic kubelet profile outside kubernetes, and much of kubernetes's kubelet resources have been replaced with this profile. It's not a complete rewrite, but it's a start. This should definitely be tested in a development environment before merging. On the way, this should also fix the naming collision between two different prometheus node exporter packages by pinning to a specific version.
- Loading branch information
Showing
8 changed files
with
228 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright (c) 2023 The Regents of the University of Michigan. | ||
# All Rights Reserved. Licensed according to the terms of the Revised | ||
# BSD License. See LICENSE.txt for details. | ||
class nebula::profile::kubelet ( | ||
String $kubelet_version, | ||
String $pod_manifest_path = "/etc/kubelet_manifests", | ||
Boolean $use_pod_manifest_path = true, | ||
) { | ||
include nebula::profile::networking::sysctl | ||
include nebula::profile::containerd | ||
include nebula::profile::kubernetes::apt | ||
|
||
kmod::load { "overlay": } | ||
kmod::load { "br_netfilter": } | ||
|
||
file { "/etc/sysctl.d/kubelet.conf": | ||
content => template("nebula/profile/kubernetes/kubelet_sysctl.conf.erb"), | ||
notify => Service["procps"], | ||
} | ||
|
||
package { "kubelet": | ||
ensure => $kubelet_version, | ||
require => Apt::Source["kubernetes"], | ||
} | ||
|
||
apt::pin { "kubelet": | ||
packages => ["kubelet"], | ||
version => $kubelet_version, | ||
} | ||
|
||
service { "kubelet": | ||
ensure => "running", | ||
enable => true, | ||
require => Package["kubelet"], | ||
} | ||
|
||
if $use_pod_manifest_path { | ||
file { "/etc/systemd/system/kubelet.service.d": | ||
ensure => "directory", | ||
} | ||
|
||
file { "/etc/systemd/system/kubelet.service.d/20-containerd-and-manifest-dir.conf": | ||
content => template("nebula/profile/kubelet/systemd.conf.erb"), | ||
require => Package["kubelet"], | ||
notify => Exec["kubelet reload daemon"], | ||
} | ||
|
||
exec { 'kubelet reload daemon': | ||
command => "/bin/systemctl daemon-reload", | ||
refreshonly => true, | ||
notify => Service["kubelet"], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2023 The Regents of the University of Michigan. | ||
# All Rights Reserved. Licensed according to the terms of the Revised | ||
# BSD License. See LICENSE.txt for details. | ||
require 'spec_helper' | ||
|
||
describe 'nebula::profile::kubelet' do | ||
on_supported_os.each do |os, os_facts| | ||
context "on #{os}" do | ||
let(:facts) { os_facts } | ||
let(:params) { { kubelet_version: "invalid-example-version" } } | ||
|
||
it { is_expected.to compile } | ||
|
||
# Prerequisites according to kubernetes documentation: | ||
# https://kubernetes.io/docs/setup/production-environment/container-runtimes/ | ||
it { is_expected.to contain_kmod__load("overlay") } | ||
it { is_expected.to contain_kmod__load("br_netfilter") } | ||
it { is_expected.to contain_file("/etc/sysctl.d/kubelet.conf").that_notifies("Service[procps]") } | ||
["net.bridge.bridge-nf-call-iptables", | ||
"net.bridge.bridge-nf-call-ip6tables", | ||
"net.ipv4.ip_forward"].each do |param| | ||
it do | ||
is_expected.to contain_file("/etc/sysctl.d/kubelet.conf") | ||
.with_content(/^#{param} *= *1$/) | ||
end | ||
end | ||
|
||
it { is_expected.to contain_service("containerd") } | ||
|
||
it do | ||
is_expected.to contain_apt__source("kubernetes") | ||
.with_location("https://apt.kubernetes.io/") | ||
.with_release("kubernetes-xenial") | ||
end | ||
|
||
it do | ||
is_expected.to contain_package("kubelet") | ||
.with_ensure("invalid-example-version") | ||
.that_requires("Apt::Source[kubernetes]") | ||
end | ||
|
||
it do | ||
is_expected.to contain_apt__pin("kubelet") | ||
.with_packages(["kubelet"]) | ||
.with_version("invalid-example-version") | ||
end | ||
|
||
it do | ||
is_expected.to contain_service("kubelet") | ||
.with_ensure("running") | ||
.with_enable(true) | ||
.that_requires("Package[kubelet]") | ||
end | ||
|
||
context "with kubelet_version set to 1.2.3-00" do | ||
let(:params) { { kubelet_version: "1.2.3-00" } } | ||
|
||
it { is_expected.to contain_package("kubelet").with_ensure("1.2.3-00") } | ||
it { is_expected.to contain_apt__pin("kubelet").with_version("1.2.3-00") } | ||
end | ||
|
||
it do | ||
is_expected.to contain_exec("kubelet reload daemon") | ||
.that_notifies("Service[kubelet]") | ||
.with_refreshonly(true) | ||
.with_command("/bin/systemctl daemon-reload") | ||
end | ||
|
||
it do | ||
is_expected.to contain_file("/etc/systemd/system/kubelet.service.d") | ||
.with_ensure("directory") | ||
end | ||
|
||
it do | ||
is_expected.to contain_file("/etc/systemd/system/kubelet.service.d/20-containerd-and-manifest-dir.conf") | ||
.that_requires("File[/etc/systemd/system/kubelet.service.d]") | ||
.that_requires("Package[kubelet]") | ||
.that_notifies("Exec[kubelet reload daemon]") | ||
end | ||
|
||
it do | ||
is_expected.to contain_file("/etc/systemd/system/kubelet.service.d/20-containerd-and-manifest-dir.conf") | ||
.with_content(/^Restart=always$/) | ||
end | ||
|
||
it do | ||
# This is important because we're using this file to override | ||
# the contents of the original systemd file. Without this empty | ||
# line, systemd might ignore our preferred ExecStart. | ||
is_expected.to contain_file("/etc/systemd/system/kubelet.service.d/20-containerd-and-manifest-dir.conf") | ||
.with_content(/^ExecStart=$/) | ||
end | ||
|
||
it do | ||
is_expected.to contain_file("/etc/systemd/system/kubelet.service.d/20-containerd-and-manifest-dir.conf") | ||
.with_content(/^ExecStart=\/usr\/bin\/kubelet/) | ||
end | ||
|
||
["--address=127.0.0.1", | ||
"--pod-manifest-path=/etc/kubelet_manifests", | ||
"--container-runtime=remote", | ||
"--container-runtime-endpoint=unix:///run/containerd/containerd.sock", | ||
"--cgroup-driver=systemd"].each do |param| | ||
it do | ||
is_expected.to contain_file("/etc/systemd/system/kubelet.service.d/20-containerd-and-manifest-dir.conf") | ||
.with_content(/^ExecStart=.+ #{param}/) | ||
end | ||
end | ||
|
||
context "with pod_manifest_path set to /tmp" do | ||
let(:params) { { kubelet_version: "123", pod_manifest_path: "/tmp" } } | ||
|
||
it do | ||
is_expected.to contain_file("/etc/systemd/system/kubelet.service.d/20-containerd-and-manifest-dir.conf") | ||
.with_content(/^ExecStart=.+ --pod-manifest-path=\/tmp/) | ||
end | ||
end | ||
|
||
context "with use_pod_manifest_path set to false" do | ||
let(:params) { { kubelet_version: "123", use_pod_manifest_path: false } } | ||
|
||
it { is_expected.not_to contain_file("/etc/systemd/system/kubelet.service.d") } | ||
it { is_expected.not_to contain_file("/etc/systemd/system/kubelet.service.d/20-containerd-and-manifest-dir.conf") } | ||
it { is_expected.not_to contain_exec("kubelet reload daemon") } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Managed by puppet (nebula/profile/kubelet/systemd.conf.erb) | ||
[Service] | ||
ExecStart= | ||
ExecStart=/usr/bin/kubelet --address=127.0.0.1 --pod-manifest-path=<%= @pod_manifest_path %> --cgroup-driver=systemd --container-runtime=remote --container-runtime-endpoint=unix:///run/containerd/containerd.sock | ||
Restart=always |