/client-go

Golang client for Kubernetes-based systems using JSON styles, move to https://gitee.com/iscas-system/client

Primary LanguageGoApache License 2.0Apache-2.0

client-go

We expect to provide a go client:

  • Flexibility. It can support all Kubernetes-based systems with minimized extra development, such as Openshift, istio, etc.
  • Usability. Developers just need to learn to write json/yaml(kubernetes native style) from Kubernetes documentation.
  • Integration. It can work with the other Kubernetes clients, such as official.

This project is based on the following softwares.

NAME Website LICENSE
gjson https://github.com/tidwall/gjson MIT
match https://github.com/tidwall/match MIT
pretty https://github.com/tidwall/pretty MIT

Comparison

official cdk8s this project
Compatibility for kubernetes-native kinds for crd kinds for both
Support customized Kubernetes resources a lot of development a lot of development zero-deployment
Works with the other SDKs complex complex simple

Supported

  • National Key Research and Development Program of China (2023YFB3308702)

Architecture

avatar

Installation

git clone --recursive https://github.com/kubesys/client-go

Maven users

Usage

Creating a client

There are two ways to create a client:

  • By url and token:
client := new KubernetesClient(url, token);
client.Init()

Here, the token can be created and get by following commands:

  1. create token
kubectl create -f https://raw.githubusercontent.com/kubesys/client-go/master/account.yaml
  1. get token
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep kubernetes-client | awk '{print $1}') | grep "token:" | awk -F":" '{print$2}' | sed 's/ //g'

  • By kubeconfig:
client := kubesys.NewKubernetesClientWithDefaultKubeConfig()
client.Init()

simple-example

Assume you have a json:

{
  "apiVersion": "v1",
  "kind": "Pod",
  "metadata": {
    "name": "busybox1",
    "namespace": "default"
  },
  "spec": {
    "containers": [
      {
        "command": [
          "sleep",
          "3600"
        ],
        "image": "busybox",
        "imagePullPolicy": "IfNotPresent",
        "name": "busybox"
      }
    ]
  }
}

List resources:

client.ListResources("Pod")

Create a resource:

client.CreateResource(json);

Get a resource:

client.GetResource("Pod", "default", "busybox");

Delete a resource::

client.DeleteResource("Pod", "default", "busybox")

get-all-kinds

fmt.Println(client.GetKinds());

for developer

go mod init client-go
go mod tidy

RoadMap

  • 2.0.x: product ready
    • 2.0.0: using jsonparser
    • 2.0.1: support kubeconfig
    • 2.0.2: support yaml
    • 2.0.3: support binding