-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(REPLATS-487) Add plan to install helm charts #12
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
* [`get_ingress_ip`](#get_ingress_ip): Returns the ip of the ingress load balancer service. | ||
* [`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. | ||
* [`has_ingress_controller`](#has_ingress_controller): Checks whether an ingress controller is installed. | ||
* [`helm_add_repository`](#helm_add_repository): Add a helm repository. | ||
* [`helm_install_chart`](#helm_install_chart): Install or upgrade a helm chart. | ||
* [`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 | ||
* [`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 @@ | |
|
||
### Plans | ||
|
||
* [`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 | ||
* [`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 | ||
* [`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 | ||
|
||
|
@@ -432,6 +434,26 @@ Checks whether an ingress controller is installed. | |
|
||
**Supports noop?** false | ||
|
||
### <a name="helm_add_repository"></a>`helm_add_repository` | ||
|
||
Add a helm repository. | ||
|
||
**Supports noop?** false | ||
|
||
#### Parameters | ||
|
||
##### `repository_name` | ||
|
||
Data type: `String` | ||
|
||
Name for the helm repository. | ||
|
||
##### `repository_uri` | ||
|
||
Data type: `String` | ||
|
||
Uri for the helm repository. | ||
|
||
### <a name="helm_install_chart"></a>`helm_install_chart` | ||
|
||
Install or upgrade a helm chart. | ||
|
@@ -760,6 +782,89 @@ Number of seconds to wait for Deployment and StatefulSet rollouts to complete. | |
|
||
## Plans | ||
|
||
### <a name="pam_toolsinstall_chart"></a>`pam_tools::install_chart` | ||
|
||
Install a helm chart. | ||
|
||
Optionally adds a helm *repository_uri* before installing. | ||
|
||
Optionally waits for rollout of the installed chart based on a | ||
*part_of* selector. | ||
|
||
#### Parameters | ||
|
||
The following parameters are available in the `pam_tools::install_chart` plan: | ||
|
||
* [`targets`](#targets) | ||
* [`chart_name`](#chart_name) | ||
* [`release`](#release) | ||
* [`repository_uri`](#repository_uri) | ||
* [`values_yaml`](#values_yaml) | ||
* [`namespace`](#namespace) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above, this link seems to go to the |
||
* [`part_of`](#part_of) | ||
* [`timeout`](#timeout) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one goes to "get_ingress_ip" |
||
|
||
##### <a name="targets"></a>`targets` | ||
|
||
Data type: `TargetSpec` | ||
|
||
Test hosts to deploy to. | ||
|
||
##### <a name="chart_name"></a>`chart_name` | ||
|
||
Data type: `String` | ||
|
||
The chart to install. | ||
|
||
##### <a name="release"></a>`release` | ||
|
||
Data type: `String` | ||
|
||
The name of the installed instance of the chart. | ||
|
||
##### <a name="repository_uri"></a>`repository_uri` | ||
|
||
Data type: `Optional[String]` | ||
|
||
If a helm repository uri is given, ensure it is added and updated on targets | ||
before attempting to install the chart. Will take the repository name from | ||
the *chart_name* prefix/. | ||
|
||
Default value: ``undef`` | ||
|
||
##### <a name="values_yaml"></a>`values_yaml` | ||
|
||
Data type: `Optional[String]` | ||
|
||
Optional yaml string of chart values to pass to Helm. | ||
|
||
Default value: ``undef`` | ||
|
||
##### <a name="namespace"></a>`namespace` | ||
|
||
Data type: `String` | ||
|
||
k8s namespace we're installing into. | ||
|
||
Default value: `'default'` | ||
|
||
##### <a name="part_of"></a>`part_of` | ||
|
||
Data type: `Optional[String]` | ||
|
||
If given, plan will wait for rollout of deployments and statefulsets | ||
matching 'app.kuberneters.io/part-of=${part_of}' until *timeout*. | ||
|
||
Default value: ``undef`` | ||
|
||
##### <a name="timeout"></a>`timeout` | ||
|
||
Data type: `Integer` | ||
|
||
Number of seconds to wait for the services to all be ready. | ||
|
||
Default value: `600` | ||
|
||
### <a name="pam_toolsinstall_published"></a>`pam_tools::install_published` | ||
|
||
Install a published Replicated application via kubectl-kots. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Install a helm chart. | ||
# | ||
# Optionally adds a helm *repository_uri* before installing. | ||
# | ||
# Optionally waits for rollout of the installed chart based on a | ||
# *part_of* selector. | ||
# | ||
# @param targets | ||
# Test hosts to deploy to. | ||
# @param chart_name | ||
# The chart to install. | ||
# @param release | ||
# The name of the installed instance of the chart. | ||
# @param repository_uri | ||
# If a helm repository uri is given, ensure it is added and updated on targets | ||
# before attempting to install the chart. Will take the repository name from | ||
# the *chart_name* prefix/. | ||
# @param values_yaml | ||
# Optional yaml string of chart values to pass to Helm. | ||
# @param namespace | ||
# k8s namespace we're installing into. | ||
# @param part_of | ||
# If given, plan will wait for rollout of deployments and statefulsets | ||
# matching 'app.kuberneters.io/part-of=${part_of}' until *timeout*. | ||
# @param timeout | ||
# Number of seconds to wait for the services to all be ready. | ||
plan pam_tools::install_chart( | ||
TargetSpec $targets, | ||
String $chart_name, | ||
String $release, | ||
Optional[String] $repository_uri = undef, | ||
Optional[String] $values_yaml = undef, | ||
String $namespace = 'default', | ||
Optional[String] $part_of = undef, | ||
Integer $timeout = 600, | ||
) { | ||
|
||
if $repository_uri =~ NotUndef { | ||
$repository_name = regsubst($chart_name, '^([\w-]+)/[\w-]+$', '\1') | ||
# regsubst() returns the string unchanged if it does not match. | ||
if $repository_name == $chart_name { | ||
fail_plan("Expected to find a repository name as the prefix/ in chart_name: '${chart_name}'. Therefore unable to add repository uri '${repository_uri}'.") | ||
} | ||
$repo_results = run_task('pam_tools::helm_add_repository', $targets, { | ||
repository_name => $repository_name, | ||
repository_uri => $repository_uri, | ||
}) | ||
} else { | ||
$repo_results = 'No repository to add.' | ||
} | ||
|
||
$install_results = run_task('pam_tools::helm_install_chart', $targets, { | ||
chart => $chart_name, | ||
release => $release, | ||
values => $values_yaml, | ||
namespace => $namespace, | ||
}) | ||
|
||
if $part_of =~ NotUndef { | ||
$wait_results = run_task('pam_tools::wait_for_rollout', $targets, { | ||
selector => "app.kubernetes.io/part-of=${part_of}", | ||
namespace => $namespace, | ||
timeout => "${timeout}s", | ||
}) | ||
} else { | ||
$wait_results = 'No part_of selector specified; not waiting for rollout.' | ||
} | ||
|
||
$results = { | ||
repo_results => $repo_results, | ||
install_results => $install_results, | ||
wait_results => $wait_results, | ||
} | ||
return $results | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'pam_tools::install_chart' do | ||
# Include the BoltSpec library functions | ||
include BoltSpec::Plans | ||
|
||
let(:targets) { ['spec-host'] } | ||
let(:params) do | ||
{ | ||
'targets' => targets, | ||
'chart_name' => 'test-chart', | ||
'release' => 'a-release', | ||
} | ||
end | ||
|
||
it 'installs a chart' do | ||
expect_task('pam_tools::helm_install_chart') | ||
.with_targets(targets) | ||
.with_params( | ||
'chart' => 'test-chart', | ||
'release' => 'a-release', | ||
'values' => nil, | ||
'namespace' => 'default', | ||
) | ||
.always_return('results' => 'installed') | ||
|
||
result = run_plan('pam_tools::install_chart', params) | ||
expect(result.ok?).to eq(true) | ||
expect(result.value['repo_results']).to eq('No repository to add.') | ||
expect(result.value['wait_results']).to match(%r{No part_of selector specified}) | ||
end | ||
|
||
it 'adds a repository then installs a chart' do | ||
params['repository_uri'] = 'https://a.repo.rspec' | ||
params['chart_name'] = 'arepo/test-chart' | ||
|
||
expect_task('pam_tools::helm_add_repository') | ||
.with_targets(targets) | ||
.with_params( | ||
'repository_name' => 'arepo', | ||
'repository_uri' => 'https://a.repo.rspec', | ||
) | ||
.always_return('_output' => 'added arepo') | ||
|
||
expect_task('pam_tools::helm_install_chart') | ||
.with_targets(targets) | ||
.with_params( | ||
'chart' => 'arepo/test-chart', | ||
'release' => 'a-release', | ||
'values' => nil, | ||
'namespace' => 'default', | ||
) | ||
.always_return('results' => 'installed') | ||
|
||
result = run_plan('pam_tools::install_chart', params) | ||
expect(result.ok?).to eq(true) | ||
expect(result.value['repo_results']).to be_kind_of(Bolt::ResultSet) | ||
expect(result.value['wait_results']).to match(%r{No part_of selector specified}) | ||
end | ||
|
||
it 'fails if repository_uri is given but chart_name has no prefix' do | ||
params['repository_uri'] = 'https://a.repo.rspec' | ||
|
||
result = run_plan('pam_tools::install_chart', params) | ||
expect(result.ok?).to eq(false) | ||
expect(result.value.message).to match(%r{Expected to find a repository name}) | ||
end | ||
|
||
it 'installs a chart then waits' do | ||
params['part_of'] = 'stuff' | ||
|
||
expect_task('pam_tools::helm_install_chart') | ||
expect_task('pam_tools::wait_for_rollout') | ||
.with_targets(targets) | ||
.with_params( | ||
'selector' => 'app.kubernetes.io/part-of=stuff', | ||
'namespace' => 'default', | ||
'timeout' => '600s', | ||
) | ||
.always_return('_output' => 'running') | ||
|
||
result = run_plan('pam_tools::install_chart', params) | ||
expect(result.ok?).to eq(true) | ||
expect(result.value['repo_results']).to eq('No repository to add.') | ||
expect(result.value['wait_results']).to be_kind_of(Bolt::ResultSet) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"description": "Add a helm repository.", | ||
"input_method": "environment", | ||
"parameters": { | ||
"repository_name": { | ||
"description": "Name for the helm repository.", | ||
"type": "String" | ||
}, | ||
"repository_uri": { | ||
"description": "Uri for the helm repository.", | ||
"type": "String" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#! /bin/bash | ||
|
||
# PT_* are passed into the environment by Bolt. | ||
# shellcheck disable=SC2154 | ||
repo_name="${PT_repository_name}" | ||
repo_uri="${PT_repository_uri}" | ||
|
||
helm repo add "${repo_name}" "${repo_uri}" | ||
helm repo update |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clicking this seems to take you to the
repository_uri
under "helm_add_repository" instead of "pam_tools::install_chart".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks like a puppet-strings bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I should clarify; REFERENCE.md is generated by rake strings:generate:reference which is a puppet-strings rake helper. If I manually edit for these issues, it will come into conflict or be reset the next time REFERENCE gets auto generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like puppet-strings is using github issues; I'll open a bug there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
puppetlabs/puppet-strings#294