-
Notifications
You must be signed in to change notification settings - Fork 245
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
Use oci image to run a task #2130
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,17 @@ import ( | |
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/google/go-containerregistry/pkg/name" | ||
remoteimg "github.com/google/go-containerregistry/pkg/v1/remote" | ||
"github.com/tektoncd/cli/pkg/bundle" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
"fmt" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/AlecAivazis/survey/v2/terminal" | ||
"github.com/spf13/cobra" | ||
|
@@ -61,6 +66,7 @@ type startOptions struct { | |
Labels []string | ||
ShowLog bool | ||
Filename string | ||
Image string | ||
TimeOut string | ||
DryRun bool | ||
Output string | ||
|
@@ -73,6 +79,7 @@ type startOptions struct { | |
UseParamDefaults bool | ||
PodTemplate string | ||
SkipOptionalWorkspace bool | ||
remoteOptions bundle.RemoteOptions | ||
} | ||
|
||
// NameArg validates that the first argument is a valid task name | ||
|
@@ -123,8 +130,14 @@ func startCommand(p cli.Params) *cobra.Command { | |
|
||
tkn task start foo -s ServiceAccountName -n bar | ||
|
||
The Task can either be specified by reference in a cluster using the positional argument | ||
or in a file using the --filename argument. | ||
The Task can either be specified by reference in a cluster using the positional argument, | ||
an oci bundle using the --image argument and the positional argument or in a file using the --filename argument | ||
|
||
Authentication: | ||
There are three ways to authenticate against your registry when using the --image argument. | ||
1. By default, your docker.config in your home directory and podman's auth.json are used. | ||
2. Additionally, you can supply a Bearer Token via --remote-bearer | ||
3. Additionally, you can use Basic auth via --remote-username and --remote-password | ||
|
||
For params values, if you want to provide multiple values, provide them comma separated | ||
like cat,foo,bar | ||
|
@@ -167,16 +180,26 @@ For passing the workspaces via flags: | |
if format != "" && opt.ShowLog { | ||
return errors.New("cannot use --output option with --showlog option") | ||
} | ||
if len(args) != 0 { | ||
// classic with no image | ||
if len(args) != 0 && opt.Image == "" { | ||
return NameArg(args, p, &opt) | ||
} | ||
if opt.Filename == "" { | ||
// image but no task name | ||
if len(args) == 0 && opt.Image != "" { | ||
return errors.New("task name required with --image option") | ||
} | ||
// trying to use a file and image | ||
if opt.Filename != "" && opt.Image != "" { | ||
return errors.New("cannot use --filename option with --image option") | ||
} | ||
// not passing enough | ||
if opt.Filename == "" && len(args) == 0 { | ||
return errors.New("either a Task name or a --filename argument must be supplied") | ||
} | ||
if opt.Filename != "" && opt.Last { | ||
return errors.New("cannot use --last option with --filename option") | ||
// cant mix image/file with --last ( I think this is true? ) | ||
if (opt.Filename != "" || opt.Image != "") && opt.Last { | ||
return errors.New("cannot use --last option with --filename or --image option") | ||
} | ||
|
||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
@@ -212,24 +235,24 @@ For passing the workspaces via flags: | |
c.Flags().StringArrayVarP(&opt.Workspaces, "workspace", "w", []string{}, "pass one or more workspaces to map to the corresponding physical volumes") | ||
c.Flags().BoolVarP(&opt.ShowLog, "showlog", "", false, "show logs right after starting the Task") | ||
c.Flags().StringVarP(&opt.Filename, "filename", "f", "", "local or remote file name containing a Task definition to start a TaskRun") | ||
c.Flags().StringVarP(&opt.Image, "image", "i", "", "use an oci bundle") | ||
|
||
c.Flags().StringVarP(&opt.TimeOut, "timeout", "", "", "timeout for TaskRun") | ||
c.Flags().BoolVarP(&opt.DryRun, "dry-run", "", false, "preview TaskRun without running it") | ||
c.Flags().StringVarP(&opt.Output, "output", "", "", "format of TaskRun (yaml or json)") | ||
c.Flags().StringVarP(&opt.PrefixName, "prefix-name", "", "", "specify a prefix for the TaskRun name (must be lowercase alphanumeric characters)") | ||
c.Flags().BoolVarP(&opt.UseParamDefaults, "use-param-defaults", "", false, "use default parameter values without prompting for input") | ||
c.Flags().StringVar(&opt.PodTemplate, "pod-template", "", "local or remote file containing a PodTemplate definition") | ||
c.Flags().BoolVarP(&opt.SkipOptionalWorkspace, "skip-optional-workspace", "", false, "skips the prompt for optional workspaces") | ||
bundle.AddRemoteFlags(c.Flags(), &opt.remoteOptions) | ||
|
||
return c | ||
} | ||
|
||
func parseTask(taskLocation string, httpClient http.Client) (*v1beta1.Task, error) { | ||
b, err := file.LoadFileContent(httpClient, taskLocation, file.IsYamlFile(), fmt.Errorf("invalid file format for %s: .yaml or .yml file extension and format required", taskLocation)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
func parseTask(b []byte) (*v1beta1.Task, error) { | ||
|
||
m := map[string]interface{}{} | ||
err = yaml.UnmarshalStrict(b, &m) | ||
err := yaml.UnmarshalStrict(b, &m) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -277,28 +300,59 @@ func startTask(opt startOptions, args []string) error { | |
Namespace: opt.cliparams.Namespace(), | ||
}, | ||
} | ||
|
||
var tname string | ||
if len(args) > 0 { | ||
|
||
switch { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here is where i think we can generalize the logic for a task and a pipeline? @vdemeester |
||
case len(args) > 0 && opt.Image == "": | ||
tname = args[0] | ||
tr.Spec = v1beta1.TaskRunSpec{ | ||
TaskRef: &v1beta1.TaskRef{Name: tname}, | ||
} | ||
} else { | ||
task, err := parseTask(opt.Filename, cs.HTTPClient) | ||
case opt.Filename != "": | ||
b, err := file.LoadFileContent(cs.HTTPClient, opt.Filename, file.IsYamlFile(), fmt.Errorf("invalid file format for %s: .yaml or .yml file extension and format required", opt.Filename)) | ||
if err != nil { | ||
return err | ||
} | ||
task, err := parseTask(b) | ||
if err != nil { | ||
return err | ||
} | ||
opt.task = task | ||
tname = task.ObjectMeta.Name | ||
|
||
if task.Spec.Params != nil { | ||
params.FilterParamsByType(task.Spec.Params) | ||
} | ||
|
||
tr.Spec = v1beta1.TaskRunSpec{ | ||
TaskSpec: &task.Spec, | ||
} | ||
case opt.Image != "": | ||
ref, err := name.ParseReference(opt.Image) | ||
if err != nil { | ||
return err | ||
} | ||
img, err := remoteimg.Image(ref, opt.remoteOptions.ToOptions()...) | ||
if err != nil { | ||
return err | ||
} | ||
err = bundle.Get(img, "task", args[0], func(_, _, _ string, element runtime.Object, b []byte) { | ||
task, intErr := parseTask(b) | ||
if intErr != nil { | ||
err = intErr | ||
} | ||
opt.task = task | ||
tname = task.ObjectMeta.Name | ||
|
||
if task.Spec.Params != nil { | ||
params.FilterParamsByType(task.Spec.Params) | ||
} | ||
|
||
tr.Spec = v1beta1.TaskRunSpec{ | ||
TaskSpec: &task.Spec, | ||
} | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if err := opt.getInputs(); err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
not goimported
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 linter seems happy enough, and i did run
goimports -l -e -w ./pkg/cmd/task/start*
.I noticed the makefile has a goimports cmd, but its looking in a
.bin/
of the current dir, and i dont have goimports installed there. Is there a way to setup the.bin/
from the makefile with the required dependencies? Not sure what the difference would be, running there vs where i have it installed, but happy to update, or if there is documentation I'm missing somewhere can you please point me in that direction? thanks 😸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.
@williamlfish it should "auto-install" it in the
.bin
folder on themake lint
commands (or whatever the target name is). At least that's what it's supposed to do 😛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.
@vdemeester I updated
make lint
to do that with the latest commit, it was previously just installing golangci-lint. I'm not sure what version or what binaryyamllint
is supposed to be, but we should have that auto install too, for now i just moved to to the end so it fails there if someone does not have it installed 🤷♀️