-
Notifications
You must be signed in to change notification settings - Fork 68
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
Feature/helm deploy #189
Closed
Closed
Feature/helm deploy #189
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b58f678
add comments
gfulton-redhat 7dcd285
updated header comments
gfulton-redhat 950fc96
add test file
gfulton-redhat 64f97ba
fix lint errors
gfulton-redhat 86ee848
remove unused properties
gfulton-redhat 6e887fd
make sure the default configs are there
gfulton-redhat 70697f5
make sure the required fields are as designed
gfulton-redhat 7f61dd2
add base test
gfulton-redhat a4f139c
add testing stubs
gfulton-redhat f80fa11
add testing stubs
gfulton-redhat 6e45052
add testing stubs
gfulton-redhat 450b58e
test stubs
gfulton-redhat 0e8d29c
tweaks from review, unfinished
GregJohnStewart 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
140 changes: 140 additions & 0 deletions
140
src/ploigos_step_runner/step_implementers/deploy/helm.py
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,140 @@ | ||
"""`StepImplementer` for the `deploy` step using `helm secrets upgrade --install` so that it works for both an initial \ | ||
upgrade of a preinstalled helm chart. | ||
|
||
Step Configuration | ||
------------------ | ||
Step configuration expected as input to this step. | ||
Could come from: | ||
* static configuration | ||
* runtime configuration | ||
* previous step results | ||
|
||
Configuration Key | Required? | Default | Description | ||
-----------------------------|-----------|---------|----------- | ||
`helm-chart` | Yes | | The chart argument can be either: a chart \ | ||
reference('example/mariadb'), a path to a chart directory, a \ | ||
packaged chart, or a fully qualified URL. | ||
`helm-release` | Yes | | Release tag. | ||
`helm-flags` | No | `[]` | Use flags to customize the installation behavior. | ||
""" # pylint: disable=line-too-long | ||
|
||
|
||
import sys | ||
import sh | ||
|
||
from ploigos_step_runner.step_implementer import StepImplementer | ||
from ploigos_step_runner import StepResult, StepRunnerException | ||
from ploigos_step_runner.utils.io import \ | ||
create_sh_redirect_to_multiple_streams_fn_callback | ||
|
||
DEFAULT_CONFIG = { | ||
'helm-release-name': "", | ||
'helm-additional-arguments': [] | ||
} | ||
|
||
REQUIRED_CONFIG_OR_PREVIOUS_STEP_RESULT_ARTIFACT_KEYS = [ | ||
'helm-chart' | ||
] | ||
|
||
DEFAULT_RELEASE_FORMAT = "{org}-{app}-{service}" | ||
DEFAULT_CHART_FORMAT = "{service}" | ||
|
||
|
||
class Helm(StepImplementer): | ||
"""`StepImplementer` for the `deploy` step using Helm. | ||
""" | ||
|
||
def __init__( # pylint: disable=too-many-arguments | ||
self, | ||
workflow_result, | ||
parent_work_dir_path, | ||
config, | ||
environment=None | ||
): | ||
super().__init__( | ||
workflow_result=workflow_result, | ||
parent_work_dir_path=parent_work_dir_path, | ||
config=config, | ||
environment=environment | ||
) | ||
|
||
@staticmethod | ||
def step_implementer_config_defaults(): | ||
"""Getter for the StepImplementer's configuration defaults. | ||
|
||
Returns | ||
------- | ||
dict | ||
Default values to use for step configuration values. | ||
|
||
Notes | ||
----- | ||
These are the lowest precedence configuration values. | ||
""" | ||
|
||
return DEFAULT_CONFIG | ||
|
||
@staticmethod | ||
def _required_config_or_result_keys(): | ||
"""Getter for step configuration or previous step result artifacts that are required before | ||
running this step. | ||
|
||
See Also | ||
-------- | ||
_validate_required_config_or_previous_step_result_artifact_keys | ||
|
||
Returns | ||
------- | ||
array_list | ||
Array of configuration keys or previous step result artifacts | ||
that are required before running the step. | ||
""" | ||
return REQUIRED_CONFIG_OR_PREVIOUS_STEP_RESULT_ARTIFACT_KEYS | ||
|
||
def _run_step(self): # pylint: disable=too-many-locals | ||
"""Runs the step implemented by this StepImplementer. | ||
|
||
Returns | ||
------- | ||
StepResult | ||
Object containing the dictionary results of this step. | ||
""" | ||
step_result = StepResult.from_step_implementer(self) | ||
|
||
if not self.get_value("helm-release-name"): | ||
self.__setattr__("helm-release-name", DEFAULT_RELEASE_FORMAT) | ||
# TODO:: fill in placeholders in DEFAULT_RELEASE_FORMAT before setting | ||
|
||
# install the helm chart | ||
helm_output_file_path = self.write_working_file('helm_output.txt') | ||
try: | ||
# execute helm step (params come from config) | ||
with open(helm_output_file_path, 'w') as helm_output_file: | ||
# pylint: disable=no-member | ||
sh.helm( | ||
'secrets', 'upgrade', '--install', | ||
self.get_value('helm-release-name'), | ||
self.get_value('helm-chart'), | ||
*self.get_value('helm-additional-arguments'), | ||
_out=create_sh_redirect_to_multiple_streams_fn_callback([ | ||
sys.stdout, | ||
helm_output_file | ||
]), | ||
_err=create_sh_redirect_to_multiple_streams_fn_callback([ | ||
sys.stderr, | ||
helm_output_file | ||
]) | ||
) | ||
except StepRunnerException as error: | ||
step_result.success = False | ||
step_result.message = "Error running helm. " \ | ||
f"More details maybe found in 'helm-output' report artifact: {error}" | ||
finally: | ||
step_result.add_artifact( | ||
description="Standard out and standard error from helm.", | ||
name='helm-output', | ||
value=helm_output_file_path | ||
) | ||
# TODO:: run helm test to ensure success | ||
|
||
return step_result |
Oops, something went wrong.
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.
@gfulton-redhat we should auto generate the helm chart name based on the org/app/service/enviornment names that are given. if you want you can allow someone to overwrite the auto generated name with a config value, but i dont see the use case at this time, but im sure someone will want to do it for some reason, but lets have a sensable default.
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.
I'm not too familiar with Helm, what's a reasonable format for the chart name?
Also, do we have a convention for handling default values?
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.
@GregJohnStewart Do you mean format in the sense of how it's spelled/capitalized/puncuated? Check out the best practices section of the upstream doc. Can you elaborate on the question about convention? Not sure I understand.