Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imagestream generator fixes #120

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions ocp-stream-generator/ocp-stream-generator/distribution_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,34 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

images = {"RHEL 7": "registry.redhat.io/rhscl/APP_NAME-APP_VERSION-rhel7:latest",
"RHEL 8": "registry.redhat.io/rhel8/APP_NAME-APP_VERSION:latest",
"RHEL 9": "registry.redhat.io/rhel9/APP_NAME-APP_VERSION:latest",
"UBI 7": "registry.redhat.io/ubi7/APP_NAME-APP_VERSION:latest",
"UBI 8": "registry.redhat.io/ubi8/APP_NAME-APP_VERSION:latest",
"UBI 9": "registry.redhat.io/ubi9/APP_NAME-APP_VERSION:latest",
"CentOS Stream 8": "quay.io/sclorg/APP_NAME-APP_VERSION-c8s:latest",
"CentOS Stream 9": "quay.io/sclorg/APP_NAME-APP_VERSION-c9s:latest"}
images = {"RHEL 7": {
"private": "registry.redhat.io/rhscl/APP_NAME-APP_VERSION-rhel7:latest"
},
"RHEL 8": {
"private": "registry.redhat.io/rhel8/APP_NAME-APP_VERSION:latest"
},
"RHEL 9": {
"private": "registry.redhat.io/rhel9/APP_NAME-APP_VERSION:latest"
},
"UBI 7": {
"private": "registry.redhat.io/ubi7/APP_NAME-APP_VERSION:latest",
"public": "registry.access.redhat.com/ubi7/APP_NAME-APP_VERSION:latest"
},
"UBI 8": {
"private": "registry.redhat.io/ubi8/APP_NAME-APP_VERSION:latest",
"public": "registry.access.redhat.com/ubi8/APP_NAME-APP_VERSION:latest"
},
"UBI 9": {
"private": "registry.redhat.io/ubi9/APP_NAME-APP_VERSION:latest",
"public": "registry.access.redhat.com/ubi9/APP_NAME-APP_VERSION:latest"
},
"CentOS Stream 8": {
"public": "quay.io/sclorg/APP_NAME-APP_VERSION-c8s:latest"
},
"CentOS Stream 9": {
"public": "quay.io/sclorg/APP_NAME-APP_VERSION-c9s:latest"
}
}

abbreviations ={"RHEL 7": "el7",
"RHEL 8": "el8",
Expand Down
15 changes: 10 additions & 5 deletions ocp-stream-generator/ocp-stream-generator/stream_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,18 @@ def __init__(self, file, header):
self.app_name = header["name"]
self.app_pretty_name = header["pretty_name"]
self.filename = file["filename"]
# hack - UBI images are both in public and private repos, need to
# distinguish between them based on filename
repo_access = "public" if "centos" in self.filename else "private"
self.tags = []
for distro in file["distros"]:
for app_version in distro["app_versions"]:
_tag = Tag(header, distro["name"], version=app_version)
_tag = Tag(header, distro["name"], repo_access, version=app_version)
self.tags.append(_tag)
_latest_distro = self.obtain_distro_for_latest(file["latest"]);
if not _latest_distro:
return
self.latest_tag = Tag(header, _latest_distro, latest=file["latest"])
self.latest_tag = Tag(header, _latest_distro, repo_access, latest=file["latest"])


class Tag:
Expand All @@ -90,6 +93,7 @@ class Tag:
app_pretty_name: str
latest = None
category: str
repo_access = None

def obtain_stream_name(self):
if self.latest:
Expand All @@ -107,11 +111,12 @@ def obtain_image(self):
if self.latest:
return self.latest
else:
return images[self.distro_name] \
.replace("APP_VERSION", str(self.version)) \
return images[self.distro_name][self.repo_access] \
.replace("APP_VERSION", str(self.version).replace(".","")) \
.replace("APP_NAME", self.app_name)

def __init__(self, header, distro_name, version=None, latest=None):
def __init__(self, header, distro_name, repo_access, version=None, latest=None):
self.repo_access = repo_access
self.category = header["category"]
self.app_name = header["name"]
self.app_pretty_name = header["pretty_name"]
Expand Down
8 changes: 4 additions & 4 deletions ocp-stream-generator/tests/test_json_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@


def test_add_tag():
tag = Tag(header, "RHEL 8", version=1)
tag = Tag(header, "RHEL 8", "private", version=1)
assert builder.add_tag({"spec": { "tags": []}}, tag) == add_tag_result

def test_add_latest_tag():
tag_latest = Tag(header, "RHEL8", latest="1-el8")
tag_latest = Tag(header, "RHEL8", "private", latest="1-el8")
assert builder.add_tag({"spec": { "tags": []}}, tag_latest) == add_tag_latest_result

def test_create_annotation():
tag = Tag(header, "RHEL 8", version=1)
tag = Tag(header, "RHEL 8", "private", version=1)
assert builder.create_annotation(tag) == create_annotation_result

def test_create_annotation_latest():
latest_tag = Tag(header, "RHEL 8", latest="1-el8")
latest_tag = Tag(header, "RHEL 8", "private", latest="1-el8")
assert builder.create_annotation(latest_tag) == create_annotation_latest_result

def test_create_header():
Expand Down
Loading