Skip to content

Commit

Permalink
Add ability to deploy helm v3
Browse files Browse the repository at this point in the history
fix tests

add unit test for helm_repo

removing helm 3 option in helm init

add acceptance test for helm 3
  • Loading branch information
Marc Schaer authored and AblionGE committed Nov 21, 2020
1 parent 94fd36d commit 4557029
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 98 deletions.
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _Private Classes_
* [`helm::chart`](#helmchart): Manages the deployment of helm charts.
* [`helm::chart_update`](#helmchart_update): Update the deployed Helm charts.
* [`helm::create`](#helmcreate): Creates a new Helm chart.
* [`helm::helm_init`](#helmhelm_init): Deploys the Tiller pod and initializes the Helm client.
* [`helm::helm_init`](#helmhelm_init): Deploys the Tiller pod and initializes the Helm client (only for Helm versions < 3).
* [`helm::package`](#helmpackage): Packages a chart directory ino a chart archive..
* [`helm::repo`](#helmrepo): Adds a Helm repository.
* [`helm::repo_update`](#helmrepo_update): Updates all of the Helm repositories.
Expand Down
4 changes: 4 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
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 @@ -56,6 +58,8 @@
tiller_tls_key => $tiller_tls_key,
tls_ca_cert => $tls_ca_cert,
upgrade => $upgrade,
version => $version,
install_path => $install_path,
}
}
}
103 changes: 59 additions & 44 deletions manifests/helm_init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@
# 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 @@ -110,59 +118,66 @@
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,
})

if $home != undef {
$is_client_init_cmd = "test -d ${home}/plugins"
}
else {
$is_client_init_cmd = 'test -d ~/.helm/plugins'
}
$versioninfo = split($version, '.')

if $client_only == false {
$is_server_init_cmd = "kubectl get deployment --namespace=${tiller_namespace} | grep 'tiller-deploy'"
} else {
$is_server_init_cmd = true
}
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 $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,
}
}
}
}
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
#
# @param version
# The version of helm to install.
# Defaults to 2.5.1
# Defaults to 2.7.2
#
# @param archive_baseurl
# The base URL for downloading the helm archive, must contain file helm-v${version}-linux-${arch}.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
$tls_ca_cert = undef
$upgrade = false
$version = '2.7.2'
$archive_baseurl = 'https://kubernetes-helm.storage.googleapis.com'
$archive_baseurl = 'https://get.helm.sh'
}
99 changes: 68 additions & 31 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,79 @@
Optional[String] $password = undef,
Optional[String] $repo_name = undef,
Optional[String] $url = undef,
Optional[String] $version = $helm::version,
){

include ::helm::params

if $ensure == present {
$helm_repo_add_flags = helm_repo_add_flags({
ensure => $ensure,
ca_file => $ca_file,
cert_file => $cert_file,
debug => $debug,
key_file => $key_file,
no_update => $no_update,
home => $home,
host => $host,
kube_context => $kube_context,
tiller_namespace => $tiller_namespace,
username => $username,
password => $password,
repo_name => $repo_name,
url => $url,
})
$exec_repo = "helm repo ${helm_repo_add_flags}"
$unless_repo = "helm repo list | awk '{if(NR>1)print \$1}' | grep -w ${repo_name}"
}
$versioninfo = split($version, '.')

if (Integer($version[0]) < 3) {
if $ensure == present {
$helm_repo_add_flags = helm_repo_add_flags({
ensure => $ensure,
ca_file => $ca_file,
cert_file => $cert_file,
debug => $debug,
key_file => $key_file,
no_update => $no_update,
home => $home,
host => $host,
kube_context => $kube_context,
tiller_namespace => $tiller_namespace,
username => $username,
password => $password,
repo_name => $repo_name,
url => $url,
})
$exec_repo = "helm repo ${helm_repo_add_flags}"
$unless_repo = "helm repo list | awk '{if(NR>1)print \$1}' | grep -w ${repo_name}"
}

if $ensure == absent {
$helm_repo_remove_flags = helm_repo_remove_flags({
ensure => $ensure,
home => $home,
host => $host,
kube_context => $kube_context,
repo_name => $repo_name,
tiller_namespace => $tiller_namespace,
})
$exec_repo = "helm repo ${helm_repo_remove_flags}"
$unless_repo = "helm repo list | awk '{if (\$1 == \"${repo_name}\") exit 1}'"
}
} else {
if $ensure == present {
$helm_repo_add_flags = helm_repo_add_flags({
ensure => $ensure,
ca_file => $ca_file,
cert_file => $cert_file,
debug => $debug,
key_file => $key_file,
no_update => $no_update,
host => $host,
kube_context => $kube_context,
tiller_namespace => $tiller_namespace,
username => $username,
password => $password,
repo_name => $repo_name,
url => $url,
})
$exec_repo = "helm repo ${helm_repo_add_flags}"
$unless_repo = "helm repo list | awk '{if(NR>1)print \$1}' | grep -w ${repo_name}"
}

if $ensure == absent {
$helm_repo_remove_flags = helm_repo_remove_flags({
ensure => $ensure,
home => $home,
host => $host,
kube_context => $kube_context,
repo_name => $repo_name,
tiller_namespace => $tiller_namespace,
})
$exec_repo = "helm repo ${helm_repo_remove_flags}"
$unless_repo = "helm repo list | awk '{if (\$1 == \"${repo_name}\") exit 1}'"
if $ensure == absent {
$helm_repo_remove_flags = helm_repo_remove_flags({
ensure => $ensure,
host => $host,
kube_context => $kube_context,
repo_name => $repo_name,
tiller_namespace => $tiller_namespace,
})
$exec_repo = "helm repo ${helm_repo_remove_flags}"
$unless_repo = "helm repo list | awk '{if (\$1 == \"${repo_name}\") exit 1}'"
}
}

exec { "helm repo ${repo_name}":
Expand Down
36 changes: 26 additions & 10 deletions manifests/repo_update.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,36 @@
Optional[Array] $path = undef,
Optional[String] $tiller_namespace = undef,
Boolean $update = true,
Optional[String] $version = $helm::params::version,
){

include ::helm::params

if $update {
$helm_repo_update_flags = helm_repo_update_flags({
debug => $debug,
home => $home,
host => $host,
kube_context => $kube_context,
tiller_namespace => $tiller_namespace,
update => $update,
})
$exec_update = "helm repo ${helm_repo_update_flags}"
$versioninfo = split($version, '.')

if (Integer($version[0]) < 3) {
if $update {
$helm_repo_update_flags = helm_repo_update_flags({
debug => $debug,
home => $home,
host => $host,
kube_context => $kube_context,
tiller_namespace => $tiller_namespace,
update => $update,
})
$exec_update = "helm repo ${helm_repo_update_flags}"
}
} else {
if $update {
$helm_repo_update_flags = helm_repo_update_flags({
debug => $debug,
host => $host,
kube_context => $kube_context,
tiller_namespace => $tiller_namespace,
update => $update,
})
$exec_update = "helm repo ${helm_repo_update_flags}"
}
}

exec { 'helm repo update':
Expand Down

0 comments on commit 4557029

Please sign in to comment.