Skip to content

Commit

Permalink
openshift resources prometheus rules (#4411)
Browse files Browse the repository at this point in the history
Introduce openshift-prometheus-rules as a separate integration that handles prometheus rule for namespace openshiftResources. Similar to openshift-routes or openshift-vault-secrets. This will speed up app-interface PR checks.

Ticket: APPSRE-10344
  • Loading branch information
chassing authored Jun 3, 2024
1 parent f1cd436 commit 5e50ded
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Additional tools that use the libraries created by the reconciliations are also
openshift-namespace-labels Manages labels on OpenShift namespaces.
openshift-namespaces Manages OpenShift Namespaces.
openshift-network-policies Manages OpenShift NetworkPolicies.
openshift-prometheus-rules Manages OpenShift Prometheus Rules.
openshift-resourcequotas Manages OpenShift ResourceQuota objects.
openshift-resources Manages OpenShift Resources.
openshift-rolebindings Configures Rolebindings in OpenShift
Expand Down Expand Up @@ -212,6 +213,8 @@ Additional tools that use the libraries created by the reconciliations are also
to Status Board.
status-page-components Manages components on statuspage.io hosted
status pages.
status-page-maintenances Manages maintenances on statuspage.io hosted
status pages.
template-renderer Render datafile templates in app-interface.
template-validator Test app-interface templates.
terraform-aws-route53 Manage AWS Route53 resources using
Expand All @@ -227,7 +230,8 @@ Additional tools that use the libraries created by the reconciliations are also
terraform-users Manage AWS users using Terraform.
terraform-vpc-peerings Manage VPC peerings between OSD clusters and
AWS accounts or other OSD clusters.
terraform-vpc-resources Manage VPC creation through a VPC request.
terraform-vpc-resources Manage VPC creation
unleash-feature-toggles Manage Unleash feature toggles.
vault-replication Allow vault to replicate secrets to other
instances.
version-gate-approver Approves OCM cluster upgrade version gates.
Expand Down
25 changes: 25 additions & 0 deletions reconcile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,31 @@ def openshift_routes(
)


@integration.command(short_help="Manages OpenShift Prometheus Rules.")
@threaded()
@binary(["oc", "ssh"])
@binary_version("oc", ["version", "--client"], OC_VERSION_REGEX, OC_VERSIONS)
@internal()
@use_jump_host()
@cluster_name
@namespace_name
@click.pass_context
def openshift_prometheus_rules(
ctx, thread_pool_size, internal, use_jump_host, cluster_name, namespace_name
):
import reconcile.openshift_prometheus_rules

run_integration(
reconcile.openshift_prometheus_rules,
ctx.obj,
thread_pool_size,
internal,
use_jump_host,
cluster_name=cluster_name,
namespace_name=namespace_name,
)


@integration.command(short_help="Configures the teams and members in Quay.")
@click.pass_context
def quay_membership(ctx):
Expand Down
43 changes: 43 additions & 0 deletions reconcile/openshift_prometheus_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from collections.abc import Iterable
from typing import Any

import reconcile.openshift_resources_base as orb
from reconcile.utils.runtime.integration import DesiredStateShardConfig
from reconcile.utils.semver_helper import make_semver

QONTRACT_INTEGRATION = "openshift-prometheus-rules"
QONTRACT_INTEGRATION_VERSION = make_semver(1, 0, 0)
PROVIDERS = ["prometheus-rule"]


def run(
dry_run: bool,
thread_pool_size: int = 10,
internal: bool | None = None,
use_jump_host: bool = True,
cluster_name: Iterable[str] | None = None,
exclude_cluster: Iterable[str] | None = None,
namespace_name: str | None = None,
) -> None:
orb.QONTRACT_INTEGRATION = QONTRACT_INTEGRATION
orb.QONTRACT_INTEGRATION_VERSION = QONTRACT_INTEGRATION_VERSION

orb.run(
dry_run=dry_run,
thread_pool_size=thread_pool_size,
internal=internal,
use_jump_host=use_jump_host,
providers=PROVIDERS,
cluster_name=cluster_name,
exclude_cluster=exclude_cluster,
namespace_name=namespace_name,
init_api_resources=True,
)


def early_exit_desired_state(*args: Any, **kwargs: Any) -> dict[str, Any]:
return orb.early_exit_desired_state(PROVIDERS)


def desired_state_shard_config() -> DesiredStateShardConfig:
return orb.desired_state_shard_config()
2 changes: 1 addition & 1 deletion reconcile/openshift_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

QONTRACT_INTEGRATION = "openshift_resources"
QONTRACT_INTEGRATION_VERSION = make_semver(1, 9, 3)
PROVIDERS = ["resource", "resource-template", "prometheus-rule"]
PROVIDERS = ["resource", "resource-template"]


def run(
Expand Down
2 changes: 2 additions & 0 deletions reconcile/openshift_resources_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,8 @@ def canonicalize_namespaces(
override = ["Secret"]
elif providers[0] == "route":
override = ["Route"]
elif providers[0] == "prometheus-rule":
override = ["PrometheusRule"]

namespace_info["openshiftResources"] = ors
canonicalized_namespaces.append(namespace_info)
Expand Down

0 comments on commit 5e50ded

Please sign in to comment.