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

[BUILD-372] SHIP-0021: Local Source Upload #934

Merged
merged 3 commits into from
Jan 20, 2022

Conversation

otaviof
Copy link
Member

@otaviof otaviof commented Nov 3, 2021

Changes

Local Source Upload (SHIP-0021)

This PR feature local source upload (SHIP-0021), creating the workflow changes to replace the git clone step, by waiting for the content uploaded by the user. The upload is stored in the same original location, the /workspace/source mount point.

To accomplish this task, we employ the waiter nested application, which holds the POD running while the upload is performed.

In order to trigger the local source upload, the user will need the following BuildRun, for instance:

---
apiVersion: shipwright.io/v1alpha1
kind: BuildRun
spec:
  sources:
    - name: local-copy
      type: LocalCopy
      timeout: 60s

The data upload will be performed by our CLI application.

Remote Artifacts

Given the fact there are two types of BuildSource supported, the Remote Artifacts is now defined by the type attribute. The "HTTP" type is introduced for this reason.

---
apiVersion: shipwright.io/v1alpha1
kind: Build
spec:
  sources:
    - name: remote-artifact
      type: HTTP
      url: https://.../

Testing

To run the controller and simulate the changes locally, you'll need a waiter image in place. For that export WAITER_CONTAINER_IMAGE, as per:

export WAITER_CONTAINER_IMAGE="ghcr.io/otaviof/waiter:latest"
make local

After the changes here are merged, then we can use the regular waiter image.

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

Release Notes

action required: `.spec.sources` contains a new attribute `type`, for Remote Artifacts the `type` is "HTTP". The newly introduced type is `LocalCopy`.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 3, 2021
@openshift-ci openshift-ci bot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Nov 3, 2021
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 11, 2021
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 11, 2021
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2021
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 14, 2021
@otaviof otaviof changed the title [WIP] SHIP-0021: Waiter [WIP] SHIP-0021: Local Source Upload Dec 20, 2021
@otaviof otaviof changed the title [WIP] SHIP-0021: Local Source Upload [BUILD-372] SHIP-0021: Local Source Upload Dec 21, 2021
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 21, 2021
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.

Hi @otaviof looks good mostly. Suggesting that you quickly prepare a separate PR for the base image as this needs to be built first.

.github/workflows/base-images.yaml Outdated Show resolved Hide resolved
.ko.yaml Outdated Show resolved Hide resolved
cmd/waiter/main.go Outdated Show resolved Hide resolved
cmd/waiter/waiter.go Outdated Show resolved Hide resolved
cmd/waiter/waiter.go Outdated Show resolved Hide resolved
pkg/config/config.go Show resolved Hide resolved
// AmendTaskSpecWithSources adds steps, results and volumes for spec.source and spec.sources
// isLocalCopy appends all "Sources" in a single slice, and if any entry is typed "LocalCopy" it
// returns first LocalCopy typed BuildSource found, or nil.
func isLocalCopy(build *buildv1alpha1.Build, buildRun *buildv1alpha1.BuildRun) *buildv1alpha1.BuildSource {
Copy link
Member

Choose a reason for hiding this comment

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

The name of the function suggests that it returns a boolean. I suggest to chose a name like findLocalCopyBuildSource.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, a more complete name makes more sense here. I adopted your suggestion, with a minor modification. Please consider.

pkg/reconciler/buildrun/resources/sources/local_copy.go Outdated Show resolved Hide resolved
Comment on lines 87 to 103
// making sure the taskrun is schedule and becomes a pod, since the build-controller will transit
// the object status from empty to unknown, when the actual build starts
Eventually(func() *corev1.ConditionStatus {
status := getBuildRunStatus(buildRunName)
Logf("BuildRun '%s' status '%v'...", buildRunName, status)
return status
}, time.Duration(60*time.Second), 3*time.Second).
Should(Equal(&unknownCondition), "BuildRun should reach unknown condition")

// asserting the waiter step will end up in timeout, in other words, it ends as failed
Eventually(func() *corev1.ConditionStatus {
status := getBuildRunStatus(buildRunName)
Expect(status).ToNot(BeNil())
Logf("BuildRun '%s' status '%s'...", buildRunName, *status)
return status
}, time.Duration(90*time.Second), 10*time.Second).
Should(Equal(&falseCondition), "BuildRun should end up in timeout")
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 Jan 6, 2022

Choose a reason for hiding this comment

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

I suggest to wait for the Reason value (Running in the first block, Failed in the second one) and assert the status. Basically it will be unknown already when the BuildRun is Pending and it can theoretically stay there for a while (waiting for the pod to be scheduled and its images pulled).

Copy link
Member Author

@otaviof otaviof Jan 12, 2022

Choose a reason for hiding this comment

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

Please consider latest changes, I'm using your suggestion and checking the actual "Reason", inside the Condition slice.

I wonder if we should also extend the first block timeout to account for the image pulling time as well.

Copy link
Member

Choose a reason for hiding this comment

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

Right, especially with a lower bandwidth, it might not be enough. For this purpose, there is also the timeout multiplyer that you could add here as well. Like here:

}, time.Duration(1100*getTimeoutMultiplier())*time.Second, 5*time.Second).Should(Equal(trueCondition), "BuildRun did not succeed")

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the snippet, it's in place now.

.gitignore Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 9, 2022
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 10, 2022
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 11, 2022
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.

Stumbled over one more reference to quay.io.

pkg/config/config.go Outdated Show resolved Hide resolved
@otaviof otaviof force-pushed the ship-0021-waiter branch 6 times, most recently from 87b03f9 to c7b5042 Compare January 13, 2022 10:28
Copy link
Member

@gabemontero gabemontero left a comment

Choose a reason for hiding this comment

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

reviewing your PR on a per commit basis @otaviof (since I'm multi tasking a bit here this afternoon) ... if anything, I wanted to show I had at least started on this

only minor comments for commit 377dfb0

will take on the bigger dd72409 in a subsequent iteration

thanks

pkg/reconciler/buildrun/resources/sources.go Outdated Show resolved Hide resolved
@@ -11,9 +11,12 @@ import (
// BuildSourceType enumerates build source type names.
type BuildSourceType string

// LocalCopy defines a source type that waits for user input, as in a local copy into a POD.
// LocalCopy source type when the user will upload local content.
Copy link
Member

Choose a reason for hiding this comment

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

not officially asking for a change, but am wondering .... is it truly obvious that "uploading local content" means it is NOT a remote artifact?

Probably the answer is "yes it is obvious", but at least at this precise moment, I have a small percent of uncertainty

But especially when we start adding remote artifact types other than HTTP, perhaps distinguishing that local source is not one of the remote artifacts becomes a bit more important.

I won't push on it further @otaviof but if you are amenable to making it really clear by all means

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably the answer is "yes it is obvious", but at least at this precise moment, I have a small percent of uncertainty

I think you touch a important subject.

To be honest, at this point, I don't think the local-copy nor the remote-artifacts are depicted well enough. I'm rewording the doc comments for the BuildSource types, trying to contrast "upload" vs. "download". Please consider.

Copy link
Member

Choose a reason for hiding this comment

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

the comments in question are clearer @otaviof

after reading your comment here and in the code, I think I might even go a step further, and

  • change constants starting with RemoteArtifacts... to DownloadedArtfacts...
  • change LocalCopy to UploadedArtifacts

WDYT?

Copy link
Member

@gabemontero gabemontero left a comment

Choose a reason for hiding this comment

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

ok here is my second pass on the waiter commit @otaviof

a few questions, and perhaps an alternative to your existing waiter implementation that is "simpler" in that it is mainly based off of existing golang utilities (assuming the pid in the file is not required down the line)

cmd/waiter/README.md Outdated Show resolved Hide resolved
cmd/waiter/README.md Outdated Show resolved Hide resolved
cmd/waiter/main.go Show resolved Hide resolved
cmd/waiter/waiter.go Show resolved Hide resolved
pkg/apis/build/v1alpha1/build_source.go Show resolved Hide resolved
cmd/waiter/README.md Outdated Show resolved Hide resolved
cmd/waiter/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@rolfedh rolfedh left a comment

Choose a reason for hiding this comment

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

Made some minor suggestions. Otherwise, LGTM.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 18, 2022
@otaviof
Copy link
Member Author

otaviof commented Jan 18, 2022

Made some minor suggestions. Otherwise, LGTM.

Thanks, appreciated!

@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 18, 2022
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.

Just two more questions regarding the e2e test.

test/e2e/e2e_local_source_upload_test.go Outdated Show resolved Hide resolved
"github.com/shipwright-io/build/test/utils"
)

var _ = Describe("For a Kubernetes cluster with Tekton and build installed", func() {
Copy link
Member

Choose a reason for hiding this comment

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

It would be cool to have an e2e test which causes the waiter to successfully complete. Not sure if that's doable.

Copy link
Member Author

@otaviof otaviof Jan 20, 2022

Choose a reason for hiding this comment

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

I agree! The complete test workflow will initially happen on the CLI repository (as part of PR #86), since it depends on the client to utilize the local source upload feature end-to-end. As per:

https://github.com/otaviof/cli/blob/5c0cadc4c623920cafc43d1b77dbc481660129ad/test/e2e/upload.bats#L54-L75

Given the approach is consolidated on the CLI side, we can then reuse it here, if we conclude we want it here to.

What do you think about this approach, and, should we create a issue to keep track of it?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, an issue sounds fine.

@gabemontero
Copy link
Member

Other than a response to my idea of actually changing the names of the structs LocalCopy and RemoteArtifacts (where I don't consider doing the suggestion a blocker), my review comments are resolved @otaviof

I'll

/approve

and let @SaschaSchwarze0 handle LGTM with his remaining comments.

@adambkaplan did you want a pass at this before it merges?

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 19, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gabemontero

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 19, 2022
@SaschaSchwarze0 SaschaSchwarze0 added this to the release-v0.8.0 milestone Jan 19, 2022
otaviof and others added 3 commits January 20, 2022 08:03
Co-authored-by: Sascha Schwarze <schwarzs@de.ibm.com>
Co-authored-by: Rolfe Dlugy-Hegwer <rolfedh@users.noreply.github.com>
Implementing "type" on the BuildSource instances employed for the
Remote Artifacts support.

Amending tests.
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.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 20, 2022
@openshift-merge-robot openshift-merge-robot merged commit 9ceb2f0 into shipwright-io:main Jan 20, 2022
@SaschaSchwarze0 SaschaSchwarze0 added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Jan 20, 2022
@otaviof otaviof deleted the ship-0021-waiter branch January 20, 2022 09:19
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/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note-action-required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants