Add support for [cluster] parameters and [cluster_template] parameters

This change introduces support managing parameters in the following
two sections.
 - [cluster]
 - [cluster_template]

Note that parameters for swarm and mesos are intentionally excluded
from this change, because mesos support is being deprecated and usage
of swarm would be not so popular as kubernetes these days.

Change-Id: I41ebc97d67eee5e5543bb48d878802e7777c47a8
This commit is contained in:
Takashi Kajinami 2021-12-17 13:22:57 +09:00
parent b3f2138647
commit 344a27abf7
5 changed files with 154 additions and 0 deletions

40
manifests/cluster.pp Normal file
View File

@ -0,0 +1,40 @@
# == Class: magnum::cluster
#
# Setup magnum cluster.
#
# === Parameters
#
# [*etcd_discovery_service_endpoint_format*]
# (optional) Url for etcd public discovery endpoint.
# Defaults to $::os_service_default
#
# [*nodes_affinity_policy*]
# (optional) Affinity policy for server group of cluster nodes.
# Defaults to $::os_service_default
#
# [*temp_cache_dir*]
# (optional) Explicitly specify the temporary directory to hold cached TLS
# certs.
# Defaults to $::os_service_default
#
# [*pre_delete_lb_timeout*]
# (optional) The timeout in seconds to wait for the load balancers to be
# deleted.
# Defaults to $::os_service_default
#
class magnum::cluster (
$etcd_discovery_service_endpoint_format = $::os_service_default,
$nodes_affinity_policy = $::os_service_default,
$temp_cache_dir = $::os_service_default,
$pre_delete_lb_timeout = $::os_service_default,
) {
include magnum::deps
magnum_config {
'cluster/etcd_discovery_service_endpoint_format': value => $etcd_discovery_service_endpoint_format;
'cluster/nodes_affinity_policy': value => $nodes_affinity_policy;
'cluster/temp_cache_dir': value => $temp_cache_dir;
'cluster/pre_delete_lb_timeout': value => $pre_delete_lb_timeout;
}
}

View File

@ -0,0 +1,26 @@
# == Class: magnum::cluster_template
#
# Setup magnum cluster_template.
#
# === Parameters
#
# [*kubernetes_allowed_network_drivers*]
# (optional) Allowed network drivers for kubernetes cluster-templates.
# Defaults to $::os_service_default
#
# [*kubernetes_default_network_driver*]
# (optional) Default network driver for kubernetes.
# Defaults to $::os_service_default
#
class magnum::cluster_template (
$kubernetes_allowed_network_drivers = $::os_service_default,
$kubernetes_default_network_driver = $::os_service_default,
) {
include magnum::deps
magnum_config {
'cluster_template/kubernetes_allowed_network_drivers': value => join(any2array($kubernetes_allowed_network_drivers), ',');
'cluster_template/kubernetes_default_network_driver': value => $kubernetes_default_network_driver;
}
}

View File

@ -0,0 +1,7 @@
---
features:
- |
The following two classes have been added.
- ``magnum::cluster``
- ``magnum::cluster_template``

View File

@ -0,0 +1,44 @@
require 'spec_helper'
describe 'magnum::cluster' do
shared_examples 'magnum::cluster' do
it 'contains default values' do
is_expected.to contain_magnum_config('cluster/etcd_discovery_service_endpoint_format').with_value('<SERVICE DEFAULT>')
is_expected.to contain_magnum_config('cluster/nodes_affinity_policy').with_value('<SERVICE DEFAULT>')
is_expected.to contain_magnum_config('cluster/temp_cache_dir').with_value('<SERVICE DEFAULT>')
is_expected.to contain_magnum_config('cluster/pre_delete_lb_timeout').with_value('<SERVICE DEFAULT>')
end
context 'configure cluster with parameters' do
let :params do
{
:etcd_discovery_service_endpoint_format => 'https://discovery.etcd.io/new?size=%(size)d',
:nodes_affinity_policy => 'soft-anti-affinity',
:temp_cache_dir => '/var/lib/magnum/certificate-cache',
:pre_delete_lb_timeout => 60,
}
end
it 'contains overrided values' do
is_expected.to contain_magnum_config('cluster/etcd_discovery_service_endpoint_format').with_value('https://discovery.etcd.io/new?size=%(size)d')
is_expected.to contain_magnum_config('cluster/nodes_affinity_policy').with_value('soft-anti-affinity')
is_expected.to contain_magnum_config('cluster/temp_cache_dir').with_value('/var/lib/magnum/certificate-cache')
is_expected.to contain_magnum_config('cluster/pre_delete_lb_timeout').with_value(60)
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts({}))
end
it_behaves_like 'magnum::cluster'
end
end
end

View File

@ -0,0 +1,37 @@
require 'spec_helper'
describe 'magnum::cluster_template' do
shared_examples 'magnum::cluster_template' do
it 'contains default values' do
is_expected.to contain_magnum_config('cluster_template/kubernetes_allowed_network_drivers').with_value('<SERVICE DEFAULT>')
is_expected.to contain_magnum_config('cluster_template/kubernetes_default_network_driver').with_value('<SERVICE DEFAULT>')
end
context 'configure cluster_template with parameters' do
let :params do
{
:kubernetes_allowed_network_drivers => ['all'],
:kubernetes_default_network_driver => 'flannel',
}
end
it 'contains overrided values' do
is_expected.to contain_magnum_config('cluster_template/kubernetes_allowed_network_drivers').with_value('all')
is_expected.to contain_magnum_config('cluster_template/kubernetes_default_network_driver').with_value('flannel')
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts({}))
end
it_behaves_like 'magnum::cluster_template'
end
end
end