https://github.com/kubesphere/client-go
https://github.com/kubesphere/client-go
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kubesphere/client-go
- Owner: kubesphere
- License: apache-2.0
- Created: 2021-03-03T08:21:43.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-02T11:22:46.000Z (over 1 year ago)
- Last Synced: 2024-04-13T21:23:17.563Z (over 1 year ago)
- Language: Go
- Size: 245 KB
- Stars: 9
- Watchers: 4
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# KubeSphere client-go Project
The KubeSphere client-go Project is a rest-client of go libraries for communicating with the KubeSphere API Server.
# How to use it
1. Import client-go packages:
```golang
import (
"kubesphere.io/client-go/rest"
"kubesphere.io/client-go/client"
"kubesphere.io/client-go/client/generic"
)
```
2. Create a generic client instance:
```golang
var client client.Client
config := &rest.Config{
Host: "127.0.0.1:9090",
Username: "admin",
Password: "P@88w0rd",
}
client = generic.NewForConfigOrDie(config, client.Options{Scheme: f.Scheme})
```
> generic.NewForConfigOrDie returns a client.Client that reads and writes from/to an KubeSphere API server.
> It's only compatible with Kubernetes-like API objects.
3. KubeSphere API server provided a proxy to Kubernetes API Server. The client can read and write those Kubernetes native objects with the client directly.
```golang
deploy := &appsv1.Deployment{}
client.Get(context.TODO(), client.ObjectKey{Namespace: "kubesphere-system", Name: "ks-apiserver"}, deploy)
```
4. URLOptions and WorkspaceOptions can be provided to read and write Kubernetes likely Object that provided by KubeSphere API.
```golang
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "ks-test",
Labels: map[string]string{
constants.WorkspaceLabelKey: "Workspace",
},
},
}
opts := &client.URLOptions{
Group: "tenant.kubesphere.io",
Version: "v1alpha2",
}
err := f.GenericClient(f.BaseName).Create(context.TODO(), ns, opts, &client.WorkspaceOptions{Name: "Workspace"})
```
The KubeSphere API Architecture can be found at https://kubesphere.io/docs/reference/api-docs/
# Where does it come from?
client-go is synced from https://github.com/kubesphere/kubesphere/blob/master/staging/src/kubesphere.io/client-go. Code changes are made in that location, merged into `kubesphere.io/client-go` and later synced here.