Skip to content

Commit 10f08b5

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 04e89bc commit 10f08b5

File tree

6 files changed

+845
-1
lines changed

6 files changed

+845
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ 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 defaults to `iib-tenant`.
449458

450459

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

iib/workers/config.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ 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: str = 'iib-tenant'
135+
130136

131137
class ProductionConfig(Config):
132138
"""The production IIB Celery configuration."""
@@ -326,6 +332,7 @@ def validate_celery_config(conf: app.utils.Settings, **kwargs) -> None:
326332

327333
_validate_multiple_opm_mapping(conf['iib_ocp_opm_mapping'])
328334
_validate_iib_org_customizations(conf['iib_organization_customizations'])
335+
_validate_konflux_config(conf)
329336

330337
if conf.get('iib_aws_s3_bucket_name'):
331338
if not isinstance(conf['iib_aws_s3_bucket_name'], str):
@@ -481,6 +488,46 @@ def _validate_iib_org_customizations(
481488
)
482489

483490

491+
def _validate_konflux_config(conf: app.utils.Settings) -> None:
492+
"""
493+
Validate Konflux configuration variables.
494+
495+
:param celery.app.utils.Settings conf: the Celery application configuration to validate
496+
:raises iib.exceptions.ConfigError: if the configuration is invalid
497+
"""
498+
konflux_url = conf.get('iib_konflux_cluster_url')
499+
konflux_token = conf.get('iib_konflux_cluster_token')
500+
konflux_ca_cert = conf.get('iib_konflux_cluster_ca_cert')
501+
502+
if any([konflux_url, konflux_token, konflux_ca_cert]):
503+
_validate_konflux_required_fields(konflux_url, konflux_token, konflux_ca_cert)
504+
_validate_konflux_field_types(konflux_url, konflux_token, konflux_ca_cert)
505+
506+
507+
def _validate_konflux_required_fields(konflux_url, konflux_token, konflux_ca_cert):
508+
"""Validate that all required Konflux fields are provided."""
509+
if not konflux_url:
510+
raise ConfigError('iib_konflux_cluster_url must be set when using Konflux configuration')
511+
if not konflux_token:
512+
raise ConfigError('iib_konflux_cluster_token must be set when using Konflux configuration')
513+
if not konflux_ca_cert:
514+
raise ConfigError(
515+
'iib_konflux_cluster_ca_cert must be set when using Konflux configuration'
516+
)
517+
518+
519+
def _validate_konflux_field_types(konflux_url, konflux_token, konflux_ca_cert):
520+
"""Validate the types and formats of Konflux configuration fields."""
521+
if not isinstance(konflux_url, str) or not konflux_url.startswith('https://'):
522+
raise ConfigError('iib_konflux_cluster_url must be a valid HTTPS URL')
523+
524+
if not isinstance(konflux_token, str):
525+
raise ConfigError('iib_konflux_cluster_token must be a string')
526+
527+
if not isinstance(konflux_ca_cert, str):
528+
raise ConfigError('iib_konflux_cluster_ca_cert must be a string')
529+
530+
484531
def get_worker_config() -> app.utils.Settings:
485532
"""Return the Celery configuration."""
486533
# Import this here to avoid a circular import

0 commit comments

Comments
 (0)