client-go

command module
v1.1.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

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

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

Documentation

Overview

Copyright (2021, ) Institute of Software, Chinese Academy of Sciences

Directories

Path Synopsis
examples
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL