Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: New KonfluxClient class for calling Konflux APIs #1151

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

vfreex
Copy link
Contributor

@vfreex vfreex commented Nov 25, 2024

  • Move code for Konflux interactions into separate class KonfluxClient.
  • Use LRU cache for certain APIs.

@ashwindasr
Copy link
Contributor

/approve

unittests need to be updated though

Copy link
Contributor

openshift-ci bot commented Nov 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ashwindasr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 25, 2024
@vfreex
Copy link
Contributor Author

vfreex commented Nov 26, 2024

@ashwindasr Thanks for the review. I've pushed another commit to fix the flake8 errors. Test build: https://art-jenkins.apps.prod-stable-spoke1-dc-iad2.itup.redhat.com/job/aos-cd-builds/job/build%252Focp4-konflux/362/console

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 2, 2024
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2024
async def _patch(self, manifest: dict):
""" Patch a resource.

:param dyn_client: The dynamic client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param dyn_client is not defined

async def _replace(self, manifest: dict):
""" Replace a resource.

:param dyn_client: The dynamic client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param dyn_client is not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

async def _delete(self, api_version: str, kind: str, name: str, namespace: str):
""" Delete a resource.

:param dyn_client: The dynamic client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param dyn_client is not defined

async def _create_or_patch(self, manifest: dict):
""" Create or patch a resource.

:param dyn_client: The dynamic client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param dyn_client is not defined

async def _create_or_replace(self, manifest: dict):
""" Create or replace a resource.

:param dyn_client: The dynamic client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param dyn_client is not defined

output_image: str,
building_arches: Sequence[str],
git_auth_secret: str = "pipelines-as-code-secret",
additional_tags: Sequence[str] = [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default value for additional_tags sis mutable. In Python, mutable args are evaluated only once at function definition time, so calling the function with a different value of the argument will affect all subsequent calls of that function. Better use None instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""
Wait for a PipelineRun to complete.

:param dyn_client: The dynamic client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param dyn_client is not defined

if e.status == 410:
# If the last result is too old, an `ApiException` exception will be thrown with
# `code` 410. In that case we have to recover by retrying without resource_version.
self._logger.debug("%s: Resource version %s is too old. Recovering...", pipelinerun_name, resource_version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get an ApiException at line #476, resource_version won't be assigned and referencing it will raise an exception

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 476 is called without a resource version, so it should never raises a 410 APIException. But for robustness, I've removed the resource_version reference from logging.

@staticmethod
def _new_component(name: str, application: str, component_name: str,
image_repo: Optional[str], source_url: Optional[str], revision: Optional[str]) -> dict:
obj = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider storing this definition as a jinja template, instead of hardcoding it. This could make it easier to find and maintain


# https://konflux.pages.redhat.com/docs/users/how-tos/configuring/overriding-compute-resources.html
# ose-installer-artifacts fails with OOM with default values, hence bumping memory limit
obj["spec"]["taskRunSpecs"] = [{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment, I think storing these definitions in template files would be best. Also ok with a follow up PR

- Move code for Konflux interactions into separate class `KonfluxClient`.
- Use LRU cache for certain APIs.
@vfreex
Copy link
Contributor Author

vfreex commented Dec 4, 2024

@locriandev Thanks for the review. I've addressed your review suggestions again except the one for moving application/component definition to jinja files, which can be done in separate PRs.

@vfreex
Copy link
Contributor Author

vfreex commented Dec 4, 2024

Copy link
Contributor

openshift-ci bot commented Dec 4, 2024

@vfreex: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/security 375505f link false /test security

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Contributor

@locriandev locriandev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 4, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit cdd8b01 into openshift-eng:main Dec 4, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants