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 triggerbinding list #541

Merged
merged 1 commit into from
Dec 23, 2019
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,17 @@ $ ./kubectl plugin list
The following commands help you understand and effectively use the Tekton CLI:

* `tkn help:` Displays a list of the commands with helpful information.
* [`tkn clustertask:`](docs/cmd/tkn_clustertask.md) Parent command of the ClusterTask command group.
* [`tkn completion:`](docs/cmd/tkn_completion.md) Outputs a BASH or ZSH completion script for `tkn` to allow command completion with Tab.
* [`tkn version:`](docs/cmd/tkn_version.md) Outputs the cli version.
* [`tkn condition:`](docs/cmd/tkn_condition.md) Parent command of the Condition command group.
* [`tkn pipeline:`](docs/cmd/tkn_pipeline.md) Parent command of the Pipeline command group.
* [`tkn pipelinerun:`](docs/cmd/tkn_pipelinerun.md) Parent command of the Pipelinerun command group.
* [`tkn resource:`](docs/cmd/tkn_resource.md) Parent command of the Resource command group.
* [`tkn task:`](docs/cmd/tkn_task.md) Parent command of the Task command group.
* [`tkn taskrun:`](docs/cmd/tkn_taskrun.md) Parent command of the Taskrun command group.
* [`tkn clustertask:`](docs/cmd/tkn_clustertask.md) Parent command of the ClusterTask command group.
* [`tkn resource:`](docs/cmd/tkn_resource.md) Parent command of the Resource command group.
* [`tkn condition:`](docs/cmd/tkn_condition.md) Parent command of the Condition command group.
* [`tkn triggerbinding:`](docs/cmd/tkn_triggerbinding.md) Parent command of the Triggerbinding command group.
* [`tkn triggertemplate:`](docs/cmd/tkn_triggertemplate.md) Parent command of the Triggertemplate command group.
* [`tkn version:`](docs/cmd/tkn_version.md) Outputs the cli version.

For every `tkn` command, you can use `-h` or `--help` flags to display specific help for that command.

Expand Down
1 change: 1 addition & 0 deletions docs/cmd/tkn.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CLI for tekton pipelines
* [tkn resource](tkn_resource.md) - Manage pipeline resources
* [tkn task](tkn_task.md) - Manage tasks
* [tkn taskrun](tkn_taskrun.md) - Manage taskruns
* [tkn triggerbinding](tkn_triggerbinding.md) - Manage triggerbindings
* [tkn triggertemplate](tkn_triggertemplate.md) - Manage triggertemplates
* [tkn version](tkn_version.md) - Prints version information

25 changes: 25 additions & 0 deletions docs/cmd/tkn_triggerbinding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## tkn triggerbinding

Manage triggerbindings

***Aliases**: tb,triggerbindings*

### Synopsis

Manage triggerbindings

### Options

```
-c, --context string name of the kubeconfig context to use (default: kubectl config current-context)
-h, --help help for triggerbinding
-k, --kubeconfig string kubectl config file (default: $HOME/.kube/config)
-n, --namespace string namespace to use (default: from $KUBECONFIG)
-C, --nocolour disable colouring (default: false)
```

### SEE ALSO

* [tkn](tkn.md) - CLI for tekton pipelines
* [tkn triggerbinding list](tkn_triggerbinding_list.md) - Lists triggerbindings in a namespace

49 changes: 49 additions & 0 deletions docs/cmd/tkn_triggerbinding_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## tkn triggerbinding list

Lists triggerbindings in a namespace

***Aliases**: ls*

### Usage

```
tkn triggerbinding list
```

### Synopsis

Lists triggerbindings in a namespace

### Examples

List all triggerbindings in namespace 'bar':

tkn triggerbinding list -n bar

or

tkn tb ls -n bar


### Options

```
--allow-missing-template-keys If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. (default true)
-h, --help help for list
-o, --output string Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
--template string Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
```

### 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, --nocolour disable colouring (default: false)
```

### SEE ALSO

* [tkn triggerbinding](tkn_triggerbinding.md) - Manage triggerbindings

86 changes: 86 additions & 0 deletions docs/man/man1/tkn-triggerbinding-list.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
.TH "TKN\-TRIGGERBINDING\-LIST" "1" "" "Auto generated by spf13/cobra" ""
.nh
.ad l


.SH NAME
.PP
tkn\-triggerbinding\-list \- Lists triggerbindings in a namespace


.SH SYNOPSIS
.PP
\fBtkn triggerbinding list\fP


.SH DESCRIPTION
.PP
Lists triggerbindings in a namespace


.SH OPTIONS
.PP
\fB\-\-allow\-missing\-template\-keys\fP[=true]
If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.

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

.PP
\fB\-o\fP, \fB\-\-output\fP=""
Output format. One of: json|yaml|name|go\-template|go\-template\-file|template|templatefile|jsonpath|jsonpath\-file.

.PP
\fB\-\-template\fP=""
Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [
\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]].


.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\-\-nocolour\fP[=false]
disable colouring (default: false)


.SH EXAMPLE
.PP
List all triggerbindings in namespace 'bar':

.PP
.RS

.nf
tkn triggerbinding list \-n bar

.fi
.RE

.PP
or

.PP
.RS

.nf
tkn tb ls \-n bar

.fi
.RE


.SH SEE ALSO
.PP
\fBtkn\-triggerbinding(1)\fP
45 changes: 45 additions & 0 deletions docs/man/man1/tkn-triggerbinding.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.TH "TKN\-TRIGGERBINDING" "1" "" "Auto generated by spf13/cobra" ""
.nh
.ad l


.SH NAME
.PP
tkn\-triggerbinding \- Manage triggerbindings


.SH SYNOPSIS
.PP
\fBtkn triggerbinding\fP


.SH DESCRIPTION
.PP
Manage triggerbindings


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

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

.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\-\-nocolour\fP[=false]
disable colouring (default: false)


.SH SEE ALSO
.PP
\fBtkn(1)\fP, \fBtkn\-triggerbinding\-list(1)\fP
2 changes: 1 addition & 1 deletion docs/man/man1/tkn.1
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ CLI for tekton pipelines

.SH SEE ALSO
.PP
\fBtkn\-clustertask(1)\fP, \fBtkn\-completion(1)\fP, \fBtkn\-condition(1)\fP, \fBtkn\-pipeline(1)\fP, \fBtkn\-pipelinerun(1)\fP, \fBtkn\-resource(1)\fP, \fBtkn\-task(1)\fP, \fBtkn\-taskrun(1)\fP, \fBtkn\-triggertemplate(1)\fP, \fBtkn\-version(1)\fP
\fBtkn\-clustertask(1)\fP, \fBtkn\-completion(1)\fP, \fBtkn\-condition(1)\fP, \fBtkn\-pipeline(1)\fP, \fBtkn\-pipelinerun(1)\fP, \fBtkn\-resource(1)\fP, \fBtkn\-task(1)\fP, \fBtkn\-taskrun(1)\fP, \fBtkn\-triggerbinding(1)\fP, \fBtkn\-triggertemplate(1)\fP, \fBtkn\-version(1)\fP
2 changes: 2 additions & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/tektoncd/cli/pkg/cmd/pipelinerun"
"github.com/tektoncd/cli/pkg/cmd/task"
"github.com/tektoncd/cli/pkg/cmd/taskrun"
"github.com/tektoncd/cli/pkg/cmd/triggerbinding"
"github.com/tektoncd/cli/pkg/cmd/triggertemplate"
"github.com/tektoncd/cli/pkg/cmd/version"
)
Expand Down Expand Up @@ -84,6 +85,7 @@ func Root(p cli.Params) *cobra.Command {
pipelinerun.Command(p),
task.Command(p),
taskrun.Command(p),
triggerbinding.Command(p),
triggertemplate.Command(p),
version.Command(),
)
Expand Down
133 changes: 133 additions & 0 deletions pkg/cmd/triggerbinding/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Copyright © 2019 The Tekton Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package triggerbinding

import (
"errors"
"fmt"
"text/tabwriter"

"github.com/spf13/cobra"
"github.com/tektoncd/cli/pkg/cli"
"github.com/tektoncd/cli/pkg/formatted"
"github.com/tektoncd/cli/pkg/helper/validate"
"github.com/tektoncd/cli/pkg/printer"
"github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
"github.com/tektoncd/triggers/pkg/client/clientset/versioned"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
cliopts "k8s.io/cli-runtime/pkg/genericclioptions"
)

const (
emptyMsg = "No triggerbindings found"
)

func listCommand(p cli.Params) *cobra.Command {
f := cliopts.NewPrintFlags("list")

eg := `List all triggerbindings in namespace 'bar':

tkn triggerbinding list -n bar

or

tkn tb ls -n bar
`

c := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "Lists triggerbindings in a namespace",
Annotations: map[string]string{
"commandType": "main",
},
Example: eg,
RunE: func(cmd *cobra.Command, args []string) error {
if err := validate.NamespaceExists(p); err != nil {
return err
}

cs, err := p.Clients()
if err != nil {
return err
}

tbs, err := list(cs.Triggers, p.Namespace())
if err != nil {
return fmt.Errorf(`failed to list triggerbindings from %s namespace \n`, p.Namespace())
}

output, err := cmd.LocalFlags().GetString("output")
if err != nil {
return errors.New(`output option not set properly \n`)
}

stream := &cli.Stream{
Out: cmd.OutOrStdout(),
Err: cmd.OutOrStderr(),
}

if output != "" {
return printer.PrintObject(stream.Out, tbs, f)
}

if err = printFormatted(stream, tbs, p); err != nil {
return errors.New(`failed to print triggerbindings \n`)
}
return nil

},
}

f.AddFlags(c)

return c
}

func list(client versioned.Interface, namespace string) (*v1alpha1.TriggerBindingList, error) {
tbs, err := client.TektonV1alpha1().TriggerBindings(namespace).List(metav1.ListOptions{})
if err != nil {
return nil, err
}

// NOTE: this is required for -o json|yaml to work properly since
// tektoncd go client fails to set these; probably a bug
tbs.GetObjectKind().SetGroupVersionKind(
schema.GroupVersionKind{
Version: "tekton.dev/v1alpha1",
Kind: "TriggerBindingList",
})

return tbs, nil
}

func printFormatted(s *cli.Stream, tbs *v1alpha1.TriggerBindingList, p cli.Params) error {
if len(tbs.Items) == 0 {
fmt.Fprintln(s.Err, emptyMsg)
return nil
}

w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "NAME\tAGE")
for _, tb := range tbs.Items {
fmt.Fprintf(w, "%s\t%s\n",
tb.Name,
formatted.Age(&tb.CreationTimestamp, p.Time()),
)
}

return w.Flush()
}
Loading