Skip to content

Commit

Permalink
pull metrics-server and metallb with update-component-versions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
eaudetcobello committed Jun 11, 2024
1 parent cb9cec1 commit 0533c05
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
1 change: 1 addition & 0 deletions build-scripts/components/metallb/repository
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://metallb.github.io/metallb
1 change: 1 addition & 0 deletions build-scripts/components/metrics-server/repository
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://kubernetes-sigs.github.io/metrics-server
35 changes: 34 additions & 1 deletion build-scripts/hack/update-component-versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

DIR = Path(__file__).absolute().parent
COMPONENTS = DIR.parent / "components"
MANIFESTS = DIR.parent.parent / "k8s" / "manifests" / "charts"

# Version marker for latest Kubernetes version. Expected to be one of:
#
Expand All @@ -36,6 +37,14 @@
# Helm release branch to track. The most recent tag in the branch will be used.
HELM_RELEASE_BRANCH = "release-3.14"

# MetalLB Helm repository and chart version
METALLB_HELM_REPO = "https://metallb.github.io/metallb"
METALLB_CHART_VERSION = "0.14.5"

# Metrics Server Helm repository
METRICS_SERVER_REPO = "https://kubernetes-sigs.github.io/metrics-server"
METRICS_SERVER_CHART_VERSION = "3.12.1"


def get_kubernetes_version() -> str:
"""Update Kubernetes version based on the specified marker file"""
Expand Down Expand Up @@ -64,7 +73,9 @@ def get_containerd_version() -> str:
"""Update containerd version using latest tag of specified branch"""
containerd_repo = util.read_file(COMPONENTS / "containerd/repository")

with util.git_repo(containerd_repo, CONTAINERD_RELEASE_BRANCH, shallow=False) as dir:
with util.git_repo(
containerd_repo, CONTAINERD_RELEASE_BRANCH, shallow=False
) as dir:
# Get the latest tagged release from the current branch
return util.parse_output(["git", "describe", "--tags", "--abbrev=0"], cwd=dir)

Expand All @@ -86,6 +97,20 @@ def get_helm_version() -> str:
return util.parse_output(["git", "describe", "--tags", "--abbrev=0"], cwd=dir)


def pull_metallb_chart() -> None:
LOG.info("Pulling MetalLB chart @ %s", METALLB_CHART_VERSION)
metallb_chart_repo = util.read_file(COMPONENTS / "metallb/repository")
util.helm_pull("metallb", metallb_chart_repo, METALLB_CHART_VERSION, MANIFESTS)


def pull_metrics_server_chart() -> None:
LOG.info("Pulling Metrics Server chart @ %s", METRICS_SERVER_CHART_VERSION)
metallb_chart_repo = util.read_file(COMPONENTS / "metrics-server/repository")
util.helm_pull(
"metrics-server", metallb_chart_repo, METRICS_SERVER_CHART_VERSION, MANIFESTS
)


def update_component_versions(dry_run: bool):
for component, get_version in [
("kubernetes", get_kubernetes_version),
Expand All @@ -101,6 +126,14 @@ def update_component_versions(dry_run: bool):
if not dry_run:
Path(path).write_text(version.strip() + "\n")

for component, pull_helm_chart in [
("metallb", pull_metallb_chart),
("metrics-server", pull_metrics_server_chart),
]:
LOG.info("Updating chart for %s", component)
if not dry_run:
pull_helm_chart()


def main():
parser = argparse.ArgumentParser(
Expand Down
10 changes: 0 additions & 10 deletions build-scripts/hack/update-metrics-server-chart.sh

This file was deleted.

7 changes: 7 additions & 0 deletions build-scripts/hack/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tempfile
import subprocess
import logging
import yaml
from urllib.request import urlopen
from pathlib import Path

Expand Down Expand Up @@ -48,3 +49,9 @@ def read_file(path: Path) -> str:

def read_url(url: str) -> str:
return urlopen(url).read().decode().strip()

def helm_pull(chart_name: str, repo_url: str, version: str, destination: Path) -> None:
parse_output(["helm", "repo", "add", chart_name, repo_url])
parse_output(["helm", "pull", f"{chart_name}/{chart_name}", "--version", version, "--destination", destination])

LOG.info("Pulled helm repository %s @ %s as %s to %s", repo_url, version, chart_name, destination)

0 comments on commit 0533c05

Please sign in to comment.