Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ olm/catalog/
olm/subscriptions/
olm/catalog-source.yaml
stackable-bcrypt/target
__pycache__/

# Nix stuff
.envrc
Expand Down
33 changes: 33 additions & 0 deletions olm/build-manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ def generate_manifests(args: argparse.Namespace) -> list[dict]:
args, manifests
)
cluster_permissions = [(op_service_account["metadata"]["name"], op_cluster_role)]
op_role = find_op_role(args, manifests)
permissions = (
[(op_service_account["metadata"]["name"], op_role)] if op_role else []
)
deployments = [op_deployment]

related_images = generate_csv_related_images(
Expand All @@ -284,6 +288,7 @@ def generate_manifests(args: argparse.Namespace) -> list[dict]:
csv = generate_csv(
args,
cluster_permissions,
permissions,
deployments,
related_images,
)
Expand Down Expand Up @@ -319,6 +324,23 @@ def filter_op_objects(args: argparse.Namespace, manifests) -> tuple[dict, dict,
return tuple(result)


def find_op_role(args: argparse.Namespace, manifests: list[dict]) -> dict | None:
"""Returns the operator role, which only operators that need permissions in their own
namespace have (e.g. commons-operator).

Its RoleBinding is not needed, as OLM binds the role to the operator service account itself.
Any other Role would be dropped silently, so it is rejected instead.
"""
name = f"{args.op_name}-role"
roles = [m for m in manifests if m["kind"] == "Role"]
unexpected = [r["metadata"]["name"] for r in roles if r["metadata"]["name"] != name]
if unexpected:
raise ManifestException(
f"Unexpected Roles {unexpected} in Helm templates, only '{name}' is embedded in the CSV"
)
return roles[0] if roles else None


def write_manifests(args: argparse.Namespace, manifests: list[dict]) -> None:
"""Write the manifests to the certification repository."""
try:
Expand All @@ -333,6 +355,7 @@ def write_manifests(args: argparse.Namespace, manifests: list[dict]) -> None:
# - config maps
# The other objects are embedded in the CSV. These are:
# - the operator cluster role (N.B. some products have more than one cluster role e.g. HDFS)
# - the operator role, if any (its RoleBinding is created by OLM)
# - the operator deployment
for m in manifests:
dest_file = None
Expand Down Expand Up @@ -374,6 +397,7 @@ def write_manifests(args: argparse.Namespace, manifests: list[dict]) -> None:
def generate_csv(
args: argparse.Namespace,
cluster_permissions: list[tuple[str, dict]],
permissions: list[tuple[str, dict]],
deployments: list[dict],
related_images: list[dict[str, str]],
) -> dict:
Expand Down Expand Up @@ -420,6 +444,15 @@ def generate_csv(
}
for service_account, cluster_role in cluster_permissions
]
# OLM creates these as a Role in the operator namespace and copies it into every namespace the
# OperatorGroup targets. For an AllNamespaces OperatorGroup it creates a ClusterRole instead.
result["spec"]["install"]["spec"]["permissions"] = [
{
"serviceAccountName": service_account,
"rules": role["rules"],
}
for service_account, role in permissions
]
### 4. Add deployments
result["spec"]["install"]["spec"]["deployments"] = [
{
Expand Down