Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-biswas committed Feb 8, 2024
0 parents commit ec3cd58
Show file tree
Hide file tree
Showing 4,857 changed files with 1,538,594 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
34 changes: 34 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
branches:
- "!*"
tags:
- "v*.*.*"

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_OWNER: ${{ github.repository_owner }}
GITHUB_REPOSITORY: ${{ github.repository }}
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# IDE
.idea
.vscode

# OS
._*
.DS_Store

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

dist/
69 changes: 69 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
project_name: kubectl-tekton

before:
hooks:
- go mod tidy

builds:
- main: ./cmd/tekton.go
binary: tekton
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

archives:
- format: tar.gz
name_template: "{{ .Binary }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
files:
- README.md
- LICENSE*

checksum:
disable: true
name_template: "{{ .ProjectName }}-{{ .Version }}-checksums.txt"
algorithm: sha256

snapshot:
name_template: "{{ .Tag }}-next"

changelog:
sort: asc
use: github
filters:
exclude:
- '^docs:'
- '^test:'

release:
name_template: "v{{ .Version }}"
prerelease: auto
make_latest: true
header: "Tekton Plugin v{{ .Version }}"

source:
enabled: false

krews:
- name: tekton
url_template: "https:/{{ .Env.GITHUB_REPOSITORY }}/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
commit_author:
name: Sayan Biswas
email: [email protected]
commit_msg_template: "Krew plugin update for {{ .ProjectName }} version {{ .Tag }}"
homepage: "https:/{{ .Env.GITHUB_REPOSITORY }}"
description: "Kubectl plugin to query tekton resources"
short_description: "Kubectl plugin to query tekton resources"
caveats: "kubectl tekton --help"
skip_upload: false
repository:
owner: "{{ .Env.GITHUB_OWNER }}"
name: "{{ base .Env.GITHUB_REPOSITORY }}"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Sayan Biswas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
131 changes: 131 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# kubectl-tekton
kubectl-tekton is a plugin for kubectl CLI for fetching tekton resources from tekton results.

## Installation

Easiest way to install the plugin is using Krew plugin manager.
```shell
kubectl krew index add test https:/sayan-biswas/kubectl-tekton.git
```
```shell
kubectl krew install test/tekton
```

## Usage

### Configuration

Configure tekton results client
```shell
kubectl tekton config results
```

Reconfigure tekton results client
```shell
kubectl tekton config results --reset
```

Configure specific properties
```shell
kubectl tekton config results host token
```

Non-interactive configuration (no validation)
```shell
kubectl tekton config results host="https://localhost:8080" token="test-token"
```

The configuration is stored in kubeconfig context extension. This enables storing multiple tekton results configuration per context.

In Openshift platform with proper access the CLI can discover installed tekton results instances.

### Fetching Resources

List resources from a namespace
```shell
kubectl tekton get pr -n default
````

List limited resources from a namespace. By default only 10 resources are listed.
```shell
kubectl tekton get pr -n default --limit 20
```

Get resources by specifying name. Partial name can also be provided.
```shell
kubectl tekton get pr test -n default
```

Get resources by specifying UID. Partial UID can also be provided.
```shell
kubectl tekton get pr test -n default --uid="e0e4148c-b914"
```

List resources from a namespace with selectors. All the selectors support partial value.
```shell
kubectl tekton get pr -n default
--labels="app.kubernetes.io/name=test-app, app.kubernetes.io/component=database"
```

All selectors can be used together and works as AND operator.
```shell
kubectl tekton get pr -n default
--labels="app.kubernetes.io/name=test-app"
--annotations="app.io/timeout=100"
```

All selectors except OwnerReferences can work with only key or value.
```shell
kubectl tekton get pr -n default --annotations="test" --labels="test"
```

Check if a particular annotation exists, without knowing the value.
```shell
kubectl tekton get pr -n default --annotations="results.tekton.dev/log"
```

OwnerReferences filter can not filter by key/value pair, but the filter should still be provided as key/value.
```shell
kubectl tekton get pr -n default --owner-references="kind=Service name=test-service"
```

Multiple owner references can be provided, but keys of each owner references should be seperated by space.
```shell
kubectl tekton get pr -n default
--owner-references="kind=Service name=test-service, kind=Deployment name=test-app"
```

OwnerReferences filter can be used to find child resources.
```shell
kubectl tekton get pr -n default --owner-references="name=parent-name"
```

Filter flag can be used to pass raw filter. Invalid syntax will cause error.
```shell
kubectl tekton get pr -n default --filter="data.status.conditions[0].reason in ['Failed']"
```

All the filters with partial string also.

Flags
```
--uid filter resource by UID
--output print resource in JSON and YAML
--limit limit number of items in page
--labels filter resources by lables
--annotations filter resources by annotations
--finalizers filter resources by finalizers
--owner-references filter resources by owner references
--filter filter resources using raw filter string
```

### Fetching Logs

Get PipelineRun logs
```shell
kubectl tekton logs pr testpr -n default
```
Get TaskRun logs
```shell
kubectl tekton logs tr testtr -n default --uid="436dd41a-fd8a-4a29-b4f3-389b221af5dc"
```
17 changes: 17 additions & 0 deletions cmd/tekton.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"github.com/sayan-biswas/kubectl-tekton/internal/cmd"
"github.com/spf13/pflag"
"k8s.io/kubectl/pkg/cmd/util"
)

func main() {
flags := pflag.NewFlagSet("kubectl-tekton", pflag.ExitOnError)
pflag.CommandLine = flags

c := cmd.Command()
if err := c.Execute(); err != nil {
util.CheckErr(err)
}
}
Loading

0 comments on commit ec3cd58

Please sign in to comment.