generated from ContainerCraft/devcontainer
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dynamic helm chart version lookup
- Loading branch information
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pulumi>=3 | ||
pulumi_kubernetes>=4.4.0 | ||
pulumi_kubernetes>=4.4.0beautifulsoup4 | ||
pyyaml | ||
packaging | ||
|
Empty file.
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,47 @@ | ||
import requests | ||
import logging | ||
import yaml | ||
from packaging.version import parse as parse_version, InvalidVersion, Version | ||
|
||
# Set up basic logging | ||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | ||
|
||
def is_stable_version(version_str): | ||
"""Check if the version string is a valid and stable semantic version.""" | ||
try: | ||
parsed_version = parse_version(version_str) | ||
# Check if it's a stable version (no pre-release or dev metadata) | ||
return isinstance(parsed_version, Version) and not parsed_version.is_prerelease and not parsed_version.is_devrelease | ||
except InvalidVersion: | ||
return False | ||
|
||
def get_latest_helm_chart_version(url, chart_name): | ||
try: | ||
logging.info(f"Fetching URL: {url}") | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
|
||
# Parse the YAML content | ||
index = yaml.safe_load(response.content) | ||
if chart_name in index['entries']: | ||
chart_versions = index['entries'][chart_name] | ||
# Filter out non-stable versions and sort | ||
stable_versions = [v for v in chart_versions if is_stable_version(v['version'])] | ||
if not stable_versions: | ||
logging.info(f"No stable versions found for chart '{chart_name}'.") | ||
return "No stable version found" | ||
latest_chart = max(stable_versions, key=lambda x: parse_version(x['version'])) | ||
return latest_chart['version'] | ||
else: | ||
logging.info(f"No chart named '{chart_name}' found in repository.") | ||
return "Chart not found" | ||
|
||
except requests.RequestException as e: | ||
logging.error(f"Error fetching data: {e}") | ||
return f"Error fetching data: {e}" | ||
|
||
# Example usage | ||
url = "https://raw.githubusercontent.com/cilium/charts/master/index.yaml" | ||
chart = "cilium" | ||
latest_version = get_latest_helm_chart_version(url, chart) | ||
print(f"The latest version of {chart} is: {latest_version}") |