Skip to content

Commit 67b45bf

Browse files
authored
Merge pull request #12 from puppetlabs/replats-487-add-plan-to-install-helm-charts
(REPLATS-487) Add plan to install helm charts
2 parents b94d137 + da8d7ac commit 67b45bf

File tree

8 files changed

+342
-37
lines changed

8 files changed

+342
-37
lines changed

.github/workflows/pr-test.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ jobs:
4747
bolt task run pam_tools::delete_k8s_app_resources --targets=localhost kots_slug=test-chart
4848
- uses: ./.github/actions/validate-no-pods
4949

50+
plan-helm-acceptance:
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v2
54+
- uses: nolar/setup-k3d-k3s@v1
55+
with:
56+
version: v1.19
57+
k3d-args: -p 80:80@loadbalancer -p 443:443@loadbalancer
58+
- uses: ./.github/actions/install-bolt
59+
- name: Install bitnami/metrics-server chart
60+
run: |-
61+
bolt plan run pam_tools::install_chart --targets=localhost chart_name=bitnami/metrics-server repository_uri=https://charts.bitnami.com/bitnami release='test-release' values_yaml='commonLabels: { app.kubernetes.io/part-of: metrics-server }' part_of=metrics-server
62+
5063
plan-install-acceptance:
5164
runs-on: ubuntu-latest
5265
steps:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ In particular, the target you run bolt against should have:
4848
* [kubectl]
4949
* [kubectl-kots]
5050
* [ruby] \(because most of the tasks are Ruby\)
51-
* [helm] \(optional, depending on whether you installing helm charts\)
51+
* [helm] \(optional, depending on whether you are installing helm charts\)
5252

5353
installed.
5454

REFERENCE.md

Lines changed: 129 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* [`get_ingress_ip`](#get_ingress_ip): Returns the ip of the ingress load balancer service.
2828
* [`get_kots_app_status`](#get_kots_app_status): Return the state of a given Kots application, or not-installed. Will also return not-installed if kots itself is not installed.
2929
* [`has_ingress_controller`](#has_ingress_controller): Checks whether an ingress controller is installed.
30+
* [`helm_add_repository`](#helm_add_repository): Add a helm repository.
3031
* [`helm_install_chart`](#helm_install_chart): Install or upgrade a helm chart.
3132
* [`kots_download`](#kots_download): Downloads the currently installed source of a given Kots application from the admin console to the given directory. This task is a wrapper ro
3233
* [`kots_install`](#kots_install): Install a Replicated application with kubectl-kots for testing. This task takes several shortcuts for configuration and security which are no
@@ -40,6 +41,7 @@
4041

4142
### Plans
4243

44+
* [`pam_tools::install_chart`](#pam_toolsinstall_chart): Install a helm chart. Optionally adds a helm *repository_uri* before installing. Optionally waits for rollout of the installed chart based
4345
* [`pam_tools::install_published`](#pam_toolsinstall_published): Install a published Replicated application via kubectl-kots. Runs kubectl-kots with the given license and configuration and waits for deploy
4446
* [`pam_tools::teardown`](#pam_toolsteardown): In successive tiers, teardown the application, it's admin-console metadata, and the Kots admin-console itself, if desired. By default, just
4547

@@ -55,18 +57,18 @@ minimal test memory instance of 4.5GB.
5557
This allows you to spin up Connect on an 8GB test host with the PE
5658
components squeezed down into:
5759

58-
pam_tools::calculate_pe_memory(4.5)
59-
#
60-
# {
61-
# 'console_memory' => 768,
62-
# 'postgres_console_memory' => 256,
63-
# 'puppetdb_memory' => 768,
64-
# 'postgres_puppetdb_memory' => 512,
65-
# 'orchestrator_memory' => 768,
66-
# 'postgres_orch_memory' => 256,
67-
# 'boltserver_memory' => 256,
68-
# 'puppetserver_memory' => 1024,
69-
# }
60+
pam_tools::calculate_pe_memory(4.5)
61+
#
62+
# {
63+
# 'console_memory' => 768,
64+
# 'postgres_console_memory' => 256,
65+
# 'puppetdb_memory' => 768,
66+
# 'postgres_puppetdb_memory' => 512,
67+
# 'orchestrator_memory' => 768,
68+
# 'postgres_orch_memory' => 256,
69+
# 'boltserver_memory' => 256,
70+
# 'puppetserver_memory' => 1024,
71+
# }
7072

7173
Leaving remaining memory for the rest of Connect and system.
7274

@@ -84,18 +86,18 @@ minimal test memory instance of 4.5GB.
8486
This allows you to spin up Connect on an 8GB test host with the PE
8587
components squeezed down into:
8688

87-
pam_tools::calculate_pe_memory(4.5)
88-
#
89-
# {
90-
# 'console_memory' => 768,
91-
# 'postgres_console_memory' => 256,
92-
# 'puppetdb_memory' => 768,
93-
# 'postgres_puppetdb_memory' => 512,
94-
# 'orchestrator_memory' => 768,
95-
# 'postgres_orch_memory' => 256,
96-
# 'boltserver_memory' => 256,
97-
# 'puppetserver_memory' => 1024,
98-
# }
89+
pam_tools::calculate_pe_memory(4.5)
90+
#
91+
# {
92+
# 'console_memory' => 768,
93+
# 'postgres_console_memory' => 256,
94+
# 'puppetdb_memory' => 768,
95+
# 'postgres_puppetdb_memory' => 512,
96+
# 'orchestrator_memory' => 768,
97+
# 'postgres_orch_memory' => 256,
98+
# 'boltserver_memory' => 256,
99+
# 'puppetserver_memory' => 1024,
100+
# }
99101

100102
Leaving remaining memory for the rest of Connect and system.
101103

@@ -432,6 +434,26 @@ Checks whether an ingress controller is installed.
432434

433435
**Supports noop?** false
434436

437+
### <a name="helm_add_repository"></a>`helm_add_repository`
438+
439+
Add a helm repository.
440+
441+
**Supports noop?** false
442+
443+
#### Parameters
444+
445+
##### `repository_name`
446+
447+
Data type: `String`
448+
449+
Name for the helm repository.
450+
451+
##### `repository_uri`
452+
453+
Data type: `String`
454+
455+
Uri for the helm repository.
456+
435457
### <a name="helm_install_chart"></a>`helm_install_chart`
436458

437459
Install or upgrade a helm chart.
@@ -760,6 +782,89 @@ Number of seconds to wait for Deployment and StatefulSet rollouts to complete.
760782

761783
## Plans
762784

785+
### <a name="pam_toolsinstall_chart"></a>`pam_tools::install_chart`
786+
787+
Install a helm chart.
788+
789+
Optionally adds a helm *repository_uri* before installing.
790+
791+
Optionally waits for rollout of the installed chart based on a
792+
*part_of* selector.
793+
794+
#### Parameters
795+
796+
The following parameters are available in the `pam_tools::install_chart` plan:
797+
798+
* [`targets`](#targets)
799+
* [`chart_name`](#chart_name)
800+
* [`release`](#release)
801+
* [`repository_uri`](#repository_uri)
802+
* [`values_yaml`](#values_yaml)
803+
* [`namespace`](#namespace)
804+
* [`part_of`](#part_of)
805+
* [`timeout`](#timeout)
806+
807+
##### <a name="targets"></a>`targets`
808+
809+
Data type: `TargetSpec`
810+
811+
Test hosts to deploy to.
812+
813+
##### <a name="chart_name"></a>`chart_name`
814+
815+
Data type: `String`
816+
817+
The chart to install.
818+
819+
##### <a name="release"></a>`release`
820+
821+
Data type: `String`
822+
823+
The name of the installed instance of the chart.
824+
825+
##### <a name="repository_uri"></a>`repository_uri`
826+
827+
Data type: `Optional[String]`
828+
829+
If a helm repository uri is given, ensure it is added and updated on targets
830+
before attempting to install the chart. Will take the repository name from
831+
the *chart_name* prefix/.
832+
833+
Default value: ``undef``
834+
835+
##### <a name="values_yaml"></a>`values_yaml`
836+
837+
Data type: `Optional[String]`
838+
839+
Optional yaml string of chart values to pass to Helm.
840+
841+
Default value: ``undef``
842+
843+
##### <a name="namespace"></a>`namespace`
844+
845+
Data type: `String`
846+
847+
k8s namespace we're installing into.
848+
849+
Default value: `'default'`
850+
851+
##### <a name="part_of"></a>`part_of`
852+
853+
Data type: `Optional[String]`
854+
855+
If given, plan will wait for rollout of deployments and statefulsets
856+
matching 'app.kuberneters.io/part-of=${part_of}' until *timeout*.
857+
858+
Default value: ``undef``
859+
860+
##### <a name="timeout"></a>`timeout`
861+
862+
Data type: `Integer`
863+
864+
Number of seconds to wait for the services to all be ready.
865+
866+
Default value: `600`
867+
763868
### <a name="pam_toolsinstall_published"></a>`pam_tools::install_published`
764869

765870
Install a published Replicated application via kubectl-kots.

functions/calculate_pe_memory.pp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
# This allows you to spin up Connect on an 8GB test host with the PE
55
# components squeezed down into:
66
#
7-
# pam_tools::calculate_pe_memory(4.5)
8-
# #
9-
# # {
10-
# # 'console_memory' => 768,
11-
# # 'postgres_console_memory' => 256,
12-
# # 'puppetdb_memory' => 768,
13-
# # 'postgres_puppetdb_memory' => 512,
14-
# # 'orchestrator_memory' => 768,
15-
# # 'postgres_orch_memory' => 256,
16-
# # 'boltserver_memory' => 256,
17-
# # 'puppetserver_memory' => 1024,
18-
# # }
7+
# pam_tools::calculate_pe_memory(4.5)
8+
# #
9+
# # {
10+
# # 'console_memory' => 768,
11+
# # 'postgres_console_memory' => 256,
12+
# # 'puppetdb_memory' => 768,
13+
# # 'postgres_puppetdb_memory' => 512,
14+
# # 'orchestrator_memory' => 768,
15+
# # 'postgres_orch_memory' => 256,
16+
# # 'boltserver_memory' => 256,
17+
# # 'puppetserver_memory' => 1024,
18+
# # }
1919
#
2020
# Leaving remaining memory for the rest of Connect and system.
2121
#

plans/install_chart.pp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Install a helm chart.
2+
#
3+
# Optionally adds a helm *repository_uri* before installing.
4+
#
5+
# Optionally waits for rollout of the installed chart based on a
6+
# *part_of* selector.
7+
#
8+
# @param targets
9+
# Test hosts to deploy to.
10+
# @param chart_name
11+
# The chart to install.
12+
# @param release
13+
# The name of the installed instance of the chart.
14+
# @param repository_uri
15+
# If a helm repository uri is given, ensure it is added and updated on targets
16+
# before attempting to install the chart. Will take the repository name from
17+
# the *chart_name* prefix/.
18+
# @param values_yaml
19+
# Optional yaml string of chart values to pass to Helm.
20+
# @param namespace
21+
# k8s namespace we're installing into.
22+
# @param part_of
23+
# If given, plan will wait for rollout of deployments and statefulsets
24+
# matching 'app.kuberneters.io/part-of=${part_of}' until *timeout*.
25+
# @param timeout
26+
# Number of seconds to wait for the services to all be ready.
27+
plan pam_tools::install_chart(
28+
TargetSpec $targets,
29+
String $chart_name,
30+
String $release,
31+
Optional[String] $repository_uri = undef,
32+
Optional[String] $values_yaml = undef,
33+
String $namespace = 'default',
34+
Optional[String] $part_of = undef,
35+
Integer $timeout = 600,
36+
) {
37+
38+
if $repository_uri =~ NotUndef {
39+
$repository_name = regsubst($chart_name, '^([\w-]+)/[\w-]+$', '\1')
40+
# regsubst() returns the string unchanged if it does not match.
41+
if $repository_name == $chart_name {
42+
fail_plan("Expected to find a repository name as the prefix/ in chart_name: '${chart_name}'. Therefore unable to add repository uri '${repository_uri}'.")
43+
}
44+
$repo_results = run_task('pam_tools::helm_add_repository', $targets, {
45+
repository_name => $repository_name,
46+
repository_uri => $repository_uri,
47+
})
48+
} else {
49+
$repo_results = 'No repository to add.'
50+
}
51+
52+
$install_results = run_task('pam_tools::helm_install_chart', $targets, {
53+
chart => $chart_name,
54+
release => $release,
55+
values => $values_yaml,
56+
namespace => $namespace,
57+
})
58+
59+
if $part_of =~ NotUndef {
60+
$wait_results = run_task('pam_tools::wait_for_rollout', $targets, {
61+
selector => "app.kubernetes.io/part-of=${part_of}",
62+
namespace => $namespace,
63+
timeout => "${timeout}s",
64+
})
65+
} else {
66+
$wait_results = 'No part_of selector specified; not waiting for rollout.'
67+
}
68+
69+
$results = {
70+
repo_results => $repo_results,
71+
install_results => $install_results,
72+
wait_results => $wait_results,
73+
}
74+
return $results
75+
}

0 commit comments

Comments
 (0)