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

Add source timestamp field for source result #1471

Merged
merged 4 commits into from
Jan 29, 2024

Conversation

HeavyWombat
Copy link
Contributor

@HeavyWombat HeavyWombat commented Jan 18, 2024

Changes

Extend the API fields and CRD files to include the source timestamp in the source result.

Update Git step code to write commit timestamp result file.

Update Bundle step code to write source timestamp, which is the the most recent source file timestamp.

Extend task run setup logic to include respective command line flags for the Git and Bundle step CLIs to write the result files, which then can be used to extend the status sources fields of the BuildRun.

Fix timestamp issue in Bundle pack and push code so that only the image gets a neutral timestamp, but the packaged source files retain their respective filesystem modification timestamps.

Add integration test cases to verify the new status sources fields.

Fixes #1446

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.

Release Notes

Git and Bundle sources now produce additional status fields in a BuildRun to return the commit timestamp of the commit being used, or the image/source timestamp of Bundle images respectively.

@HeavyWombat HeavyWombat added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 18, 2024
@openshift-ci openshift-ci bot added the release-note Label for when a PR has specified a release note label Jan 18, 2024
@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jan 18, 2024
@openshift-ci openshift-ci bot requested review from adambkaplan and otaviof January 18, 2024 12:02
@@ -188,14 +211,16 @@ var _ = Describe("Bundle Loader", func() {
})

AfterEach(func() {
ref, err := name.ParseReference(testImage)
Expect(err).ToNot(HaveOccurred())
if testImage != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When certain tests are skipped, the testImage string can actually be empty and therefore would cause a panic.

@@ -35,12 +35,12 @@ func PackAndPush(ref name.Reference, directory string, options ...remote.Option)
return name.Digest{}, err
}

image, err := mutate.AppendLayers(empty.Image, bundleLayer)
image, err := mutate.Time(empty.Image, time.Unix(0, 0))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mutating the empty image before using it with AppendLayers makes sure that the image has timestamp 0, but the layer that is later added is not mutated as well.

@HeavyWombat HeavyWombat force-pushed the add/source-timestamp branch 3 times, most recently from 1cc6f3f to 414bd83 Compare January 18, 2024 12:41
@HeavyWombat HeavyWombat changed the title Add commit, source, and image timestamps fields Add source timestamp field for source result Jan 22, 2024
Comment on lines 35 to 38
pipelineapi.TaskResult{
Name: fmt.Sprintf("%s-source-%s-source-timestamp", prefixParamsResultsVolumes, name),
Description: "The timestamp of the most recent source file.",
},
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this should be rather declared in sources.go generically.

sourceResult.Bundle = &build.BundleSourceResult{Digest: imageDigest}
}

sourceTimestamp := findResultValue(results, fmt.Sprintf("%s-source-%s-source-timestamp", prefixParamsResultsVolumes, name))
Copy link
Member

Choose a reason for hiding this comment

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

Same here, should that be in sources.go, updateBuildRunStatusWithSourceResult ?

branchName = "branch-name"
commitSHAResult = "commit-sha"
commitAuthorResult = "commit-author"
commitTimestampResult = "commit-timestamp"
Copy link
Member

Choose a reason for hiding this comment

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

Consider using a common result as suggested in bundle.go. This will help us when we want to consume the result from another step (image-processing). Ideally we there need no check which result to read but rely on a common name independent of the source type.

Comment on lines +228 to +230
TypeMeta: metav1.TypeMeta{
Kind: string(build.ClusterBuildStrategyKind),
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using ClusterBuildStrategy caused issues since the BuildRuns created using this strategy in the test code did not have the kind and therefore failed to be usable.

for _, result := range results {
if result.Name == name {
return result.Value.StringVal
return strings.TrimSpace(result.Value.StringVal)
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 Jan 24, 2024

Choose a reason for hiding this comment

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

Why ? If for example a commit message ends with a space then we can be accurate by not trimming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me put that trim back on the other side.

Fix issue with empty string when test cases are skipped.
Extend Git step CLI to write a result file containing the source
timestamp of the commit that is checked out.
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@SaschaSchwarze0 SaschaSchwarze0 added this to the release-v0.13.0 milestone Jan 29, 2024
Add flag to write source timestamp into result file.

Fix `PackAndPush` function to set timestamp of the base image and not
for all files in the main layer of the image to keep the timestamps of
the files in the bundle layer.
Update CRDs to include timestamp fields.

Add timestamp fields for Git and Bundle results.
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 29, 2024
Copy link
Contributor

openshift-ci bot commented Jan 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SaschaSchwarze0

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 Jan 29, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit ae280b3 into main Jan 29, 2024
14 checks passed
@openshift-merge-bot openshift-merge-bot bot deleted the add/source-timestamp branch January 29, 2024 16:27
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Label for when a PR has specified a release note size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add source timestamp to source results
2 participants