Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinvaneyk committed Jan 14, 2020
0 parents commit 7bc626b
Show file tree
Hide file tree
Showing 9 changed files with 660 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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/

bin/
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) 2020 Erwin van Eyk

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.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
all: kubectl-tap

kubectl-tap:
go build -o bin/kubectl-tap ./cmd/kubectl-tap

release: changelog
GOOS=darwin GOARCH=amd64 go build -o bin/kubectl-tap-darwin-amd64 ./cmd/kubectl-tap
GOOS=linux GOARCH=amd64 go build -o bin/kubectl-tap-linux-amd64 ./cmd/kubectl-tap

changelog:
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator:1.15.0 -u erwinvaneyk -p kubectl-tap
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# kubectl-tap
A kubectl command to trigger immediate reevaluation of Kubernetes objects. It
does this by updating an annotation--by default the key `tapped`--of the object.

This functionality generally is useful when developing or debugging
controllers/operators, to avoid waiting for the periodic reconciliation loop
(which can take minutes). By updating the annotation, the object will be
enqueued and evaluated immediately by the corresponding controllers.

## Installation
This project is a [Kubectl plugin](https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/),
which means that it will be available as a subcommand in your local `kubectl` as
long as `kubectl-tap` is present under your PATH.

Install a prebuilt binary from one of the [releases](https://github.com/erwinvaneyk/kubectl-tap/releases):
```bash
VERSION=0.1.0
OS=darwin # options: [darwin, linux]
curl -fsSL -o kubectl-tap https://github.com/erwinvaneyk/kubectl-tap/releases/download/$VERSION/kubectl-tap-$OS-amd64
chmod u+x ./kubectl-tap
mv ./kubectl-tap /usr/local/bin/kubectl-tap
```

## Usage

Tap a single pod--for example the `kube-apiserver` pod in the `kube-system`:
```bash
$ kubectl tap -n kube-system pod/kube-apiserver
```

If you view the pod, an annotation should have been added to reflect the tap:
```bash
$ kubectl get -n kube-system pod/kube-apiserver -o yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
tapped: "2020-01-14T11:06:02+01:00"
[...]
```

The command works similar to the regular commands of kubectl:
```bash
# Tap all deployments in kube-system
kubectl tap -n kube-system deployments --all

# Tap all pods with the `component: kube-apiserver` label
kubectl tap -n kube-system -l component=kube-apiserver pod
```
18 changes: 18 additions & 0 deletions cmd/kubectl-tap/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"github.com/erwinvaneyk/kubectl-tap/pkg/cmd"
"github.com/spf13/pflag"
"k8s.io/cli-runtime/pkg/genericclioptions"
"os"
)

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

root := cmd.NewCmdTap(genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr})
if err := root.Execute(); err != nil {
os.Exit(1)
}
}
21 changes: 21 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module github.com/erwinvaneyk/kubectl-tap

go 1.13

require (
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
k8s.io/apimachinery v0.17.0
k8s.io/cli-runtime v0.17.0
k8s.io/client-go v0.17.0
k8s.io/kubectl v0.17.0
)

replace (
golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
k8s.io/api => k8s.io/api v0.0.0-20200113233642-3946df5ca773
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200113233504-44bd77c24ef9
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20200113235527-4c0b167ce833
k8s.io/client-go => k8s.io/client-go v0.0.0-20200113233857-bcaa73156d59
)
Loading

0 comments on commit 7bc626b

Please sign in to comment.