Skip to content

Commit

Permalink
Correctly handle undef name/discovery tag for etcd
Browse files Browse the repository at this point in the history
  • Loading branch information
ananace committed Jan 16, 2025
1 parent d416a02 commit ca785f0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1292,11 +1292,11 @@ Default value: `"${cert_path}/client-ca.key"`

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

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

name of the etcd cluster for searching its nodes in the puppetdb, will use k8s::etcd_cluster_name unless otherwise specified

Default value: `undef`
Default value: `'default'`

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

Expand Down
9 changes: 6 additions & 3 deletions manifests/server/apiserver.pp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@
' resources {',
' type = \'Class\' and',
' title = \'K8s::Server::Etcd\' and',
" parameters.cluster_name = '${etcd_cluster_name}' and",
" parameters.puppetdb_discovery_tag = '${puppetdb_discovery_tag}'",
($puppetdb_discovery_tag ? {
undef => undef,
default => " parameters.puppetdb_discovery_tag = '${puppetdb_discovery_tag}' and",
}),
" parameters.cluster_name = '${etcd_cluster_name}'",
' }',
' }',
' order by certname',
'}',
].join(' ')
].delete_undef_values().join(' ')

$cluster_nodes = puppetdb_query($pql_query)
$_discovery = {
Expand Down
14 changes: 7 additions & 7 deletions manifests/server/etcd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Boolean $manage_setup = true,
Boolean $manage_firewall = false,
Boolean $manage_members = false,
Optional[String[1]] $cluster_name = undef,
String[1] $cluster_name = 'default',
Optional[String[1]] $puppetdb_discovery_tag = $cluster_name,

Boolean $self_signed_tls = false,
Expand Down Expand Up @@ -119,9 +119,6 @@
}

if $ensure == 'present' and $manage_members {
$_cluster_name = pick($cluster_name, $k8s::etcd_cluster_name, 'default')
$_puppetdb_discovery_tag = pick($puppetdb_discovery_tag, $cluster_name, $k8s::puppetdb_discovery_tag, 'default')

# Needs the PuppetDB terminus installed
$pql_query = [
'resources[certname,parameters] {',
Expand All @@ -131,13 +128,16 @@
' resources {',
' type = \'Class\' and',
' title = \'K8s::Server::Etcd\' and',
" parameters.cluster_name = '${_cluster_name}' and",
" parameters.puppetdb_discovery_tag = '${_puppetdb_discovery_tag}' and",
" parameters.cluster_name = '${cluster_name}' and",
($puppetdb_discovery_tag ? {
undef => undef,
default => " parameters.puppetdb_discovery_tag = '${puppetdb_discovery_tag}' and",
}),
" certname != '${trusted[certname]}'",
' }',
' }',
' order by certname }',
].join(' ')
].delete_undef_values().join(' ')

$cluster_nodes = puppetdb_query($pql_query)
$_setup_splat = {
Expand Down

0 comments on commit ca785f0

Please sign in to comment.