|
28 | 28 | Requirements: |
29 | 29 | - uv (https://docs.astral.sh/uv/) — installs PyYAML automatically |
30 | 30 | - helm (https://helm.sh) |
| 31 | + - git (createdAt is the commit date of the checked-out release tag) |
31 | 32 | """ |
32 | 33 |
|
33 | 34 | import argparse |
| 35 | +import datetime |
34 | 36 | import json |
35 | 37 | import logging |
36 | 38 | import os |
@@ -399,6 +401,7 @@ def generate_csv( |
399 | 401 | result["spec"]["minKubeVersion"] = min_kube_version(args.release) |
400 | 402 | result["metadata"]["name"] = f"{csv_name}.v{args.release}" |
401 | 403 | result["metadata"]["annotations"]["containerImage"] = related_images[0]["image"] |
| 404 | + result["metadata"]["annotations"]["createdAt"] = created_at(args.repo_operator) |
402 | 405 | result["metadata"]["annotations"]["description"] = chart["description"] |
403 | 406 | result["metadata"]["annotations"]["capabilities"] = listing["capabilities"] |
404 | 407 | result["metadata"]["annotations"]["categories"] = listing["categories"] |
@@ -431,6 +434,31 @@ def generate_csv( |
431 | 434 | return result |
432 | 435 |
|
433 | 436 |
|
| 437 | +def created_at(repo: pathlib.Path) -> str: |
| 438 | + """Return the commit date of the checked-out commit, so createdAt stays the same when the bundle is rebuilt.""" |
| 439 | + try: |
| 440 | + completed_proc = subprocess.run( |
| 441 | + ["git", "-C", str(repo), "log", "-1", "--format=%ct"], |
| 442 | + capture_output=True, |
| 443 | + check=True, |
| 444 | + ) |
| 445 | + except subprocess.CalledProcessError as e: |
| 446 | + logging.error(e.stderr.decode("utf-8")) |
| 447 | + raise ManifestException(f'Failed to read the commit date of "{repo}"') |
| 448 | + return format_created_at(int(completed_proc.stdout)) |
| 449 | + |
| 450 | + |
| 451 | +def format_created_at(epoch_seconds: int) -> str: |
| 452 | + """Format a Unix timestamp the way OLM bundles write createdAt, in UTC. |
| 453 | +
|
| 454 | + >>> format_created_at(1784628000) |
| 455 | + '2026-07-21T10:00:00Z' |
| 456 | + """ |
| 457 | + return datetime.datetime.fromtimestamp( |
| 458 | + epoch_seconds, tz=datetime.timezone.utc |
| 459 | + ).strftime("%Y-%m-%dT%H:%M:%SZ") |
| 460 | + |
| 461 | + |
434 | 462 | def load_chart(args: argparse.Namespace) -> dict: |
435 | 463 | chart_path = args.repo_operator / "deploy" / "helm" / args.op_name / "Chart.yaml" |
436 | 464 | return yaml.load(chart_path.read_text(), Loader=yaml.SafeLoader) |
|
0 commit comments