Skip to content

Commit

Permalink
Refactoring and add notes for further changes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljcollinsuk committed Dec 12, 2024
1 parent bf988d4 commit 1e0ac28
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 37 deletions.
3 changes: 3 additions & 0 deletions controlpanel/api/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def update_helm_repository(force=False):
_execute("repo", "update", timeout=None) # timeout = infinity.


# TODO no longer used, remove
def get_default_image_tag_from_helm_chart(chart_url, chart_name):
proc = _execute("show", "values", chart_url)
if proc:
Expand All @@ -171,6 +172,8 @@ def get_default_image_tag_from_helm_chart(chart_url, chart_name):
return None


# TODO this is no longer called from the Your Tools page
# consider removing as part of further refactoring
def get_helm_entries():
# Update repository metadata.
update_helm_repository()
Expand Down
2 changes: 2 additions & 0 deletions controlpanel/api/models/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def url(self, user):
def save(self, *args, **kwargs):
helm.update_helm_repository(force=True)

# TODO description is now required when creating a release, so this is unlikely to be called
# Consider removing
if not self.description:
self.description = helm.get_chart_app_version(self.chart_name, self.version) or ""

Expand Down
40 changes: 3 additions & 37 deletions controlpanel/frontend/views/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@

# First-party/Local
from controlpanel.api import cluster
from controlpanel.api.helm import (
get_chart_version_info,
get_default_image_tag_from_helm_chart,
get_helm_entries,
)
from controlpanel.api.models import Tool, ToolDeployment
from controlpanel.oidc import OIDCLoginRequiredMixin
from controlpanel.utils import start_background_task
Expand Down Expand Up @@ -85,10 +80,6 @@ def _add_new_item_to_tool_box(self, user, tool_box, tool, tools_info):
"deployment": None,
"releases": {},
}
# TODO We should update model to always store an image tag
# image_tag = tool.image_tag
# if not image_tag:
# image_tag = charts_info.get(tool.version, {}) or "unknown"
if tool.id not in tools_info[tool_box]["releases"]:
tools_info[tool_box]["releases"][tool.id] = {
"tool_id": tool.id,
Expand All @@ -110,6 +101,7 @@ def _add_deployed_charts_info(self, tools_info, user, id_token):
# Get list of deployed tools
# TODO this sets what tool the user currently has deployed. If we were to refactor to store
# deployed tools in the database, we could remove a lot of this logic
# See https://github.com/ministryofjustice/analytical-platform/issues/6266
deployments = cluster.ToolDeployment.get_deployments(user, id_token)
for deployment in deployments:
chart_name, chart_version = deployment.metadata.labels["chart"].rsplit("-", 1)
Expand Down Expand Up @@ -142,7 +134,8 @@ def _add_deployed_charts_info(self, tools_info, user, id_token):
}

def _retrieve_detail_tool_info(self, user, tools):
# TODO why do we need this? We could change so that all information required about available tools comes from the DB # noqa: E501
# TODO when deployed tools are tracked in the DB this will not be needed
# see https://github.com/ministryofjustice/analytical-platform/issues/6266 # noqa: E501
tools_info = {}
for tool in tools:
# Work out which bucket the chart should be in
Expand All @@ -152,31 +145,6 @@ def _retrieve_detail_tool_info(self, user, tools):
self._add_new_item_to_tool_box(user, tool_box, tool, tools_info)
return tools_info

def _get_charts_info(self, tool_list):
# We may need the default image_tag from helm chart
# unless we configure it specifically in parameters of tool release
# TODO if we make sure that we always have an image_tag for a tool, then building charts_info is redundant and could be removed # noqa: E501
charts_info = {}
chart_entries = None
for tool in tool_list:
if tool.version in charts_info:
continue

image_tag = tool.image_tag
if image_tag:
continue

if chart_entries is None:
# load the potential massive helm chart yaml only it is necessary
chart_entries = get_helm_entries()
chart_app_version = get_chart_version_info(chart_entries, tool.chart_name, tool.version)
if chart_app_version:
image_tag = get_default_image_tag_from_helm_chart(
chart_app_version.chart_url, tool.chart_name
)
charts_info[tool.version] = image_tag
return charts_info

def get_context_data(self, *args, **kwargs):
"""
Retrieve information about tools and arrange them for the
Expand Down Expand Up @@ -238,8 +206,6 @@ def get_context_data(self, *args, **kwargs):
context["managed_airflow_dev_url"] = f"{settings.AWS_SERVICE_URL}/?{args_airflow_dev_url}"
context["managed_airflow_prod_url"] = f"{settings.AWS_SERVICE_URL}/?{args_airflow_prod_url}"

# Arrange tools information
# charts_info = self._get_charts_info(context["tools"])
tools_info = self._retrieve_detail_tool_info(user, context["tools"])

if "vscode" in tools_info:
Expand Down

0 comments on commit 1e0ac28

Please sign in to comment.