Skip to content

Commit

Permalink
Avoid unnecessary changes associated with Helm v2 when doing Helm v3
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Jan 14, 2021
1 parent e006602 commit 8a87cba
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 84 deletions.
4 changes: 0 additions & 4 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
Boolean $tiller_tls_verify = $helm::tiller_tls_verify,
Optional[String] $tls_ca_cert = $helm::tls_ca_cert,
Boolean $upgrade = $helm::upgrade,
Optional[String] $version = $helm::version,
Optional[String] $install_path = $helm::install_path,
){

$tiller_namespaces.each |$ns| {
Expand Down Expand Up @@ -58,8 +56,6 @@
tiller_tls_key => $tiller_tls_key,
tls_ca_cert => $tls_ca_cert,
upgrade => $upgrade,
version => $version,
install_path => $install_path,
}
}
}
105 changes: 45 additions & 60 deletions manifests/helm_init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,7 @@
# @param upgrade
# Specifies whether to upgrade if Tiller is installed.
# Valid values are `true`, `false`.
#
# @param version
# Specifies the version to install
# default is 2.7.2
#
# @param install_path
# Specifies the install_path of helm executable
# default to '/usr/bin'
#
#
define helm::helm_init (
Boolean $init = true,
Boolean $canary_image = false,
Expand All @@ -118,66 +110,59 @@
Boolean $tiller_tls_verify = false,
Optional[String] $tls_ca_cert = undef,
Boolean $upgrade = false,
Optional[String] $version = undef,
Optional[String] $install_path = undef,
){

include ::helm::params

if $init {
$helm_init_flags = helm_init_flags({
init => $init,
canary_image => $canary_image,
client_only => $client_only,
debug => $debug,
dry_run => $dry_run,
home => $home,
host => $host,
kube_context => $kube_context,
local_repo_url => $local_repo_url,
net_host => $net_host,
service_account => $service_account,
skip_refresh => $skip_refresh,
stable_repo_url => $stable_repo_url,
overrides => $overrides,
node_selectors => $node_selectors,
tiller_image => $tiller_image,
tiller_namespace => $tiller_namespace,
tiller_tls => $tiller_tls,
tiller_tls_cert => $tiller_tls_cert,
tiller_tls_key => $tiller_tls_key,
tls_ca_cert => $tls_ca_cert,
upgrade => $upgrade,
})

$versioninfo = split($version, '.')

if (Integer($version[0]) < 3) {
$helm_init_flags = helm_init_flags({
init => $init,
canary_image => $canary_image,
client_only => $client_only,
debug => $debug,
dry_run => $dry_run,
home => $home,
host => $host,
kube_context => $kube_context,
local_repo_url => $local_repo_url,
net_host => $net_host,
service_account => $service_account,
skip_refresh => $skip_refresh,
stable_repo_url => $stable_repo_url,
overrides => $overrides,
node_selectors => $node_selectors,
tiller_image => $tiller_image,
tiller_namespace => $tiller_namespace,
tiller_tls => $tiller_tls,
tiller_tls_cert => $tiller_tls_cert,
tiller_tls_key => $tiller_tls_key,
tls_ca_cert => $tls_ca_cert,
upgrade => $upgrade,
})

if $home != undef {
$is_client_init_cmd = "test -d ${home}/plugins"
}
else {
$is_client_init_cmd = 'test -d ~/.helm/plugins'
}
if $home != undef {
$is_client_init_cmd = "test -d ${home}/plugins"
}
else {
$is_client_init_cmd = 'test -d ~/.helm/plugins'
}

if $client_only == false {
$is_server_init_cmd = "kubectl get deployment --namespace=${tiller_namespace} | grep 'tiller-deploy'"
} else {
$is_server_init_cmd = true
}
if $client_only == false {
$is_server_init_cmd = "kubectl get deployment --namespace=${tiller_namespace} | grep 'tiller-deploy'"
} else {
$is_server_init_cmd = true
}

$exec_init = "helm ${helm_init_flags}"
$unless_init = "${is_client_init_cmd} && ${is_server_init_cmd}"
$exec_init = "helm ${helm_init_flags}"
$unless_init = "${is_client_init_cmd} && ${is_server_init_cmd}"

exec { "helm ${tiller_namespace} init":
command => $exec_init,
environment => $env,
path => $path,
logoutput => true,
timeout => 0,
unless => $unless_init,
}
exec { "helm ${tiller_namespace} init":
command => $exec_init,
environment => $env,
path => $path,
logoutput => true,
timeout => 0,
unless => $unless_init,
}
}
}
26 changes: 15 additions & 11 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,22 @@
}
}

contain ::helm::binary
contain ::helm::config
if versioncmp($version, '3.0.0') >= 0 {
contain ::helm::binary
} else {
contain ::helm::binary
contain ::helm::config

if $client_only == false {
contain ::helm::account_config
Class['helm::binary']
-> Class['helm::account_config']
-> Class['helm::config']
}
else{
Class['helm::binary']
-> Class['helm::config']
if $client_only == false {
contain ::helm::account_config
Class['helm::binary']
-> Class['helm::account_config']
-> Class['helm::config']
}
else{
Class['helm::binary']
-> Class['helm::config']
}
}

}
4 changes: 0 additions & 4 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
'tiller_tls_verify' => false,
'tls_ca_cert' => 'ca_cert',
'upgrade' => false,
'version' => '2.5.1',
'install_path' => '/usr/bin',
} }

it do
Expand Down Expand Up @@ -60,8 +58,6 @@
'tiller_tls_verify' => 'false',
'tls_ca_cert' => 'ca_cert',
'upgrade' => 'false',
'version' => '2.5.1',
'install_path' => '/usr/bin',
})
end
end
Expand Down
15 changes: 14 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:architecture => 'amd64'
} }

let(:params) { {
let(:default_params) { {
'env' => [ 'HOME=/root', 'KUBECONFIG=/root/admin.conf'],
'init' => true,
'install_path' => '/usr/bin',
Expand All @@ -19,6 +19,7 @@
} }

context 'with sane default values for all parameters' do
let(:params) { default_params }
it do
is_expected.to compile.with_all_deps
is_expected.to contain_class('helm')
Expand All @@ -27,4 +28,16 @@
is_expected.to contain_class('helm::config')
end
end

context 'helm v3' do
let(:params) { default_params.merge('version' => '3.5.0') }

it do
is_expected.to compile.with_all_deps
is_expected.to contain_class('helm')
is_expected.to contain_class('helm::binary')
is_expected.not_to contain_class('helm::account_config')
is_expected.not_to contain_class('helm::config')
end
end
end
4 changes: 0 additions & 4 deletions spec/defines/helm_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
'tiller_tls_cert' => 'cert',
'tiller_tls_key' => 'key',
'tiller_tls_verify' => true,
'version' => '2.7.2',
} }
it do
is_expected.to compile.with_all_deps
Expand All @@ -28,7 +27,6 @@
'path' => [ '/bin','/usr/bin'],
'service_account' => 'tiller',
'tiller_namespace' => 'kube-system',
'version' => '2.7.2',
} }
it do
is_expected.to compile.with_all_deps
Expand All @@ -43,7 +41,6 @@
'path' => [ '/bin','/usr/bin'],
'service_account' => 'tiller',
'tiller_namespace' => 'kube-system',
'version' => '2.7.2',
}}
it do
is_expected.to compile.with_all_deps
Expand All @@ -58,7 +55,6 @@
'path' => [ '/bin','/usr/bin'],
'service_account' => 'tiller',
'tiller_namespace' => 'kube-system',
'version' => '2.7.2',
}}
it do
is_expected.to compile.with_all_deps
Expand Down

0 comments on commit 8a87cba

Please sign in to comment.