Skip to content

Commit

Permalink
Code for Release
Browse files Browse the repository at this point in the history
  • Loading branch information
vs4vijay committed Apr 22, 2020
1 parent d18c50e commit 7f4cd44
Show file tree
Hide file tree
Showing 12 changed files with 566 additions and 83 deletions.
30 changes: 30 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

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

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.14.x
-
name: GoReleaser Action
uses: goreleaser/goreleaser-action@v1.3.1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
*.out

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

.DS_Store
53 changes: 53 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
before:
hooks:
- go mod download

dist: bin

builds:
- env:
- CGO_ENABLED=0
goos:
- darwin
- linux
- windows
goarch:
- amd64
- 386

brews:
- name: lazykubectl
github:
owner: vs4vijay
name: homebrew-tap
url_template: "https://github.com/vs4vijay/lazykubectl/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
commit_author:
name: Vijay Soni (vs4vijay)
email: vs4vijay@gmail.com
folder: Formula
description: "lazykubectl - A better client for kubernetes"
skip_upload: false
install: |
bin.install "lazykubectl"
test: |
system "#{bin}/lazykubectl version"
archives:
- replacements:
darwin: mac
linux: linux
windows: windows
386: i386
amd64: x86_64

checksum:
name_template: "checksums.txt"

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

changelog:
filters:
exclude:
- "^docs:"
- "^test:"
161 changes: 80 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# lazykubectl

---

## Screenshots

![LazyKubectl Pods](_screenshots/lazykubectl_pods.png)

![LazyKubectl Containers](_screenshots/lazykubectl_containers.png)

![LazyKubectl Logs](_screenshots/lazykubectl_logs.png)


---

## References
- https://pkg.go.dev/k8s.io/client-go/kubernetes?tab=doc
- https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/

---

## ToDo
- [x] Auth
Expand Down Expand Up @@ -55,14 +67,11 @@ clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfig},
&clientcmd.ConfigOverrides{CurrentContext: kubeContext})

rawConfig, err := clientConfig.RawConfig()
rawConfig, err := clientConfig.RawConfig()
rawConfig.CurrentContext






go func() {
for event := range watch.ResultChan() {
fmt.Printf("Type: %v\n", event.Type)
Expand All @@ -78,97 +87,84 @@ time.Sleep(5 * time.Second)



watch, _ := api.Services("").Watch(metav1.ListOptions{})
for event := range watch.ResultChan() {
fmt.Printf("Type: %v\n", event.Type)
p, ok := event.Object.(*v1.Pod)
if !ok {
fmt.Errorf("unexpected type")
}
fmt.Println(p.Status.ContainerStatuses)
fmt.Println(p.Status.Phase)
watch, _ := api.Services("").Watch(metav1.ListOptions{})
for event := range watch.ResultChan() {
fmt.Printf("Type: %v\n", event.Type)
p, ok := event.Object.(*v1.Pod)
if !ok {
fmt.Errorf("unexpected type")
}
fmt.Println(p.Status.ContainerStatuses)
fmt.Println(p.Status.Phase)
}


watchlist := cache.NewListWatchFromClient(clientset.Core().RESTClient(), "pods", v1.NamespaceDefault,
fields.Everything())
_, controller := cache.NewInformer(
watchlist,
&v1.Pod{},
time.Second * 0,
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
fmt.Printf("add: %s \n", obj)
},
DeleteFunc: func(obj interface{}) {
fmt.Printf("delete: %s \n", obj)
},
UpdateFunc:func(oldObj, newObj interface{}) {
fmt.Printf("old: %s, new: %s \n", oldObj, newObj)
},
_, controller := cache.NewInformer(
watchlist,
&v1.Pod{},
time.Second * 0,
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
fmt.Printf("add: %s \n", obj)
},
)
stop := make(chan struct{})
go controller.Run(stop)
DeleteFunc: func(obj interface{}) {
fmt.Printf("delete: %s \n", obj)
},
UpdateFunc:func(oldObj, newObj interface{}) {
fmt.Printf("old: %s, new: %s \n", oldObj, newObj)
},
},
)
stop := make(chan struct{})
go controller.Run(stop)


informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().Pods(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().Pods(conf.Namespace).Watch(options)
},
},
&api_v1.Pod{},
0, //Skip resync
cache.Indexers{},
)




deploymentsClient := clientset.ExtensionsV1beta1().Deployments("namespace-ffledgling")

// List existing deployments in namespace
deployments, err := deploymentsClient.List(metav1.ListOptions{})


e.HTTPErrorHandler = func(err error, c echo.Context) {
// Take required information from error and context and send it to a service like New Relic
fmt.Println(c.Path(), c.QueryParams(), err.Error())

switch err.(type) {
case orchestrator.CustomError:
fmt.Println("custom")
default:
fmt.Println("normal") // here v has type interface{}
}
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.CoreV1().Pods(conf.Namespace).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.CoreV1().Pods(conf.Namespace).Watch(options)
},
},
&api_v1.Pod{},
0, //Skip resync
cache.Indexers{},
)

// Call the default handler to return the HTTP response
e.DefaultHTTPErrorHandler(err, c)
}

https://github.com/alitari/kubexp
e.HTTPErrorHandler = func(err error, c echo.Context) {
// Take required information from error and context and send it to a service like New Relic
fmt.Println(c.Path(), c.QueryParams(), err.Error())

https://github.com/JulienBreux/pody
switch err.(type) {
case orchestrator.CustomError:
fmt.Println("custom")
default:
fmt.Println("normal") // here v has type interface{}
}

// Call the default handler to return the HTTP response
e.DefaultHTTPErrorHandler(err, c)
}


if v, err := g.SetView("help", maxX-25, 0, maxX-1, 9); err != nil {
if err != gocui.ErrUnknownView {
return err
}
fmt.Fprintln(v, "KEYBINDINGS")
fmt.Fprintln(v, "Space: New View")
fmt.Fprintln(v, "Tab: Next View")
fmt.Fprintln(v, "← ↑ → ↓: Move View")
fmt.Fprintln(v, "Backspace: Delete View")
fmt.Fprintln(v, "t: Set view on top")
fmt.Fprintln(v, "b: Set view on bottom")
fmt.Fprintln(v, "^C: Exit")
}
if v, err := g.SetView("help", maxX-25, 0, maxX-1, 9); err != nil {
if err != gocui.ErrUnknownView {
return err
}
fmt.Fprintln(v, "KEYBINDINGS")
fmt.Fprintln(v, "Space: New View")
fmt.Fprintln(v, "Tab: Next View")
fmt.Fprintln(v, "← ↑ → ↓: Move View")
fmt.Fprintln(v, "Backspace: Delete View")
fmt.Fprintln(v, "t: Set view on top")
fmt.Fprintln(v, "b: Set view on bottom")
fmt.Fprintln(v, "^C: Exit")
}


func Loader() string {
Expand All @@ -179,6 +175,10 @@ func Loader() string {
return characters[index : index+1]
}

https://github.com/alitari/kubexp

https://github.com/JulienBreux/pody

https://stackoverflow.com/questions/40975307/how-to-watch-events-on-a-kubernetes-service-using-its-go-client

https://github.com/NetApp/trident/blob/master/k8s_client/k8s_client.go
Expand All @@ -197,5 +197,4 @@ NewSharedIndexInformer
https://raw.githubusercontent.com/kubernetes/kubernetes/master/hack/testdata/recursive/pod/pod/busybox.yaml
https://raw.githubusercontent.com/istio/istio/master/samples/sleep/sleep.yaml


```
Binary file added _screenshots/lazykubectl_containers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _screenshots/lazykubectl_logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _screenshots/lazykubectl_pods.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pkg/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
)

var (
app *App
app *App // TODO: Not needed here once we move trigger methods to App struct
viewSequence = []string{ViewInfo, ViewNamespaces, ViewMain, ViewLogs}
activeViewIndex = 0
state = map[string]string{} // TODO: Move this to App struct
Expand Down
18 changes: 18 additions & 0 deletions testdata/admin-role-binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system
15 changes: 15 additions & 0 deletions testdata/busybox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox1
labels:
app: busybox1
spec:
containers:
- image: busybox
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
name: busybox
restartPolicy: Always
Loading

0 comments on commit 7f4cd44

Please sign in to comment.