Skip to content

Commit

Permalink
Merge pull request #149 from galaxyproject/add_reset_values_chart
Browse files Browse the repository at this point in the history
Add support for resetting values on install
  • Loading branch information
nuwang committed May 10, 2021
2 parents 1cda3c4 + c4faf0e commit a3d027b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
10 changes: 6 additions & 4 deletions cloudman/helmsman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def create(self, repo_name, chart_name, namespace,
values=values)
return self._get_from_namespace(namespace, chart_name)

def update(self, chart, values, version=None):
def update(self, chart, values, version=None, reset_values=None):
self.check_permissions('helmsman.change_chart', chart)
# 1. Guess which repo the chart came from
repo_name = self._find_repo_for_chart(chart)
Expand All @@ -273,7 +273,8 @@ def update(self, chart, values, version=None):
# 2. Apply the updated config to the chart
HelmClient().releases.update(
chart.namespace, chart.id, "%s/%s" % (repo_name, chart.name), values=values,
value_handling=HelmValueHandling.REUSE, version=version)
value_handling=HelmValueHandling.RESET if reset_values else HelmValueHandling.REUSE,
version=version)
return self.get(chart.id)

def rollback(self, chart, revision=None):
Expand Down Expand Up @@ -495,14 +496,15 @@ def install(self, namespace, release_name=None, values=None,
values=[default_values, values or {}])

def upgrade(self, chart, values=None,
context=None):
context=None, reset_values=None):
default_values = yaml.safe_load(
self.render_values(context or {}))
admin = User.objects.filter(is_superuser=True).first()
client = HelmsManAPI(HMServiceContext(user=admin))
return client.charts.update(chart,
version=self.chart_version,
values=[default_values, values or {}])
values=[default_values, values or {}],
reset_values=reset_values)

def delete(self):
self.service.delete(self.name)
3 changes: 3 additions & 0 deletions cloudman/helmsman/tests/mock_helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def _create_parser(self):
parser_upgrade.add_argument(
'--reuse-values', action='store_true',
help="reuse the last release's values and merge in any overrides")
parser_upgrade.add_argument(
'--reset-values', action='store_true',
help="reset the last release's values and merge in any overrides")
parser_upgrade.add_argument(
'-f', '--values', type=str, help='value files', nargs="*", action="append")
parser_upgrade.add_argument(
Expand Down
8 changes: 5 additions & 3 deletions cloudman/projman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,16 @@ def create(self, template_name, release_name=None,
template.install(self.project.namespace, release_name,
values, context=context))

def update(self, chart, values, context=None):
def update(self, chart, values, context=None, reset_values=None):
self.check_permissions('projman.change_chart', chart)
context = self._add_projman_default_context(context)
if chart.install_template:
updated_chart = chart.install_template.upgrade(
chart, values=values, context=context)
chart, values=values, context=context,
reset_values=reset_values)
else:
updated_chart = self._get_helmsman_api().charts.update(chart, values)
updated_chart = self._get_helmsman_api().charts.update(
chart, values, reset_values=reset_values)
return self._to_proj_chart(updated_chart)

def rollback(self, chart, revision=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def add_arguments(self, parser):
parser.add_argument('values_file', help='Values file to apply to the chart')
parser.add_argument('context_file', help='Context to apply to the chart')
parser.add_argument('--upgrade', dest='upgrade_chart', action='store_true')
parser.add_argument('--reset_values', dest='reset_values', action='store_true')

def handle(self, *args, **options):
values_file = options.get("values_file")
Expand All @@ -38,12 +39,13 @@ def handle(self, *args, **options):
options['release_name'],
values,
context=context,
upgrade_chart=options['upgrade_chart'])
upgrade_chart=options['upgrade_chart'],
reset_values=options['reset_values'])

@staticmethod
def install_template_in_project(project_name, template_name,
release_name=None, values=None, context=None,
upgrade_chart=False):
upgrade_chart=False, reset_values=False):
try:
print("Installing template {}"
" into project: {}".format(template_name, project_name))
Expand All @@ -59,7 +61,8 @@ def install_template_in_project(project_name, template_name,
else:
existing = proj.charts.find(template_name)
if existing and upgrade_chart:
ch = proj.charts.update(existing, values, context=context)
ch = proj.charts.update(existing, values, context=context,
reset_values=reset_values)
print(f"Successfully updated template '{template_name}' "
f"with release named '{release_name}' into project "
f"'{project_name}'")
Expand Down
2 changes: 2 additions & 0 deletions cloudman/projman/management/commands/projman_load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def process_settings(settings):
extra_args = []
if chart.get("upgrade"):
extra_args += ['--upgrade']
if chart.get("reset_values"):
extra_args += ['--reset_values']
with helpers.TempValuesFile(values) as values_file:
with helpers.TempValuesFile(context) as context_file:
call_command("install_template_in_project",
Expand Down
1 change: 1 addition & 0 deletions cloudman/projman/tests/data/projman_config_update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ projects:
context:
storageclass: updated-provisioner
upgrade: true
reset_values: true
jupyterhub:
release_name: jup
install_template: jupyter
Expand Down

0 comments on commit a3d027b

Please sign in to comment.