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

Tekton compatibility for committime exporter #333

Closed
wants to merge 13 commits into from

Conversation

KevinMGranger
Copy link
Collaborator

@KevinMGranger KevinMGranger commented Jan 4, 2022

copied from #327

Describe the behavior changes introduced in this PR

Adds the ability to get git commit information from Tekton runs.

It's a good enough implementation for "technology preview" status. There are open questions about how to extract the right information when there's near infinite flexibility in making a pipeline.

Right now, it tries to follow the (I believe) most common usage patterns:

  • Looks up git information from the git-checkout ClusterTask that comes with Tekton
  • Gets the image hash from the first TaskRun with a taskResult named IMAGE_DIGEST
  • Gets the image location from the first TaskRun with IMAGE or IMAGE_NAME as a param, following patterns from various s2i and buildah tasks

I'm sure we'll need to figure out a way to add some flexibility. I've started exploring some possible solutions while experimenting with this, but that should come later.

Special thanks to @jlozano-rh for starting the work on this.

Linked Issues?

resolves #224

Testing Instructions

  1. Fork my fork of this repo and check out the tekton branch.
  2. Set up the committime exporter. Make sure it is pointed to your fork. The deploytime exporter must also be there but can still point upstream.
  3. Run the tekton demo with ./demo/demo-tekton $URL_FOR_FORK.
  4. Make sure the pipeline was successful and look at the sample page.
  5. Use the prompt to make a change, and wait for it to show up.
  6. Verify the metrics show up in the dashboard.

@redhat-cop/mdt

Remaining Work

  • feature-flag the tekton features
  • resolve demo issue: occasional unable to recognize no matches for kind "Pipeline" in version "tekton.dev/v1beta1"
  • demo should poll for the page to be ready
  • git-clone task unavailable for the first run?

@KevinMGranger KevinMGranger self-assigned this Jan 4, 2022
@KevinMGranger KevinMGranger added the committime-exporter Related to the committime exporter label Jan 4, 2022
@KevinMGranger KevinMGranger added this to the v1.5-rc1 milestone Jan 4, 2022
exporters/committime/collector_base.py Outdated Show resolved Hide resolved
exporters/committime/collector_base.py Outdated Show resolved Hide resolved
exporters/committime/collector_base.py Outdated Show resolved Hide resolved
Comment on lines 202 to 214
git_host = build.metadata.labels.pelorusgithost
git_project = build.metadata.labels.pelorusgitproject
git_app = build.metadata.labels.pelorusgitapp
git_protocol = build.metadata.labels.pelorusgitprotocol
repo_url = (
git_protocol
+ "://"
+ git_host
+ "/"
+ git_project
+ "/"
+ git_app
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should break up git URLs in this way. There are a myriad of supported git url formats that are not covered by this structure, and to try to cover them all would be cumbersome and unnecessary. I would just stick to the two standard git parameters that are used all over the place:

  • git_url - The full URL string in any format
  • git_ref - The branch or tag to be examined, if applicable

Choose a reason for hiding this comment

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

@etsauer I initially approached the solution using labels. But labels have character restrictions for the value part. The idea is to improve this with an annotation to avoid dirty code like this one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using annotations makes sense. I'll add a BUILD_GIT_REPO_URI_ANNOTATION env variable (or is that too long...)

We should probably use a namespaced default, right? Something like pelorus.konveyor.io/git-uri? Or keep it simple with gitUri?

Choose a reason for hiding this comment

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

@KevinMGranger I was updating these values with a pipeline dynamically. Regarding the env variable, I think it is fine, I prefer it to be long and understandable rather than short and confusing.

Regarding the namespaced default, I think it's the same thing... keeping it simple can lead to confusion, I think having pelorus word in the name would indicate what it is.

Copy link
Collaborator

@mpryc mpryc left a comment

Choose a reason for hiding this comment

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

Just few nits around shell to get started and understand what's happening in the project :)

demo/demo-tekton Outdated Show resolved Hide resolved
demo/demo-tekton Outdated Show resolved Hide resolved
demo/demo-tekton Outdated Show resolved Hide resolved
demo/python-example/example.py Outdated Show resolved Hide resolved
pipeline_runs = pelorus.NoOpResourceInstance()

# use a jsonpath expression to find all possible values for the app label
jsonpath_str = f"$['items'][*]['metadata']['labels']['{app_label}']"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will break if app_label has single quotes in it for some reason. We could extract this part with plain python.

@KevinMGranger KevinMGranger marked this pull request as ready for review February 14, 2022 21:49
@KevinMGranger KevinMGranger changed the title [WIP] Tekton compatibility for committime exporter Tekton compatibility for committime exporter Feb 14, 2022
Copy link
Collaborator

@mpryc mpryc left a comment

Choose a reason for hiding this comment

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

  1. I think we should allow to install tkn and oc commands using Makefile dev-env to a separate PATH. This can however be different PR.

  2. Should the project template be compatible as well with kubectl ? It means to use in the demo/tekton-demo-setup/02-project.yaml api version v1, similarly to:
    https://github.com/redhat-cop/openshift-applier/blob/main/tests/files/templates/projectrequest.yml

exporters/committime/collector_base.py Show resolved Hide resolved
exporters/committime/collector_base.py Outdated Show resolved Hide resolved
exporters/committime/collector_base.py Show resolved Hide resolved
exporters/committime/collector_base.py Show resolved Hide resolved
exporters/committime/collector_base.py Show resolved Hide resolved
exporters/committime/collector_base.py Show resolved Hide resolved
Used to find the TaskRun that did the git checkout.
"""
pipeline_resource = self._kube_client.resources.get(
api_version="tekton.dev/v1beta1", kind="Pipeline"
Copy link
Collaborator

Choose a reason for hiding this comment

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

As in previous comment. I do think such api_versions should be hidden in the function body.

exporters/committime/collector_base.py Outdated Show resolved Hide resolved
else:
return NotImplemented

def __repr__(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should you define __str__(self) as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to double check how these are used within the openshift library. I think I was unsure if __str__ should transparently use the underlying string, or use __repr__.

@mpryc
Copy link
Collaborator

mpryc commented Feb 24, 2022

Few more issues found with the script (using bash as shell on Fedora):

/usr/bin/which: invalid option -- 's'
/usr/bin/oc
/usr/bin/which: invalid option -- 's'
/usr/local/bin/tkn
Setting up resources:
1. Installing tekton operator
2. Setting up python tekton project
Project already exists
3. Setting up build and deployment information
imagestream.image.openshift.io/basic-python-tekton unchanged
persistentvolumeclaim/basic-python-tekton-build-pvc unchanged
pipeline.tekton.dev/basic-python-tekton-pipeline unchanged
service/basic-python-tekton unchanged
route.route.openshift.io/basic-python-tekton unchanged
deploymentconfig.apps.openshift.io/basic-python-tekton configured
./demo/demo-tekton: line 41: $1: unbound variable

Copy link
Collaborator Author

@KevinMGranger KevinMGranger left a comment

Choose a reason for hiding this comment

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

Addressed your comments, looks like I have a little more work to do.

exporters/committime/collector_base.py Show resolved Hide resolved
exporters/committime/collector_base.py Show resolved Hide resolved
exporters/committime/collector_base.py Outdated Show resolved Hide resolved
exporters/committime/collector_base.py Show resolved Hide resolved
commit_sha = spec.revision.git.commit
metric.committer = spec.revision.git.author.name
else:
# TODO: check for existence, allow user customization? Annotation instead?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. I missed the UNKNOWN_AUTHOR part as well-- I think we can just leave it out, but I need to double check Grafana/Prometheus.

exporters/committime/collector_base.py Show resolved Hide resolved
exporters/committime/collector_base.py Show resolved Hide resolved
exporters/committime/collector_base.py Outdated Show resolved Hide resolved
else:
return NotImplemented

def __repr__(self):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to double check how these are used within the openshift library. I think I was unsure if __str__ should transparently use the underlying string, or use __repr__.

@KevinMGranger KevinMGranger marked this pull request as draft February 24, 2022 15:36
@KevinMGranger
Copy link
Collaborator Author

KevinMGranger commented Mar 2, 2022

To summarize the remaining work:

  • Move resource versions / names up into constants
  • double-check how typedstrings would be interpreted within the openshift library
  • handle string interpolation in the jsonpath expression

jlozano-rh and others added 2 commits March 2, 2022 12:01
Look for tekton data in standard locations.

Add various utility / helper functions.
While we should make a broader error management strategy,
this is here while tekton support is in preview.
Also fix referring to wrong FQDN attribute name
- use TypedStrings where possible to avoid previous errors
- filter to only use successful pipeline runs
- Rename many variables to be more clear and semantically correct
- Avoid passing around names when already present in objects to reduce errors
@openshift-ci
Copy link

openshift-ci bot commented Mar 16, 2022

@KevinMGranger: PR needs rebase.

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/test-infra repository.

@openshift-ci openshift-ci bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Mar 16, 2022
@openshift-ci
Copy link

openshift-ci bot commented Apr 6, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KevinMGranger

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 Apr 6, 2022
@openshift-ci
Copy link

openshift-ci bot commented Jun 8, 2022

@KevinMGranger: 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/4.10-unit a721ee3 link true /test 4.10-unit

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/test-infra repository. I understand the commands that are listed here.

@KevinMGranger
Copy link
Collaborator Author

Because tekton pipelines could be customized to do anything, supporting this by guessing isn't worth the technical cost.

We've decided that the best course of action is to annotate the resulting build with the required info, which was implemented with PR #498. It also solves the problem in issue #317 at the same time!

What would make tekton "support" easier is documenting how you might label the resulting build, and including an example of that. We already have demo code in the repo, so we'll likely use that.

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. committime-exporter Related to the committime exporter do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration with Tekton
4 participants