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

[WiP] Local Bundles Cleanup #198

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 0 additions & 6 deletions managedtenants/core/addon_manager.py

This file was deleted.

85 changes: 0 additions & 85 deletions managedtenants/core/addons_loader/addon.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
from pathlib import Path

import jsonschema
import semver
import yaml
from jinja2 import FileSystemLoader
from sretoolbox.container import Image

from managedtenants.core.addon_manager import AddonManager
from managedtenants.core.addons_loader.bundle import Bundle
from managedtenants.core.addons_loader.exceptions import AddonLoadError
from managedtenants.core.addons_loader.package import Package
from managedtenants.core.addons_loader.sss import Sss
from managedtenants.data.paths import SCHEMAS_DIR
from managedtenants.utils.general_utils import parse_version_from_imageset_name
from managedtenants.utils.hash import hash_dir_sha256, hash_sha256
from managedtenants.utils.schema import load_schema

# IDs of addons that are managed by the addon-operator
# These addon IDs _MUST_ be stable and not changed or bad things will happen
# (this applies to addon IDs in general, but it's worth pointing out here, too)
_ADDON_OPERATOR_ADDON_IDS = []
_PERMITTED_SUBSCRIPTION_CONFIGS = ["env"]


Expand All @@ -44,7 +33,6 @@ def __init__(
self,
path,
environment,
override_manager=None,
imageset_latest_only=False,
):
self.path = path
Expand All @@ -57,8 +45,6 @@ def __init__(
if self.imageset_version is None:
self.imagesets_path = None
self.imageset = None
self.bundles = None
self.package = None
self.catalog_image = None
else:
if all(
Expand All @@ -77,35 +63,12 @@ def __init__(
self.path / f"addonimagesets/{environment}"
)
self.imageset = self.load_imageset(self.imageset_version)
self.package = None
self.bundles = None
self.catalog_image = self.imageset["indexImage"]

elif "indexImage" in self.metadata:
self.imagesets_path = None
self.imageset = None
self.bundles = None
self.package = None
self.catalog_image = self.metadata["indexImage"]
else:
# Local bundles doesn't exist anymore,
# we have to clean this up
self.imagesets_path = None
self.imageset = None
self.bundles = self.load_bundles(metadata=self.metadata)
self.package = Package(addon=self)
self.catalog_image = self.get_image_name(environment=environment)
self.image_tag = ( # Used with .format(hash=...)
f'{self.metadata["quayRepo"]}:{environment}-{{hash}}'
)

if self.metadata["id"] not in _ADDON_OPERATOR_ADDON_IDS:
self.manager = AddonManager.UKNOWN
else:
self.manager = AddonManager.ADDON_OPERATOR

if override_manager is not None:
self.manager = override_manager

self.sss = Sss(addon=self)

Expand All @@ -131,23 +94,6 @@ def get_subscription_config(self):
return self.imageset.get("subscriptionConfig")
return self.metadata.get("subscriptionConfig")

def get_image_name(self, environment):
"""
Creates a deterministic image name that is unique per
bundles + metadata hashed content.
"""
bundles_dir = self.path / "bundles"
bundles_hash = hash_dir_sha256(path=bundles_dir)

metadata_dir = self.path / "metadata" / environment
metadata_hash = hash_dir_sha256(path=metadata_dir)

hash_tag = hash_sha256(items=(bundles_hash, metadata_hash))

return Image(
f'{self.metadata["quayRepo"]}:{environment}-{hash_tag[:7]}'
)

def load_metadata(self, environment):
metadata_path = self.path / "metadata" / environment / "addon.yaml"
metadata_dir = self.path / "metadata" / environment
Expand Down Expand Up @@ -298,10 +244,6 @@ def _validate_extra_resources(self, environment, metadata):
f"referenced resource {resource_path} not found"
)

@staticmethod
def instantiate_bundle(args):
return Bundle(path=args[0], metadata=args[1])

@staticmethod
def load_yaml(path):
try:
Expand All @@ -311,33 +253,6 @@ def load_yaml(path):
except yaml.YAMLError:
return None

def load_bundles(self, metadata):
bundles_path = self.path / "bundles"

bundles_to_load = []
for item in sorted(filter(Path.is_dir, bundles_path.iterdir())):
if item.name == "OWNERS":
continue

bundles_to_load.append((item, metadata))

# force list to not lazily evaluate the returned iterator of map()
bundles = list(map(self.instantiate_bundle, bundles_to_load))

self._validate_bundle_names(bundles)

return bundles

@staticmethod
def _validate_bundle_names(bundles):
for bundle in bundles:
try:
semver.parse(bundle.path.name)
except ValueError as e:
raise AddonLoadError(
f"{bundle.path} directory must be a semantic version"
) from e

def __repr__(self):
return f"{self.__class__.__name__}({repr(self.name)})"

Expand Down
53 changes: 0 additions & 53 deletions managedtenants/core/addons_loader/bundle.py

This file was deleted.

72 changes: 0 additions & 72 deletions managedtenants/core/addons_loader/manifest.py

This file was deleted.

31 changes: 0 additions & 31 deletions managedtenants/core/addons_loader/package.py

This file was deleted.

5 changes: 1 addition & 4 deletions managedtenants/core/addons_loader/sss.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from jinja2.exceptions import UndefinedError
from sretoolbox.utils.logger import get_text_logger

from managedtenants.core.addon_manager import AddonManager
from managedtenants.core.addons_loader.exceptions import SssLoadError
from managedtenants.data.paths import DATA_DIR

Expand Down Expand Up @@ -49,9 +48,7 @@ def _get_data(self):
# pylint: disable=unnecessary-lambda
env.filters["merge_dicts"] = lambda d1, d2: ChainMap(d1, d2)
template = env.get_template(str(self._sss_filename))
content = template.render(
AddonManager=AddonManager, ADDON=self._addon
)
content = template.render(ADDON=self._addon)
except UndefinedError as details:
raise SssLoadError(
f"error templating {self._sss_filename}: {details.message}"
Expand Down
32 changes: 0 additions & 32 deletions managedtenants/data/selectorsyncset.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ metadata: {}
apiVersion: v1
items:
{# addon v1 create OLM resources manually #}
{% if ADDON.manager == AddonManager.UKNOWN %}
- apiVersion: hive.openshift.io/v1
kind: SelectorSyncSet
metadata:
Expand Down Expand Up @@ -214,37 +213,6 @@ items:
{{ expand_dict(ADDON.metadata['monitoring']['matchLabels']) | indent(12) }}
{% endif %}

{# addon v2 Addon CR is created by OCM, only secret management handled by SSS #}
{% elif ADDON.manager == AddonManager.ADDON_OPERATOR %}
- apiVersion: hive.openshift.io/v1
kind: SelectorSyncSet
metadata:
name: addon-{{ADDON.metadata['id']}}
spec:
clusterDeploymentSelector:
matchLabels:
{{ADDON.metadata['label']}}: 'true'
resourceApplyMode: Sync

resources:
{# TODO: move pullsecret management into the addon-operator #}
{% for namespace in ADDON.metadata['namespaces'] %}
{% if ADDON.metadata['pullSecret'] is defined %}
- apiVersion: v1
kind: Secret
metadata:
name: addon-{{ADDON.metadata['id']}}-pullsecret
namespace: {{namespace}}
labels:
addon-pullsecret: "{{ADDON.metadata['id']}}"
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: >-
{{ADDON.metadata['pullSecret']}}
{% endif %}
{% endfor %}
{% endif %}

- apiVersion: hive.openshift.io/v1
kind: SelectorSyncSet
metadata:
Expand Down
12 changes: 0 additions & 12 deletions tests/addons/test_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ def test_addon_metadata(addon, addon_type, request):
assert addon.metadata == load_yaml(addon.path / "metadata/stage/addon.yaml")


@pytest.mark.parametrize(
"addon,addon_type",
[
("addon_with_imageset", ADDON_WITH_IMAGESET_TYPE),
],
)
def test_addon_bundles(addon, addon_type, request):
"""Test that addon bundles are loaded or not."""
addon = request.getfixturevalue(addon)
assert addon.bundles is None


@pytest.mark.parametrize(
"addon,addon_type",
[
Expand Down
Loading