https://github.com/shipengqi/kube
A simple Kubernetes client, based on client-go.
https://github.com/shipengqi/kube
client-go kubernetes
Last synced: 7 months ago
JSON representation
A simple Kubernetes client, based on client-go.
- Host: GitHub
- URL: https://github.com/shipengqi/kube
- Owner: shipengqi
- License: apache-2.0
- Created: 2022-01-04T06:53:09.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-15T03:17:06.000Z (over 1 year ago)
- Last Synced: 2024-10-17T12:49:30.557Z (over 1 year ago)
- Topics: client-go, kubernetes
- Language: Go
- Homepage:
- Size: 284 KB
- Stars: 4
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kube
A simple Kubernetes client, based on [client-go](https://github.com/kubernetes/client-go).
[](https://github.com/shipengqi/kube/actions/workflows/e2e.yaml)
[](https://codecov.io/gh/shipengqi/kube)
[](https://goreportcard.com/report/github.com/shipengqi/kube)
[](https://github.com/shipengqi/kube/releases)
[](https://github.com/shipengqi/kube/blob/main/LICENSE)
## Getting Started
```go
package main
import (
"context"
"log"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"github.com/shipengqi/kube"
)
func main() {
kubeconfig := "testdata/config"
flags := genericclioptions.NewConfigFlags(false)
flags.KubeConfig = &kubeconfig
cfg := kube.NewConfig(flags)
cli := kube.New(cfg)
k8s, err := cli.Dial()
if err != nil {
log.Fatal(err)
}
// get a configmap named "configmapname"
cm, err := k8s.CoreV1().ConfigMaps("default").Get(context.TODO(), "configmapname", metav1.GetOptions{})
log.Println(cm.Data)
// or
cm, err = cli.GetConfigMap(context.TODO(), "default", "configmapname")
log.Println(cm.Data)
// apply file, is like "kubectl apply -f testdata/content-apply.yaml"
err = cli.Apply("testdata/content-apply.yaml")
if err != nil {
log.Fatal(err)
}
// delete file, is like "kubectl delete -f testdata/content-apply.yaml"
err = cli.Delete("testdata/content-apply.yaml")
if err != nil {
log.Fatal(err)
}
// Exec in a pod, is like "kubectl exec -n -c -- "
stdout, stderr, err := cli.Exec("podname", "containername", "namespace", "command")
if err != nil {
log.Println(stderr)
log.Fatal(err)
}
log.Println(stdout)
// Uploads local file to a remote pod
err = cli.Upload(context.TODO(), "podname", "containername", "namespace", "testdata/upload.txt", "/testdata")
if err != nil {
log.Fatal(err)
}
// Downloads file from a remote pod to local file system
err = cli.Download(context.TODO(), "podname", "containername", "namespace", "testdata/upload.txt", "testdata")
if err != nil {
log.Fatal(err)
}
}
```
## Documentation
You can find the docs at [go docs](https://pkg.go.dev/github.com/shipengqi/kube).
## Test
```bash
go test -v . -kubeconfig
```
Tests Client.Upload, Client.Download And Client.Exec with specified pod, container, namespace:
```bash
go test -v -kubeconfig -container -pod -namespace .
```
## 🔋 JetBrains OS licenses
`kube` had been being developed with **GoLand** under the **free JetBrains Open Source license(s)** granted by JetBrains s.r.o., hence I would like to express my thanks here.