Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shipengqi/kube

A simple Kubernetes client, based on client-go.
https://github.com/shipengqi/kube

client-go kubernetes

Last synced: 2 months ago
JSON representation

A simple Kubernetes client, based on client-go.

Awesome Lists containing this project

README

        

# kube

A simple Kubernetes client, based on [client-go](https://github.com/kubernetes/client-go).

[![E2E](https://github.com/shipengqi/kube/actions/workflows/e2e.yaml/badge.svg)](https://github.com/shipengqi/kube/actions/workflows/e2e.yaml)
[![codecov](https://codecov.io/gh/shipengqi/kube/branch/main/graph/badge.svg?token=0KSRZKV4C8)](https://codecov.io/gh/shipengqi/kube)
[![Go Report Card](https://goreportcard.com/badge/github.com/shipengqi/kube)](https://goreportcard.com/report/github.com/shipengqi/kube)
[![Release](https://img.shields.io/github/release/shipengqi/kube.svg)](https://github.com/shipengqi/kube/releases)
[![License](https://img.shields.io/github/license/shipengqi/kube)](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.

JetBrains Logo (Main) logo.