Skip to content

Commit

Permalink
Split actionable code from parameter definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ananace committed Sep 24, 2024
1 parent d17cd6a commit 66bbb18
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 179 deletions.
27 changes: 16 additions & 11 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Classes

* [`k8s`](#k8s): Sets up a Kubernetes instance - either as a node or as a server
* [`k8s::common`](#k8s--common): Sets up common Kubernetes components - users/groups/folders/etc
* [`k8s::install::cni_plugins`](#k8s--install--cni_plugins): Manages the installation of CNI plugins
* [`k8s::install::container_runtime`](#k8s--install--container_runtime): Manages the installation of a container runtime / CRI
* [`k8s::install::crictl`](#k8s--install--crictl): installs the crictl debugging tool
Expand Down Expand Up @@ -429,7 +430,7 @@ Default value: `true`

##### <a name="-k8s--role"></a>`role`

Data type: `Enum['node','server','none']`
Data type: `Enum['node','server','etcd-replica','none']`

role of the node

Expand Down Expand Up @@ -491,6 +492,10 @@ version of kubernetes to install

Default value: `'1.28.14'`

### <a name="k8s--common"></a>`k8s::common`

Sets up common Kubernetes components - users/groups/folders/etc

### <a name="k8s--install--cni_plugins"></a>`k8s::install::cni_plugins`

Manages the installation of CNI plugins
Expand Down Expand Up @@ -2072,11 +2077,11 @@ Default value: `'etcd'`

##### <a name="-k8s--server--etcd--version"></a>`version`

Data type: `Optional[String[1]]`
Data type: `String[1]`

version of ectd to install, will use k8s::etcd_version unless otherwise specified

Default value: `undef`
Default value: `$k8s::etcd_version`

### <a name="k8s--server--etcd--setup"></a>`k8s::server::etcd::setup`

Expand Down Expand Up @@ -2186,11 +2191,11 @@ Default value: `"${etcd_name}.etcd"`

##### <a name="-k8s--server--etcd--setup--ensure"></a>`ensure`

Data type: `Optional[K8s::Ensure]`
Data type: `K8s::Ensure`

set ensure for installation or deinstallation

Default value: `undef`
Default value: `'present'`

##### <a name="-k8s--server--etcd--setup--etcd_name"></a>`etcd_name`

Expand Down Expand Up @@ -2218,11 +2223,11 @@ Default value: `undef`

##### <a name="-k8s--server--etcd--setup--group"></a>`group`

Data type: `Optional[String[1]]`
Data type: `String[1]`

etcd system user group

Default value: `undef`
Default value: `'etcd'`

##### <a name="-k8s--server--etcd--setup--initial_advertise_peer_urls"></a>`initial_advertise_peer_urls`

Expand Down Expand Up @@ -2370,19 +2375,19 @@ Default value: `undef`

##### <a name="-k8s--server--etcd--setup--user"></a>`user`

Data type: `Optional[String[1]]`
Data type: `String[1]`

etcd system user

Default value: `undef`
Default value: `'etcd'`

##### <a name="-k8s--server--etcd--setup--version"></a>`version`

Data type: `Optional[String[1]]`
Data type: `String[1]`

The ectd version to install

Default value: `undef`
Default value: `$k8s::etcd_version`

### <a name="k8s--server--resources"></a>`k8s::server::resources`

Expand Down
3 changes: 2 additions & 1 deletion data/common.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--- {}
---
k8s::sysconfig_path: '/etc/sysconfig'
71 changes: 71 additions & 0 deletions manifests/common.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# @summary Sets up common Kubernetes components - users/groups/folders/etc
class k8s::common {
group { $k8s::group:
ensure => present,
system => true,
gid => $k8s::gid,
}

user { $k8s::user:
ensure => present,
comment => 'Kubernetes user',
gid => $k8s::group,
home => '/srv/kubernetes',
managehome => false,
shell => (fact('os.family') ? {
'Debian' => '/usr/sbin/nologin',
default => '/sbin/nologin',
}),
system => true,
uid => $k8s::uid,
}

file {
default:
ensure => directory,
force => true,
purge => true,
recurse => true;

'/opt/k8s': ;
'/opt/k8s/bin': ;
}

file { '/var/run/kubernetes':
ensure => directory,
owner => $k8s::user,
group => $k8s::group,
}

file { "${k8s::sysconfig_path}/kube-common":
ensure => file,
content => epp('k8s/sysconfig.epp', {
comment => 'General Kubernetes Configuration',
environment_variables => {
'KUBE_LOG_LEVEL' => '',
},
}),
}

file {
default:
ensure => directory;

'/etc/kubernetes': ;
'/etc/kubernetes/certs': ;
'/etc/kubernetes/manifests':
purge => $k8s::purge_manifests,
recurse => true;
'/root/.kube': ;
'/srv/kubernetes':
owner => $k8s::user,
group => $k8s::group;
'/usr/libexec/kubernetes': ;
'/var/lib/kubelet': ;
'/var/lib/kubelet/pki': ;

'/usr/share/containers/': ;
'/usr/share/containers/oci/': ;
'/usr/share/containers/oci/hooks.d': ;
}
}
97 changes: 3 additions & 94 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -95,110 +95,19 @@
Stdlib::Fqdn $cluster_domain = 'cluster.local',
String[1] $etcd_cluster_name = 'default',

Enum['node','server','none'] $role = 'none',
Enum['node','server','etcd-replica','none'] $role = 'none',
Optional[K8s::Firewall] $firewall_type = undef,

String[1] $user = 'kube',
String[1] $group = 'kube',
Integer[0, 65535] $uid = 888,
Integer[0, 65535] $gid = 888,
) {
if $manage_container_manager {
include k8s::install::container_runtime
}

group { $group:
ensure => present,
system => true,
gid => $gid,
}

user { $user:
ensure => present,
comment => 'Kubernetes user',
gid => $group,
home => '/srv/kubernetes',
managehome => false,
shell => (fact('os.family') ? {
'Debian' => '/usr/sbin/nologin',
default => '/sbin/nologin',
}),
system => true,
uid => $uid,
}

file {
default:
ensure => directory,
force => true,
purge => true,
recurse => true;

'/opt/k8s': ;
'/opt/k8s/bin': ;
}

file { '/var/run/kubernetes':
ensure => directory,
owner => $user,
group => $group,
}

$_sysconfig_path = pick($sysconfig_path, '/etc/sysconfig')
file { "${_sysconfig_path}/kube-common":
ensure => file,
content => epp('k8s/sysconfig.epp', {
comment => 'General Kubernetes Configuration',
environment_variables => {
'KUBE_LOG_LEVEL' => '',
},
}),
}

file {
default:
ensure => directory;

'/etc/kubernetes': ;
'/etc/kubernetes/certs': ;
'/etc/kubernetes/manifests':
purge => $purge_manifests,
recurse => true;
'/root/.kube': ;
'/srv/kubernetes':
owner => $user,
group => $group;
'/usr/libexec/kubernetes': ;
'/var/lib/kubelet': ;
'/var/lib/kubelet/pki': ;

'/usr/share/containers/': ;
'/usr/share/containers/oci/': ;
'/usr/share/containers/oci/hooks.d': ;
}

if $manage_repo {
include k8s::repo
}

if $manage_packages {
# Ensure conntrack is installed to properly handle networking cleanup
if fact('os.family') == 'Debian' {
$_conntrack = 'conntrack'
} else {
$_conntrack = 'conntrack-tools'
}

ensure_packages([$_conntrack,])
}

if $role != 'none' {
include k8s::install::cni_plugins
}

if $role == 'server' {
include k8s::server
} elsif $role == 'node' {
include k8s::node
} elsif $role == 'etcd-replica' {
include k8s::server::etcd
}
}
1 change: 1 addition & 0 deletions manifests/install/container_runtime.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
}

if $manage_repo {
include k8s::repo
Class['k8s::repo'] -> Package['k8s container manager']
}
}
3 changes: 2 additions & 1 deletion manifests/install/crictl.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
Stdlib::HTTPUrl $download_url_template = 'https://github.com/kubernetes-sigs/cri-tools/releases/download/%{version}/crictl-%{version}-linux-%{arch}.tar.gz',
) {
if $manage_repo {
$pkg = pick($crictl_package, 'cri-tools')
include k8s::repo

$pkg = pick($crictl_package, 'cri-tools')
package { $pkg:
ensure => stdlib::ensure($ensure, 'package'),
}
Expand Down
20 changes: 20 additions & 0 deletions manifests/node.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@

Optional[K8s::Firewall] $firewall_type = $k8s::firewall_type,
) {
include k8s::common
include k8s::install::cni_plugins

if $k8s::manage_container_manager {
include k8s::install::container_runtime
}
if $k8s::manage_repo {
include k8s::repo
}
if $k8s::manage_packages {
# Ensure conntrack is installed to properly handle networking cleanup
if fact('os.family') == 'Debian' {
$_conntrack = 'conntrack'
} else {
$_conntrack = 'conntrack-tools'
}

ensure_packages([$_conntrack,])
}

if $manage_crictl {
include k8s::install::crictl
}
Expand Down
2 changes: 2 additions & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
Optional[K8s::Firewall] $firewall_type = $k8s::firewall_type,
String[1] $etcd_cluster_name = $k8s::etcd_cluster_name,
) {
include k8s::common

if $manage_etcd {
class { 'k8s::server::etcd':
ensure => $ensure,
Expand Down
Loading

0 comments on commit 66bbb18

Please sign in to comment.