-
Notifications
You must be signed in to change notification settings - Fork 121
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
Oci tool: makes use of oci-artifacts to store and retrieve Tekton resources #461
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
This contains a POC of a cli that can push and pull tekton resources as OCI artifacts from a supported registry. Credits: Thanks to Pierre Tasci for this patch. Signed-off-by: Sunil Thaha <sthaha@redhat.com>
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
} | ||
|
||
// getNameParts will attempt to return a { "hostname/image-name", "tag or sha" } list of the provided image name. There maybe less than the full 2 elements if one of the parts isn't included in the original name. | ||
func getNameParts(name string) (*ImageReference, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The go-containerregistry library has a pretty solid set of methods for this kind of name parsing, I'd love to avoid having to maintain it in two places.
https://godoc.org/github.com/google/go-containerregistry/pkg/name#ParseReference
} | ||
|
||
// ReadPaths will recursively search each file path for Tekton resources and return the parsed specs or an error. | ||
func ReadPaths(filePaths []string) ([]ParsedTektonResource, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like a lot of these methods are only called from within this package, so they don't have to be exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe ReadPaths and ParsedTektonResource are the only exported members and they are referenced outside of the oci
package inside of the action
package. Perhaps there is a case to be made for re-organizing but this tends to follow a cobra cli layout as far as I can tell.
// entities in a single file). | ||
var entities []string | ||
switch ext := path.Ext(filePath); true { | ||
case ext == ".yaml" || ext == ".yml": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure there's a standard K8s package to universally decode K8s config files. Can we use that instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done in tekdoc: https://github.com/tektoncd/experimental/blob/master/tekdoc/main.go#L45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UniversalDeserializer is being used here: https://github.com/tektoncd/experimental/pull/461/files/28fc8d52254c72a62a82d422db91ff4ecaf11b0a#diff-be720fcc306c3d06da4d0c6eac9ed71eR126 to decode the file contents and ensure they are parseable as Tekton crds.
The problem is that the deserializer, AFAIK, will only parse a single resource from a set of contents even if the file is a ---
separated yaml config or a json array. We want to allow parsing multiple resources from a single file. If we take a look at how kubectl accomplishes this in the cli-runtime
it is a bit more roundabout than what is trying to be accomplished here: https://github.com/kubernetes/kubectl/blob/4e4ec7cb5beac1fe75fd4be05d77c65030c30088/pkg/cmd/apply/apply.go#L323
To that end, for the first iteration of a tool that is meant just to be a POC, it might be worthwhile to keep the logic simple and more bespoke while we figure out how Tekton will support bundling these images. Perhaps we decide only Catalog CRDs should be bundled and we don't need parsing input at all"
) | ||
|
||
func init() { | ||
orascontext.GetLogger(context.Background()).Logger.SetLevel(logrus.ErrorLevel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we expect/hope this code will end up in either tkn or Tekton cobtrollers we should try to standardize on the logging used in those codebases, I don't think they use logrus today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is actually just here to suppress the built-in logger of the oras
package which spits out warnings for using a custom mime that isn't publicly registered anywhere. I don't think this PR specifies a logger and is, unfortunately, only importing logrus to set the log level.
resolver := docker.NewResolver(docker.ResolverOptions{}) | ||
memoryStore := orascontent.NewMemoryStore() | ||
|
||
_, _, err := oras.Pull( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go-containerregistry also has pretty straightforward methods for pulling and pushing, which are already used in Tekton. Can we try to use those to make this easier to integrate down the line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a case to be made here for exploring using go-containerregistry instead of oras if that is what Tekton already uses. Perhaps that can be done as a follow on exploration since this code as-is accomplishes the functionality intended.
// entities in a single file). | ||
var entities []string | ||
switch ext := path.Ext(filePath); true { | ||
case ext == ".yaml" || ext == ".yml": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UniversalDeserializer is being used here: https://github.com/tektoncd/experimental/pull/461/files/28fc8d52254c72a62a82d422db91ff4ecaf11b0a#diff-be720fcc306c3d06da4d0c6eac9ed71eR126 to decode the file contents and ensure they are parseable as Tekton crds.
The problem is that the deserializer, AFAIK, will only parse a single resource from a set of contents even if the file is a ---
separated yaml config or a json array. We want to allow parsing multiple resources from a single file. If we take a look at how kubectl accomplishes this in the cli-runtime
it is a bit more roundabout than what is trying to be accomplished here: https://github.com/kubernetes/kubectl/blob/4e4ec7cb5beac1fe75fd4be05d77c65030c30088/pkg/cmd/apply/apply.go#L323
To that end, for the first iteration of a tool that is meant just to be a POC, it might be worthwhile to keep the logic simple and more bespoke while we figure out how Tekton will support bundling these images. Perhaps we decide only Catalog CRDs should be bundled and we don't need parsing input at all"
) | ||
|
||
func init() { | ||
orascontext.GetLogger(context.Background()).Logger.SetLevel(logrus.ErrorLevel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is actually just here to suppress the built-in logger of the oras
package which spits out warnings for using a custom mime that isn't publicly registered anywhere. I don't think this PR specifies a logger and is, unfortunately, only importing logrus to set the log level.
} | ||
|
||
// ReadPaths will recursively search each file path for Tekton resources and return the parsed specs or an error. | ||
func ReadPaths(filePaths []string) ([]ParsedTektonResource, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe ReadPaths and ParsedTektonResource are the only exported members and they are referenced outside of the oci
package inside of the action
package. Perhaps there is a case to be made for re-organizing but this tends to follow a cobra cli layout as far as I can tell.
I would definitely vote for that 👼 This is the experimental repository, it's meant to be experiments and to be simpler to get stuff in 👼 |
/cc @abayer @afrittoli @bobcatfish for a 2nd approval/lgtm 👼 |
/lgtm +1 for getting it merged first as a POC, sorry if my comments made it seem like we needed to get those in ASAP. I can send some PRs to see what it looks like using go-containerregistry. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ImJasonH, vdemeester 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 |
Re: supporting yamls with |
Changes
This PR relates to the #1839: Versioning of Tasks discussion. The PR adds an
oci
tool that is currently able to store and retrieve Tekton resource (Pipeline, Task, ClusterTask...) from a registry.Credits: Thanks for Pierre Tasci @pierretasci for the initial implementation.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide
for more details.