Giter Site home page Giter Site logo

kubesys / client-go Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 2.0 209 KB

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

Home Page: https://www.yuque.com/kubesys/kubernetes-client/overview

License: Apache License 2.0

Go 100.00%
kubernetes openshift cdk8s operator-framework

client-go's Introduction

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

client-go's People

Contributors

chanyang97 avatar gxxxh avatar oneflyingfish avatar pttq avatar syswu avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

client-go's Issues

namespace should be optional

Input:

{
	"apiVersion": "v1",
	"kind": "Node",
	"metadata": {
		"name": "test"
	}
}

Output:

goroutine 1 [running]:
github.com/kubesys/kubernetes-client-go/pkg/kubesys.(*KubernetesClient).CreateResource(0x118b3fac, 0xe84b52, 0x40, 0xe8684a, 0x3b6, 0x118f00c0)
	D:/codes/golang/kubernetes-client-go/pkg/kubesys/client.go:143 +0x505
main.main()
	D:/codes/golang/kubernetes-client-go/main.go:15 +0x1d9

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.