Skip to content

Commit 6c4b3d4

Browse files
init
1 parent c298124 commit 6c4b3d4

16 files changed

+152
-60
lines changed

components.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ components:
1111
name: openshift/assisted-service
1212
image_pattern: quay.io/edge-infrastructure/assisted-service
1313
versioning_selection_mechanism: commit
14+
- repository: https://github.com/openshift/assisted-service
15+
name: openshift/assisted-service-el8
16+
image_pattern: quay.io/edge-infrastructure/assisted-service-el8
17+
versioning_selection_mechanism: commit
1418
- repository: https://github.com/openshift/assisted-image-service
1519
name: openshift/assisted-image-service
1620
image_pattern: quay.io/edge-infrastructure/assisted-image-service

hack/versions-management/core/clients/image_registry_client.py

+19
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,22 @@ def exists(self, image: str, tag: str) -> bool:
1818
except Exception as e:
1919
logger.error(f"Error checking image {image} existence: {e}")
2020
return False
21+
22+
def resolve_digest(self, image: str, tag: str) -> str | None:
23+
path = image.replace("quay.io/", "")
24+
url = f"{self.registry_url}/v2/{path}/manifests/{tag}"
25+
headers = {"Accept": "application/vnd.docker.distribution.manifest.v2+json"}
26+
27+
try:
28+
response = requests.get(url, headers=headers)
29+
if response.status_code == 200:
30+
digest = response.headers.get("Docker-Content-Digest")
31+
if digest:
32+
return digest
33+
else:
34+
logger.warning(f"No digest found in headers for {image}:{tag}")
35+
else:
36+
logger.warning(f"Failed to resolve digest: {image}:{tag} (status code {response.status_code})")
37+
except Exception as e:
38+
logger.error(f"Error resolving digest for {image}:{tag}: {e}")
39+
return None

hack/versions-management/core/repositories/version_repository.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, file_path: str):
1111

1212
def find_all(self) -> list[Version]:
1313
if not os.path.isfile(self.file_path):
14-
return []
14+
raise Exception("versions.yaml file is required")
1515
with open(self.file_path, "r") as f:
1616
data = self.yaml.load(f)
1717
try:

hack/versions-management/core/services/ansible_test_runner_service.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
from dataclasses import replace
44
from typing import override
5-
from zlib import compressobj
65

76
from core.clients.ansible_client import AnsibleClient
87
from core.models import Snapshot
@@ -29,7 +28,7 @@ def run(self) -> None:
2928
self.export_env(pending_snapshot)
3029

3130
try:
32-
self.ansible.run_playbook("test/ansible/run_test.yaml", "test/ansible/inventory.yaml")
31+
self.ansible.run_playbook("test/playbooks/run_test.yaml", "test/playbooks/inventories/remote_host.yaml")
3332
updated = replace(pending_snapshot.metadata, status="successful")
3433
except Exception:
3534
updated = replace(pending_snapshot.metadata, status="failed")
@@ -42,6 +41,7 @@ def export_env(self, snapshot: Snapshot) -> None:
4241
"kubernetes-sigs/cluster-api": "CAPI_VERSION",
4342
"metal3-io/cluster-api-provider-metal3": "CAPM3_VERSION",
4443
"quay.io/edge-infrastructure/assisted-service": "ASSISTED_SERVICE_IMAGE",
44+
"quay.io/edge-infrastructure/assisted-service-el8": "ASSISTED_SERVICE_EL8_IMAGE",
4545
"quay.io/edge-infrastructure/assisted-image-service": "ASSISTED_IMAGE_SERVICE_IMAGE",
4646
"quay.io/edge-infrastructure/assisted-installer-agent": "ASSISTED_INSTALLER_AGENT_IMAGE",
4747
"quay.io/edge-infrastructure/assisted-installer-controller": "ASSISTED_INSTALLER_CONTROLLER_IMAGE",
@@ -56,10 +56,12 @@ def export_env(self, snapshot: Snapshot) -> None:
5656
os.environ[env_key] = comp.ref
5757
self.logger.info(f"Exported {env_key}={comp.ref}")
5858
case "commit":
59-
image_key = comp.image_url.split(":")[0]
59+
image_key = comp.image_url.split("@")[0]
6060
env_key = name_map.get(image_key)
6161
if env_key:
6262
os.environ[env_key] = comp.image_url
6363
self.logger.info(f"Exported {env_key}={comp.image_url}")
64+
else:
65+
self.logger.warning(f"No environment variable mapping found for {comp.name}")
6466
case _:
65-
raise Exception("Unsupported versioning selection mechanism")
67+
raise Exception(f"Unsupported versioning selection mechanism: {comp.versioning_selection_mechanism}")

hack/versions-management/core/services/tag_reconciliation_service.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TagReconciliationService(Service):
1010
def __init__(self, versions_file_path: str, dry_run: bool):
1111
self.github: GitHubClient = GitHubClient()
1212
self.versions_repo: VersionRepository = VersionRepository(versions_file_path)
13-
self.logger: logging.Logger = setup_logger("TagReconcilerService")
13+
self.logger: logging.Logger = setup_logger("TagReconciliationService")
1414
self.dry_run: bool = dry_run
1515

1616
@override

hack/versions-management/core/services/version_discovery_service.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import hashlib
22
import logging
33
from datetime import datetime
4-
from os import name
54
from typing import override
65
from concurrent.futures import ThreadPoolExecutor
76

@@ -75,20 +74,20 @@ def process_repository(
7574
name=component.name,
7675
image_url=None,
7776
)
78-
elif component.versioning_selection_mechanism == "commit":
77+
elif component.versioning_selection_mechanism == "commit" and img_pattern:
7978
self.logger.info(f"Checking commits of component {component.name}")
8079
for commit in gh_repo.get_commits()[:20]:
8180
sha = commit.sha
8281
tag = f"latest-{sha}"
83-
img = f"{img_pattern}"
84-
if self.registry.exists(img, tag):
82+
if self.registry.exists(img_pattern, tag):
83+
digest = self.registry.resolve_digest(img_pattern, tag)
8584
self.logger.info(f"Found commit {sha} for repository {repo}")
8685
return Artifact(
8786
repository=f"https://github.com/{repo}",
8887
ref=sha,
8988
versioning_selection_mechanism=component.versioning_selection_mechanism,
9089
name=component.name,
91-
image_url=f"{img}:{tag}",
90+
image_url=f"{img_pattern}@{digest}",
9291
)
9392
else:
9493
raise Exception(f"Versioning mechanism of component {component.repository} is not supported")

hack/versions-management/test/assets/components.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ components:
1111
name: openshift/assisted-service
1212
image_pattern: quay.io/edge-infrastructure/assisted-service
1313
versioning_selection_mechanism: commit
14+
- repository: https://github.com/openshift/assisted-service
15+
name: openshift/assisted-service-el8
16+
image_pattern: quay.io/edge-infrastructure/assisted-service-el8
17+
versioning_selection_mechanism: commit
1418
- repository: https://github.com/openshift/assisted-image-service
1519
name: openshift/assisted-image-service
1620
image_pattern: quay.io/edge-infrastructure/assisted-image-service

hack/versions-management/test/assets/release-candidates.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ snapshots:
1919
name: openshift/assisted-service
2020
versioning_selection_mechanism: commit
2121
image_url: quay.io/edge-infrastructure/assisted-service:latest-76d29d2a7f0899dcede9700fc88fcbad37b6ccca
22+
- repository: https://github.com/openshift/assisted-service
23+
ref: 76d29d2a7f0899dcede9700fc88fcbad37b6ccca
24+
name: openshift/assisted-service-el8
25+
versioning_selection_mechanism: commit
26+
image_url: quay.io/edge-infrastructure/assisted-service-el8:latest-76d29d2a7f0899dcede9700fc88fcbad37b6ccca
2227
- repository: https://github.com/openshift/assisted-image-service
2328
ref: 2249c85d05600191b24e93dd92e733d49a1180ec
2429
name: openshift/assisted-image-service

hack/versions-management/test/assets/versions.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ versions:
1616
name: openshift/assisted-service
1717
versioning_selection_mechanism: commit
1818
image_url: quay.io/edge-infrastructure/assisted-service:latest-76d29d2a7f0899dcede9700fc88fcbad37b6ccca
19+
- repository: https://github.com/openshift/assisted-service
20+
ref: 76d29d2a7f0899dcede9700fc88fcbad37b6ccca
21+
name: openshift/assisted-service-el8
22+
versioning_selection_mechanism: commit
23+
image_url: quay.io/edge-infrastructure/assisted-service-el8:latest-76d29d2a7f0899dcede9700fc88fcbad37b6ccca
1924
- repository: https://github.com/openshift/assisted-image-service
2025
ref: 2249c85d05600191b24e93dd92e733d49a1180ec
2126
name: openshift/assisted-image-service

hack/versions-management/test/repositories/test_release_repository.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ def test_release_repository_find_all(snapshots_file):
3131
assert snapshot.metadata.status == "pending"
3232
assert snapshot.metadata.generated_at == datetime.fromisoformat("2025-03-10T10:32:04.642635")
3333

34-
assert len(snapshot.artifacts) == 7
34+
assert len(snapshot.artifacts) == 8
3535
assert snapshot.artifacts[0].repository == "https://github.com/kubernetes-sigs/cluster-api"
3636
assert snapshot.artifacts[1].repository == "https://github.com/metal3-io/cluster-api-provider-metal3"
3737
assert snapshot.artifacts[2].repository == "https://github.com/openshift/assisted-service"
38-
assert snapshot.artifacts[3].repository == "https://github.com/openshift/assisted-image-service"
39-
assert snapshot.artifacts[4].repository == "https://github.com/openshift/assisted-installer-agent"
40-
assert snapshot.artifacts[5].repository == "https://github.com/openshift/assisted-installer"
38+
assert snapshot.artifacts[3].repository == "https://github.com/openshift/assisted-service"
39+
assert snapshot.artifacts[4].repository == "https://github.com/openshift/assisted-image-service"
40+
assert snapshot.artifacts[5].repository == "https://github.com/openshift/assisted-installer-agent"
4141
assert snapshot.artifacts[6].repository == "https://github.com/openshift/assisted-installer"
42+
assert snapshot.artifacts[7].repository == "https://github.com/openshift/assisted-installer"
4243

4344

4445
def test_release_repository_find_by_id(snapshots_file):

hack/versions-management/test/repositories/test_version_repository.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_version_repository_find_all(versions_file):
2323
version = versions[0]
2424

2525
assert version.name == "v0.0.1"
26-
assert len(version.artifacts) == 7
26+
assert len(version.artifacts) == 8
2727

2828
assert version.artifacts[0].repository == "https://github.com/kubernetes-sigs/cluster-api"
2929
assert version.artifacts[2].image_url.startswith("quay.io/edge-infrastructure/assisted-service")
@@ -36,3 +36,11 @@ def test_invalid_versions_file_schema(tmp_path):
3636
repo = VersionRepository(str(bad_file))
3737
with pytest.raises(ValueError, match="Invalid versions.yaml structure"):
3838
repo.find_all()
39+
40+
41+
def test_non_existent_versions_file(tmp_path):
42+
non_existent_file = tmp_path / "non_existent.yaml"
43+
44+
repo = VersionRepository(str(non_existent_file))
45+
with pytest.raises(Exception, match="versions.yaml file is required"):
46+
repo.find_all()

hack/versions-management/test/services/test_ansible_test_runner_service.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,42 @@ def service_with_pending(snapshots_file):
107107
ref="ref",
108108
name="openshift/assisted-service",
109109
versioning_selection_mechanism="commit",
110-
image_url="quay.io/edge-infrastructure/assisted-service:latest-tag"
110+
image_url="quay.io/edge-infrastructure/assisted-service@sha256:latestref"
111+
),
112+
Artifact(
113+
repository="https://github.com/openshift/assisted-service",
114+
ref="ref",
115+
name="openshift/assisted-service-el8",
116+
versioning_selection_mechanism="commit",
117+
image_url="quay.io/edge-infrastructure/assisted-service-el8@sha256:latestref"
111118
),
112119
Artifact(
113120
repository="https://github.com/openshift/assisted-image-service",
114121
ref="ref",
115122
name="openshift/assisted-image-service",
116123
versioning_selection_mechanism="commit",
117-
image_url="quay.io/edge-infrastructure/assisted-image-service:latest-tag"
124+
image_url="quay.io/edge-infrastructure/assisted-image-service@sha256:latestref"
118125
),
119126
Artifact(
120127
repository="https://github.com/openshift/assisted-installer-agent",
121128
ref="ref",
122129
name="openshift/assisted-installer-agent",
123130
versioning_selection_mechanism="commit",
124-
image_url="quay.io/edge-infrastructure/assisted-installer-agent:latest-tag"
131+
image_url="quay.io/edge-infrastructure/assisted-installer-agent@sha256:latestref"
125132
),
126133
Artifact(
127134
repository="https://github.com/openshift/assisted-installer",
128135
ref="ref",
129136
name="openshift/assisted-installer-controller",
130137
versioning_selection_mechanism="commit",
131-
image_url="quay.io/edge-infrastructure/assisted-installer-controller:latest-tag"
138+
image_url="quay.io/edge-infrastructure/assisted-installer-controller@sha256:latestref"
132139
),
133140
Artifact(
134141
repository="https://github.com/openshift/assisted-installer",
135142
ref="ref",
136143
name="openshift/assisted-installer",
137144
versioning_selection_mechanism="commit",
138-
image_url="quay.io/edge-infrastructure/assisted-installer:latest-tag"
145+
image_url="quay.io/edge-infrastructure/assisted-installer@sha256:latestref"
139146
)
140147
]
141148
)
@@ -156,26 +163,27 @@ def test_export_env_variables(service_with_pending):
156163

157164
assert os.environ.get("CAPI_VERSION") == "ref"
158165
assert os.environ.get("CAPM3_VERSION") == "ref"
159-
assert os.environ.get("ASSISTED_SERVICE_IMAGE") == "quay.io/edge-infrastructure/assisted-service:latest-tag"
160-
assert os.environ.get("ASSISTED_IMAGE_SERVICE_IMAGE") == "quay.io/edge-infrastructure/assisted-image-service:latest-tag"
161-
assert os.environ.get("ASSISTED_INSTALLER_AGENT_IMAGE") == "quay.io/edge-infrastructure/assisted-installer-agent:latest-tag"
162-
assert os.environ.get("ASSISTED_INSTALLER_CONTROLLER_IMAGE") == "quay.io/edge-infrastructure/assisted-installer-controller:latest-tag"
163-
assert os.environ.get("ASSISTED_INSTALLER_IMAGE") == "quay.io/edge-infrastructure/assisted-installer:latest-tag"
166+
assert os.environ.get("ASSISTED_SERVICE_IMAGE") == "quay.io/edge-infrastructure/assisted-service@sha256:latestref"
167+
assert os.environ.get("ASSISTED_SERVICE_EL8_IMAGE") == "quay.io/edge-infrastructure/assisted-service-el8@sha256:latestref"
168+
assert os.environ.get("ASSISTED_IMAGE_SERVICE_IMAGE") == "quay.io/edge-infrastructure/assisted-image-service@sha256:latestref"
169+
assert os.environ.get("ASSISTED_INSTALLER_AGENT_IMAGE") == "quay.io/edge-infrastructure/assisted-installer-agent@sha256:latestref"
170+
assert os.environ.get("ASSISTED_INSTALLER_CONTROLLER_IMAGE") == "quay.io/edge-infrastructure/assisted-installer-controller@sha256:latestref"
171+
assert os.environ.get("ASSISTED_INSTALLER_IMAGE") == "quay.io/edge-infrastructure/assisted-installer@sha256:latestref"
164172

165173

166174
def test_successful_test_run(service_with_pending):
167175
service_with_pending.run()
168176

169177
# Verify playbook was run
170178
service_with_pending.ansible.run_playbook.assert_called_with(
171-
"test/ansible/run_test.yaml", "test/ansible/inventory.yaml"
179+
"test/playbooks/run_test.yaml", "test/playbooks/inventories/remote_host.yaml"
172180
)
173181

174182
# Verify snapshot was updated
175183
assert service_with_pending.repo.update.call_count == 1
176184
updated_snapshot = service_with_pending.repo.update.call_args[0][0]
177185
assert updated_snapshot.metadata.status == "successful"
178-
assert len(updated_snapshot.artifacts) == 7
186+
assert len(updated_snapshot.artifacts) == 8
179187

180188

181189
def test_failed_test_run(service_with_pending):

0 commit comments

Comments
 (0)