Skip to content

Commit 1e48870

Browse files
Add konflux_utils module to monitor Konflux Pipelineruns
CLOUDDST-28645 Signed-off-by: Yashvardhan Nanavati <[email protected]> Assisted-by: Cursor Signed-off-by: Yashvardhan Nanavati <[email protected]>
1 parent be76a3c commit 1e48870

File tree

6 files changed

+1129
-1
lines changed

6 files changed

+1129
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,17 @@ The custom configuration options for the Celery workers are listed below:
446446
* `iib_ocp_opm_mapping` - the dictionary mapping of OCP version to OPM version
447447
indicating the OPM version to be used for the corresponding OCP version like
448448
`{"v4.15": "opm-v1.28.0"}`
449+
* `iib_konflux_cluster_url` - the URL of the Konflux OpenShift cluster to access for Tekton PipelineRuns
450+
(e.g. `https://api.konflux.example.com:6443`). This is required for cross-cluster access to Konflux.
451+
* `iib_konflux_cluster_token` - the authentication token for accessing the Konflux OpenShift cluster.
452+
This should be a service account token with appropriate permissions to access Tekton PipelineRuns.
453+
* `iib_konflux_cluster_ca_cert` - the CA certificate for the Konflux OpenShift cluster. This can be
454+
either a file path to the certificate or the certificate content as a string. This is required
455+
for secure cross-cluster access.
456+
* `iib_konflux_namespace` - the namespace in the Konflux cluster where Tekton PipelineRuns are located.
457+
This is required when using Konflux configuration.
458+
* `iib_konflux_pipeline_timeout` - the timeout in seconds for monitoring Konflux PipelineRuns.
459+
This defaults to `1800` seconds (30 minutes).
449460

450461

451462
If you wish to configure AWS S3 bucket for storing artifact files, the following **environment variables**

iib/workers/config.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ class Config(object):
127127
# The minimal version of OPM which requires setting the --migrate-level flag for migrate
128128
iib_opm_new_migrate_version = "v1.46.0"
129129

130+
# Konflux configuration for cross-cluster access
131+
iib_konflux_cluster_url: Optional[str] = None
132+
iib_konflux_cluster_token: Optional[str] = None
133+
iib_konflux_cluster_ca_cert: Optional[str] = None
134+
iib_konflux_namespace: Optional[str] = None
135+
iib_konflux_pipeline_timeout: int = 1800
136+
130137

131138
class ProductionConfig(Config):
132139
"""The production IIB Celery configuration."""
@@ -326,6 +333,7 @@ def validate_celery_config(conf: app.utils.Settings, **kwargs) -> None:
326333

327334
_validate_multiple_opm_mapping(conf['iib_ocp_opm_mapping'])
328335
_validate_iib_org_customizations(conf['iib_organization_customizations'])
336+
_validate_konflux_config(conf)
329337

330338
if conf.get('iib_aws_s3_bucket_name'):
331339
if not isinstance(conf['iib_aws_s3_bucket_name'], str):
@@ -481,6 +489,63 @@ def _validate_iib_org_customizations(
481489
)
482490

483491

492+
def _validate_konflux_config(conf: app.utils.Settings) -> None:
493+
"""
494+
Validate Konflux configuration variables.
495+
496+
:param celery.app.utils.Settings conf: the Celery application configuration to validate
497+
:raises iib.exceptions.ConfigError: if the configuration is invalid
498+
"""
499+
konflux_url = conf.get('iib_konflux_cluster_url')
500+
konflux_token = conf.get('iib_konflux_cluster_token')
501+
konflux_ca_cert = conf.get('iib_konflux_cluster_ca_cert')
502+
konflux_namespace = conf.get('iib_konflux_namespace')
503+
504+
if any([konflux_url, konflux_token, konflux_ca_cert, konflux_namespace]):
505+
_validate_konflux_fields(konflux_url, konflux_token, konflux_ca_cert, konflux_namespace)
506+
507+
508+
def _validate_konflux_fields(
509+
konflux_url: Optional[str],
510+
konflux_token: Optional[str],
511+
konflux_ca_cert: Optional[str],
512+
konflux_namespace: Optional[str],
513+
) -> None:
514+
"""
515+
Validate Konflux configuration fields for presence, types, and formats.
516+
517+
:param str konflux_url: The Kubernetes cluster API URL
518+
:param str konflux_token: The authentication token for the cluster
519+
:param str konflux_ca_cert: The CA certificate for SSL verification
520+
:param str konflux_namespace: The namespace for Konflux operations
521+
:raises iib.exceptions.ConfigError: if the configuration is invalid
522+
"""
523+
if (
524+
not konflux_url
525+
or not isinstance(konflux_url, str)
526+
or not konflux_url.startswith('https://')
527+
):
528+
raise ConfigError(
529+
'iib_konflux_cluster_url must be a valid HTTPS URL when using Konflux configuration'
530+
)
531+
if not konflux_token or not isinstance(konflux_token, str):
532+
raise ConfigError(
533+
'iib_konflux_cluster_token must be a string when using Konflux configuration'
534+
)
535+
if not konflux_ca_cert or not isinstance(konflux_ca_cert, str):
536+
raise ConfigError(
537+
'iib_konflux_cluster_ca_cert must be a string when using Konflux configuration'
538+
)
539+
if (
540+
not konflux_namespace
541+
or not isinstance(konflux_namespace, str)
542+
or not konflux_namespace.strip()
543+
):
544+
raise ConfigError(
545+
'iib_konflux_namespace must be a non-empty string when using Konflux configuration'
546+
)
547+
548+
484549
def get_worker_config() -> app.utils.Settings:
485550
"""Return the Celery configuration."""
486551
# Import this here to avoid a circular import

0 commit comments

Comments
 (0)