From e68e352404d79a90c345f59042999914668b0f93 Mon Sep 17 00:00:00 2001 From: "Aldo \"xoen\" Giambelluca" Date: Thu, 18 Jun 2020 12:49:56 +0100 Subject: [PATCH] Helm upgrade use --force flag now Quite few users ask for support related to helm upgrade problems. It appears one of the culprits is that when there is a previous helm release in `FAILED` state helm will refuse to cooperate and raise an error like the following: ``` rstudio-alice has no deployed releases ``` There is an open issue which discusses this (see below) and some of the comments suggest to use the `--force` flag which helps with some of these helm ugprade problems. If this works/helps it should reduce the volume of support request where we have to manually `helm delete --purge` `FAILED` releases and also improve the user experience as users will see less errors. It may also help with the Tools Catalogue epic (fingers crossed) as we see other helm issues (e.g. `resource x not present` or `resource x already present` or similar helm errors) which hopefully will be avoided by the use of this flag (fingers crossed but we'll see) Also: - added test for `Helm#upgrade_release()` method - use `black` for helm test file (it's a start and it should mud the history much) GH helm issue: https://github.com/helm/helm/issues/5595 Ticket: https://trello.com/c/1XIRi1JS --- controlpanel/api/helm.py | 2 +- tests/api/test_helm.py | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/controlpanel/api/helm.py b/controlpanel/api/helm.py index a61a06f18..74de216e0 100644 --- a/controlpanel/api/helm.py +++ b/controlpanel/api/helm.py @@ -73,7 +73,7 @@ def upgrade_release(self, release, chart, *args): HelmRepository.update() return self.__class__.execute( - "upgrade", "--install", "--wait", release, chart, *args, + "upgrade", "--install", "--wait", "--force", release, chart, *args, ) def delete(self, purge=True, *args): diff --git a/tests/api/test_helm.py b/tests/api/test_helm.py index 133078575..516e756cc 100644 --- a/tests/api/test_helm.py +++ b/tests/api/test_helm.py @@ -1,9 +1,10 @@ from datetime import datetime, timedelta import pytest -from unittest.mock import patch +from unittest.mock import MagicMock, patch from controlpanel.api.helm import ( Chart, + helm, HelmRepository, ) @@ -16,10 +17,7 @@ def setup_function(fn): def test_chart_app_version(): app_version = "RStudio: 1.2.1335+conda, R: 3.5.1, Python: 3.7.1, patch: 10" chart = Chart( - "rstudio", - "RStudio with Auth0 authentication proxy", - "2.2.5", - app_version, + "rstudio", "RStudio with Auth0 authentication proxy", "2.2.5", app_version, ) assert chart.app_version == app_version @@ -53,7 +51,9 @@ def test_helm_repository_chart_info_when_chart_found(helm_repository_index): # See tests/api/fixtures/helm_mojanalytics_index.py rstudio_info = HelmRepository.get_chart_info("rstudio") - rstudio_2_2_5_app_version = "RStudio: 1.2.1335+conda, R: 3.5.1, Python: 3.7.1, patch: 10" + rstudio_2_2_5_app_version = ( + "RStudio: 1.2.1335+conda, R: 3.5.1, Python: 3.7.1, patch: 10" + ) assert len(rstudio_info) == 2 assert "2.2.5" in rstudio_info @@ -64,3 +64,19 @@ def test_helm_repository_chart_info_when_chart_found(helm_repository_index): # "recently" so for testing that for old chart # version this returns `None` assert rstudio_info["1.0.0"].app_version == None + + +def test_helm_upgrade_release(): + helm.__class__.execute = MagicMock() + + upgrade_args = ( + "release-name", + "helm-chart-name", + "--namespace=user-alice", + "--set=username=alice", + ) + helm.upgrade_release(*upgrade_args) + + helm.__class__.execute.assert_called_with( + "upgrade", "--install", "--wait", "--force", *upgrade_args, + )