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 Jul 14, 2023
1 parent b174ec9 commit 4cfbda3
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 183 deletions.
31 changes: 20 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 the cni plugins
* [`k8s::install::container_runtime`](#k8s--install--container_runtime): manages the installation of cri
* [`k8s::install::crictl`](#k8s--install--crictl): installs the crictl debugging tool
Expand Down Expand Up @@ -218,12 +219,16 @@ Data type: `String[1]`



Default value: `'1.26.1'`

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

Data type: `String[1]`



Default value: `'3.5.1'`

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

Data type: `K8s::Native_packaging`
Expand Down Expand Up @@ -474,7 +479,7 @@ Default value: `'cluster.local'`

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

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



Expand All @@ -488,6 +493,10 @@ Data type: `Optional[K8s::Firewall]`

Default value: `undef`

### <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`

Class: k8s::install::cni_plugins
Expand Down Expand Up @@ -2053,11 +2062,11 @@ Default value: `false`

##### <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--user"></a>`user`

Expand Down Expand Up @@ -2183,11 +2192,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 @@ -2215,11 +2224,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 @@ -2367,19 +2376,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: 1 addition & 2 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
---
k8s::version: 1.26.1
k8s::etcd_version: 3.5.1
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': ;
}
}
102 changes: 5 additions & 97 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
# @param etcd_cluster_name name of the etcd cluster for searching its nodes in the puppetdb
#
class k8s (
# Stored in Hiera data
String[1] $version,
String[1] $etcd_version,
String[1] $version = '1.26.1',
String[1] $etcd_version = '3.5.1',

K8s::Ensure $ensure = 'present',
Enum['container', 'native'] $packaging = 'native',
Expand Down Expand Up @@ -69,110 +68,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 @@ -89,6 +89,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 @@ -23,8 +23,9 @@
Stdlib::HTTPUrl $download_url = "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 @@ -53,6 +53,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 @@ -60,6 +60,8 @@
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 4cfbda3

Please sign in to comment.