Skip to content

Commit

Permalink
[konflux] allow field to override konflux template url
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwindasr committed Dec 12, 2024
1 parent 8e736e2 commit 20ffa6a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
16 changes: 10 additions & 6 deletions doozer/doozerlib/backend/konflux_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,31 @@ class KonfluxClient:
"aarch64": "linux/arm64",
}

def __init__(self, default_namespace: str, config: Configuration, dry_run: bool = False, logger: logging.Logger = LOGGER) -> None:
def __init__(self, default_namespace: str, config: Configuration, plr_template: str, dry_run: bool = False, logger: logging.Logger = LOGGER) -> None:
self.api_client = ApiClient(configuration=config)
self.dyn_client = DynamicClient(self.api_client)
self.default_namespace = default_namespace
self.dry_run = dry_run
self._logger = logger

plr_template_owner, konflux_plr_template_branch = plr_template.split("@") if plr_template else ["openshift-priv", "main"]
self.konflux_plr_template_url = constants.KONFLUX_PlR_TEMPLATE_URL.format(owner=plr_template_owner)

@staticmethod
def from_kubeconfig(default_namespace: str, config_file: Optional[str], context: Optional[str], dry_run: bool = False, logger: logging.Logger = LOGGER) -> "KonfluxClient":
def from_kubeconfig(default_namespace: str, config_file: Optional[str], context: Optional[str], plr_template: Optional[str], dry_run: bool = False, logger: logging.Logger = LOGGER) -> "KonfluxClient":
""" Create a KonfluxClient from a kubeconfig file.
:param config_file: The path to the kubeconfig file.
:param context: The context to use.
:param default_namespace: The default namespace.
:param dry_run: Whether to run in dry-run mode.
:param logger: The logger.
:param plr_template: Override the Pipeline Run template commit from openshift-priv/art-konflux-template
:return: The KonfluxClient.
"""
cfg = Configuration()
config.load_kube_config(config_file=config_file, context=context, persist_config=False, client_configuration=cfg)
return KonfluxClient(default_namespace=default_namespace, config=cfg, dry_run=dry_run, logger=logger)
return KonfluxClient(default_namespace=default_namespace, config=cfg, dry_run=dry_run, logger=logger, plr_template=plr_template)

@alru_cache
async def _get_api(self, api_version: str, kind: str):
Expand Down Expand Up @@ -289,8 +293,7 @@ async def ensure_component(self, name: str, application: str, component_name: st
component = self._new_component(name, application, component_name, image_repo, source_url, revision)
return await self._create_or_replace(component)

@staticmethod
def _new_pipelinerun_for_image_build(generate_name: str, namespace: Optional[str], application_name: str, component_name: str,
def _new_pipelinerun_for_image_build(self, generate_name: str, namespace: Optional[str], application_name: str, component_name: str,
git_url: str, commit_sha: str, target_branch: str, output_image: str,
build_platforms: Sequence[str], git_auth_secret: str = "pipelines-as-code-secret",
additional_tags: Optional[Sequence[str]] = None, skip_checks: bool = False) -> dict:
Expand All @@ -300,7 +303,8 @@ def _new_pipelinerun_for_image_build(generate_name: str, namespace: Optional[str

@lru_cache()
def _get_plr_template():
response = requests.get(constants.KONFLUX_PlR_TEMPLATE_URL)
self._logger.info(f"Pulling Konflux PLR template from: {self.konflux_plr_template_url}")
response = requests.get(self.konflux_plr_template_url)

return response.text

Expand Down
3 changes: 2 additions & 1 deletion doozer/doozerlib/backend/konflux_image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class KonfluxImageBuilderConfig:
base_dir: Path
group_name: str
namespace: str
plr_template: str
kubeconfig: Optional[str] = None
context: Optional[str] = None
image_repo: str = constants.KONFLUX_DEFAULT_IMAGE_REPO
Expand All @@ -63,7 +64,7 @@ class KonfluxImageBuilder:
def __init__(self, config: KonfluxImageBuilderConfig, logger: Optional[logging.Logger] = None) -> None:
self._config = config
self._logger = logger or LOGGER
self._konflux_client = KonfluxClient.from_kubeconfig(config.namespace, config.kubeconfig, config.context, config.dry_run)
self._konflux_client = KonfluxClient.from_kubeconfig(config.namespace, config.kubeconfig, config.context, config.dry_run, config.plr_template)

for secret in ["KONFLUX_ART_IMAGES_USERNAME", "KONFLUX_ART_IMAGES_PASSWORD"]:
if secret not in os.environ:
Expand Down
11 changes: 8 additions & 3 deletions doozer/doozerlib/cli/images_konflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def __init__(
image_repo: str,
skip_checks: bool,
dry_run: bool,
plr_template,
):
self.runtime = runtime
self.konflux_kubeconfig = konflux_kubeconfig
Expand All @@ -136,6 +137,7 @@ def __init__(
self.image_repo = image_repo
self.skip_checks = skip_checks
self.dry_run = dry_run
self.plr_template = plr_template

@start_as_current_span_async(TRACER, "images:konflux:build")
async def run(self):
Expand All @@ -152,7 +154,8 @@ async def run(self):
namespace=self.konflux_namespace,
image_repo=self.image_repo,
skip_checks=self.skip_checks,
dry_run=self.dry_run
dry_run=self.dry_run,
plr_template=self.plr_template
)
builder = KonfluxImageBuilder(config=config)
tasks = []
Expand All @@ -178,13 +181,15 @@ async def run(self):
@click.option('--image-repo', default=constants.KONFLUX_DEFAULT_IMAGE_REPO, help='Push images to the specified repo.')
@click.option('--skip-checks', default=False, is_flag=True, help='Skip all post build checks')
@click.option('--dry-run', default=False, is_flag=True, help='Do not build anything, but only print build operations.')
@click.option('--plr-template', required=False, default='',
help='Override the Pipeline Run template commit from openshift-priv/art-konflux-template')
@pass_runtime
@click_coroutine
async def images_konflux_build(
runtime: Runtime, konflux_kubeconfig: Optional[str], konflux_context: Optional[str],
konflux_namespace: str, image_repo: str, skip_checks: bool, dry_run: bool):
konflux_namespace: str, image_repo: str, skip_checks: bool, dry_run: bool, plr_template):
cli = KonfluxBuildCli(
runtime=runtime, konflux_kubeconfig=konflux_kubeconfig,
konflux_context=konflux_context, konflux_namespace=konflux_namespace,
image_repo=image_repo, skip_checks=skip_checks, dry_run=dry_run)
image_repo=image_repo, skip_checks=skip_checks, dry_run=dry_run, plr_template=plr_template)
await cli.run()
2 changes: 1 addition & 1 deletion doozer/doozerlib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
KONFLUX_UI_HOST = "https://konflux.apps.kflux-ocp-p01.7ayg.p1.openshiftapps.com"
KONFLUX_UI_DEFAULT_WORKSPACE = "ocp-art" # associated with ocp-art-tenant
MAX_KONFLUX_BUILD_QUEUE_SIZE = 25 # how many concurrent Konflux pipeline can we spawn per OCP version?
KONFLUX_PlR_TEMPLATE_URL = "https://raw.githubusercontent.com/openshift-priv/art-konflux-template/refs/heads/main/.tekton/art-konflux-template-push.yaml" # Konflux PipelineRun (PLR) template
KONFLUX_PlR_TEMPLATE_URL = "https://raw.githubusercontent.com/{owner}/art-konflux-template/refs/heads/{branch_name}/.tekton/art-konflux-template-push.yaml" # Konflux PipelineRun (PLR) template

REGISTRY_PROXY_BASE_URL = "registry-proxy.engineering.redhat.com"
BREW_REGISTRY_BASE_URL = "brew.registry.redhat.io"
Expand Down
12 changes: 9 additions & 3 deletions pyartcd/pyartcd/pipelines/ocp4_konflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ def default(self, obj):
class KonfluxOcp4Pipeline:
def __init__(self, runtime: Runtime, assembly: str, data_path: Optional[str], image_build_strategy: Optional[str],
image_list: Optional[str], version: str, data_gitref: Optional[str],
kubeconfig: Optional[str], skip_rebase: bool, arches: Tuple[str, ...]):
kubeconfig: Optional[str], skip_rebase: bool, arches: Tuple[str, ...], plr_template: str):
self.runtime = runtime
self.assembly = assembly
self._doozer_working = os.path.abspath(f'{self.runtime.working_dir / "doozer_working"}')
self.version = version
self.kubeconfig = kubeconfig
self.arches = arches
self.skip_rebase = skip_rebase
self.plr_template = plr_template

group_param = f'--group=openshift-{version}'
if data_gitref:
Expand Down Expand Up @@ -141,6 +142,8 @@ async def build(self):
])
if self.kubeconfig:
cmd.extend(['--konflux-kubeconfig', self.kubeconfig])
if self.plr_template:
cmd.extend(['--plr_template', self.plr_template])
if self.runtime.dry_run:
cmd.append('--dry-run')
await exectools.cmd_assert_async(cmd)
Expand Down Expand Up @@ -232,11 +235,13 @@ async def run(self):
@click.option("--skip-rebase", is_flag=True, help="(For testing) Skip the rebase step")
@click.option("--arch", "arches", metavar="TAG", multiple=True,
help="(Optional) [MULTIPLE] Limit included arches to this list")
@click.option('--plr-template', required=False, default='',
help='Override the Pipeline Run template commit from openshift-priv/art-konflux-template')
@pass_runtime
@click_coroutine
async def ocp4(runtime: Runtime, image_build_strategy: str, image_list: Optional[str], assembly: str,
data_path: Optional[str], version: str, data_gitref: Optional[str], kubeconfig: Optional[str],
ignore_locks: bool, skip_rebase: bool, arches: Tuple[str, ...]):
ignore_locks: bool, skip_rebase: bool, arches: Tuple[str, ...], plr_template: str):
if not kubeconfig:
kubeconfig = os.environ.get('KONFLUX_SA_KUBECONFIG')

Expand All @@ -254,7 +259,8 @@ async def ocp4(runtime: Runtime, image_build_strategy: str, image_list: Optional
data_gitref=data_gitref,
kubeconfig=kubeconfig,
skip_rebase=skip_rebase,
arches=arches)
arches=arches,
plr_template=plr_template)

if ignore_locks:
await pipeline.run()
Expand Down

0 comments on commit 20ffa6a

Please sign in to comment.