From 545457e9e05b3333b64fa53b492aafbc808dc942 Mon Sep 17 00:00:00 2001 From: Arie Peterson <arie@greenhost.nl> Date: Tue, 30 May 2023 16:23:05 +0200 Subject: [PATCH] Include flux git ref in info endpoint --- backend/areas/__init__.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/areas/__init__.py b/backend/areas/__init__.py index f14dde52..363d4e35 100644 --- a/backend/areas/__init__.py +++ b/backend/areas/__init__.py @@ -62,14 +62,27 @@ def api_info(): if 'version' in data: results['appVersions'][app] = data['version'] - # Get latest released version from gitlab. - git_release = requests.get("https://open.greenhost.net/stackspin/stackspin/-/raw/main/VERSION").text.rstrip() - results['lastRelease'] = git_release - # Get last update time of stackspin GitRepo object on the cluster; that # tells us when flux last updated the cluster based on changes in the # stackspin git repo. stackspin_repo = k8s.get_gitrepo('stackspin') results['lastUpdated'] = stackspin_repo['status']['artifact']['lastUpdateTime'] + # This is the branch (or other git ref, like tag or commit) that this + # cluster follows. + flux_ref = stackspin_repo['spec']['ref'] + results['followingGit'] = {} + results['followingGit']['object'] = stackspin_repo['spec']['ref'] + # The `flux_ref` is a structured object, though as far as we've seen always + # a dict with a single entry. (The key can be `branch` or `tag` or + # `commit`.) We need to reduce this to a single string git ref as well. + ref = next(iter(flux_ref.values())) + results['followingGit']['string'] = ref + + # Get latest released version from gitlab. Whether it's considered + # "released" depends on which branch we're following, but usually that's + # the `vX` "production" branch. + git_release = requests.get(f"https://open.greenhost.net/stackspin/stackspin/-/raw/{ref}/VERSION").text.rstrip() + results['lastRelease'] = git_release + return jsonify(results) -- GitLab