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 create command for task and clustertask #1359

Merged
merged 2 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/cmd/tkn_clustertask.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Manage ClusterTasks
### SEE ALSO

* [tkn](tkn.md) - CLI for tekton pipelines
* [tkn clustertask create](tkn_clustertask_create.md) - Create a ClusterTask from Task
* [tkn clustertask delete](tkn_clustertask_delete.md) - Delete ClusterTasks in a cluster
* [tkn clustertask describe](tkn_clustertask_describe.md) - Describe a ClusterTask
* [tkn clustertask list](tkn_clustertask_list.md) - Lists ClusterTasks
Expand Down
40 changes: 40 additions & 0 deletions docs/cmd/tkn_clustertask_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## tkn clustertask create

Create a ClusterTask from Task

### Usage

```
tkn clustertask create
```

### Synopsis

Create a ClusterTask from Task

### Examples

Create a ClusterTask from Task 'foo' present in namespace 'ns':
tkn clustertask create --from foo
or
tkn clustertask create foobar --from=foo

### Options

```
--from string Create a ClusterTask from Task in a particular namespace
-h, --help help for create
```

### Options inherited from parent commands

```
-c, --context string name of the kubeconfig context to use (default: kubectl config current-context)
-k, --kubeconfig string kubectl config file (default: $HOME/.kube/config)
-C, --no-color disable coloring (default: false)
```

### SEE ALSO

* [tkn clustertask](tkn_clustertask.md) - Manage ClusterTasks

1 change: 1 addition & 0 deletions docs/cmd/tkn_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Manage Tasks
### SEE ALSO

* [tkn](tkn.md) - CLI for tekton pipelines
* [tkn task create](tkn_task_create.md) - Create a Task from ClusterTask
* [tkn task delete](tkn_task_delete.md) - Delete Tasks in a namespace
* [tkn task describe](tkn_task_describe.md) - Describe a Task in a namespace
* [tkn task list](tkn_task_list.md) - Lists Tasks in a namespace
Expand Down
41 changes: 41 additions & 0 deletions docs/cmd/tkn_task_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## tkn task create

Create a Task from ClusterTask

### Usage

```
tkn task create
```

### Synopsis

Create a Task from ClusterTask

### Examples

Create a Task from ClusterTask 'foo' in namespace 'ns':
tkn task create --from foo
or
tkn task create foobar --from=foo -n ns

### Options

```
--from string Create a ClusterTask from Task in a particular namespace
-h, --help help for create
```

### Options inherited from parent commands

```
-c, --context string name of the kubeconfig context to use (default: kubectl config current-context)
-k, --kubeconfig string kubectl config file (default: $HOME/.kube/config)
-n, --namespace string namespace to use (default: from $KUBECONFIG)
-C, --no-color disable coloring (default: false)
```

### SEE ALSO

* [tkn task](tkn_task.md) - Manage Tasks

55 changes: 55 additions & 0 deletions docs/man/man1/tkn-clustertask-create.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.TH "TKN\-CLUSTERTASK\-CREATE" "1" "" "Auto generated by spf13/cobra" ""
.nh
.ad l


.SH NAME
.PP
tkn\-clustertask\-create \- Create a ClusterTask from Task


.SH SYNOPSIS
.PP
\fBtkn clustertask create\fP


.SH DESCRIPTION
.PP
Create a ClusterTask from Task


.SH OPTIONS
.PP
\fB\-\-from\fP=""
Create a ClusterTask from Task in a particular namespace

.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
help for create


.SH OPTIONS INHERITED FROM PARENT COMMANDS
.PP
\fB\-c\fP, \fB\-\-context\fP=""
name of the kubeconfig context to use (default: kubectl config current\-context)

.PP
\fB\-k\fP, \fB\-\-kubeconfig\fP=""
kubectl config file (default: $HOME/.kube/config)

.PP
\fB\-C\fP, \fB\-\-no\-color\fP[=false]
disable coloring (default: false)


.SH EXAMPLE
.PP
Create a ClusterTask from Task 'foo' present in namespace 'ns':
tkn clustertask create \-\-from foo
or
tkn clustertask create foobar \-\-from=foo


.SH SEE ALSO
.PP
\fBtkn\-clustertask(1)\fP
2 changes: 1 addition & 1 deletion docs/man/man1/tkn-clustertask.1
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Manage ClusterTasks

.SH SEE ALSO
.PP
\fBtkn(1)\fP, \fBtkn\-clustertask\-delete(1)\fP, \fBtkn\-clustertask\-describe(1)\fP, \fBtkn\-clustertask\-list(1)\fP, \fBtkn\-clustertask\-logs(1)\fP, \fBtkn\-clustertask\-start(1)\fP
\fBtkn(1)\fP, \fBtkn\-clustertask\-create(1)\fP, \fBtkn\-clustertask\-delete(1)\fP, \fBtkn\-clustertask\-describe(1)\fP, \fBtkn\-clustertask\-list(1)\fP, \fBtkn\-clustertask\-logs(1)\fP, \fBtkn\-clustertask\-start(1)\fP
59 changes: 59 additions & 0 deletions docs/man/man1/tkn-task-create.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.TH "TKN\-TASK\-CREATE" "1" "" "Auto generated by spf13/cobra" ""
.nh
.ad l


.SH NAME
.PP
tkn\-task\-create \- Create a Task from ClusterTask


.SH SYNOPSIS
.PP
\fBtkn task create\fP


.SH DESCRIPTION
.PP
Create a Task from ClusterTask


.SH OPTIONS
.PP
\fB\-\-from\fP=""
Create a ClusterTask from Task in a particular namespace

.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
help for create


.SH OPTIONS INHERITED FROM PARENT COMMANDS
.PP
\fB\-c\fP, \fB\-\-context\fP=""
name of the kubeconfig context to use (default: kubectl config current\-context)

.PP
\fB\-k\fP, \fB\-\-kubeconfig\fP=""
kubectl config file (default: $HOME/.kube/config)

.PP
\fB\-n\fP, \fB\-\-namespace\fP=""
namespace to use (default: from $KUBECONFIG)

.PP
\fB\-C\fP, \fB\-\-no\-color\fP[=false]
disable coloring (default: false)


.SH EXAMPLE
.PP
Create a Task from ClusterTask 'foo' in namespace 'ns':
tkn task create \-\-from foo
or
tkn task create foobar \-\-from=foo \-n ns


.SH SEE ALSO
.PP
\fBtkn\-task(1)\fP
2 changes: 1 addition & 1 deletion docs/man/man1/tkn-task.1
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ Manage Tasks

.SH SEE ALSO
.PP
\fBtkn(1)\fP, \fBtkn\-task\-delete(1)\fP, \fBtkn\-task\-describe(1)\fP, \fBtkn\-task\-list(1)\fP, \fBtkn\-task\-logs(1)\fP, \fBtkn\-task\-start(1)\fP
\fBtkn(1)\fP, \fBtkn\-task\-create(1)\fP, \fBtkn\-task\-delete(1)\fP, \fBtkn\-task\-describe(1)\fP, \fBtkn\-task\-list(1)\fP, \fBtkn\-task\-logs(1)\fP, \fBtkn\-task\-start(1)\fP
29 changes: 29 additions & 0 deletions pkg/clustertask/clustertask.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand Down Expand Up @@ -117,3 +118,31 @@ func getV1alpha1(c *cli.Clients, clustertaskname string, opts metav1.GetOptions)
}
return clustertask, nil
}

func Create(c *cli.Clients, ct *v1beta1.ClusterTask, opts metav1.CreateOptions) (*v1beta1.ClusterTask, error) {
_, err := actions.GetGroupVersionResource(clustertaskGroupResource, c.Tekton.Discovery())
if err != nil {
return nil, err
}

return createUnstructured(ct, c, opts)
}

func createUnstructured(obj runtime.Object, c *cli.Clients, opts metav1.CreateOptions) (*v1beta1.ClusterTask, error) {
object, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
if err != nil {
return nil, err
}
unstructuredCT := &unstructured.Unstructured{
Object: object,
}
newUnstructuredCT, err := actions.Create(clustertaskGroupResource, c, unstructuredCT, "", opts)
if err != nil {
return nil, err
}
var clusterTask *v1beta1.ClusterTask
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(newUnstructuredCT.UnstructuredContent(), &clusterTask); err != nil {
return nil, err
}
return clusterTask, nil
}
31 changes: 31 additions & 0 deletions pkg/clustertask/clustertask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,34 @@ func TestClusterTaskV1beta1_Get(t *testing.T) {
}
test.AssertOutput(t, "clustertask", got.Name)
}

func TestClusterTask_Create(t *testing.T) {
version := "v1beta1"
clock := clockwork.NewFakeClock()
ctdata := []*v1beta1.ClusterTask{
{
ObjectMeta: metav1.ObjectMeta{
Name: "clustertask",
},
},
}
cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{})
cs.Pipeline.Resources = cb.APIResourceList(version, []string{"clustertask"})
tdc := testDynamic.Options{}
dc, err := tdc.Client()
if err != nil {
t.Errorf("unable to create dynamic client: %v", err)
}

p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc}
c, err := p.Clients()
if err != nil {
t.Errorf("unable to create client: %v", err)
}

got, err := Create(c, ctdata[0], metav1.CreateOptions{})
if err != nil {
t.Errorf("unexpected Error")
}
test.AssertOutput(t, "clustertask", got.Name)
}
1 change: 1 addition & 0 deletions pkg/cmd/clustertask/clustertask.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func Command(p cli.Params) *cobra.Command {
listCommand(p),
startCommand(p),
logCommand(p),
createCommand(p),
)
return cmd
}
Loading