mirror of
https://github.com/imjasonh/client-go2
synced 2026-07-18 14:46:27 +00:00
Update to use stable Go and add comprehensive CI/CD
- Replace gotip with stable Go in GitHub Actions - Add automatic GVR inference for Kubernetes types - Rename API: NewClient (inferred GVR) and NewClientGVR (explicit) - Add comprehensive test coverage including e2e tests - Update CI to include linting, unit tests, and e2e tests with kind - Add .gitignore for common Go development files - Update README with usage examples and features 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
d6bb3cc61c
commit
74aace1a2d
7 changed files with 554 additions and 122 deletions
85
README.md
85
README.md
|
|
@ -4,31 +4,74 @@
|
|||
|
||||
This is an experimental type-parameter-aware client that wraps [`k8s.io/client-go/dynamic`](https://pkg.go.dev/k8s.io/client-go/dynamic) _(...for now)_.
|
||||
|
||||
Assuming you've got a working kubeconfig (does `kubectl get pods` work?), you can run this code:
|
||||
## Features
|
||||
|
||||
- **Type-safe generic client** - Work with strongly-typed Kubernetes objects instead of `unstructured.Unstructured`
|
||||
- **Automatic GVR inference** - No need to manually specify GroupVersionResource for standard Kubernetes types
|
||||
- **Full CRUD operations** - List, Get, Create, Update, Delete, and Patch support
|
||||
- **Informer support** - Watch for changes with type-safe event handlers
|
||||
- **Zero code generation** - Uses Go generics instead of code generation
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
// Create a client that automatically infers the GVR from the type
|
||||
podClient, err := generic.NewClient[*corev1.Pod](config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// List pods in a namespace
|
||||
pods, err := podClient.List(ctx, "kube-system")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Create a ConfigMap
|
||||
cmClient, err := generic.NewClient[*corev1.ConfigMap](config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = cmClient.Create(ctx, "default", &corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "my-config",
|
||||
},
|
||||
Data: map[string]string{
|
||||
"key": "value",
|
||||
},
|
||||
})
|
||||
|
||||
// If you need to specify a custom GVR, use NewClientGVR
|
||||
customClient := generic.NewClientGVR[*corev1.Pod](customGVR, config)
|
||||
```
|
||||
|
||||
## Running the Example
|
||||
|
||||
```
|
||||
$ go run ./
|
||||
2021/12/15 12:08:11 LISTING PODS
|
||||
2021/12/15 12:08:11 - coredns-558bd4d5db-hjs27
|
||||
2021/12/15 12:08:11 - coredns-558bd4d5db-vhrtd
|
||||
2021/12/15 12:08:11 - etcd-kind-control-plane
|
||||
2021/12/15 12:08:11 - kindnet-c977m
|
||||
2021/12/15 12:08:11 - kube-apiserver-kind-control-plane
|
||||
2021/12/15 12:08:11 - kube-controller-manager-kind-control-plane
|
||||
2021/12/15 12:08:11 - kube-proxy-fgpfd
|
||||
2021/12/15 12:08:11 - kube-scheduler-kind-control-plane
|
||||
I1215 12:08:11.086322 32526 shared_informer.go:240] Waiting for caches to sync for /v1, Resource=configmaps
|
||||
2021/12/15 12:08:11 --> ADD kube-public/cluster-info
|
||||
2021/12/15 12:08:11 --> ADD kube-system/extension-apiserver-authentication
|
||||
2021/12/15 12:08:11 --> ADD tekton-pipelines/config-logging
|
||||
2025/07/23 11:23:10 LISTING PODS
|
||||
2025/07/23 11:23:10 - coredns-674b8bbfcf-ddcww
|
||||
2025/07/23 11:23:10 - coredns-674b8bbfcf-dqqx5
|
||||
2025/07/23 11:23:10 - etcd-kind-control-plane
|
||||
2025/07/23 11:23:10 - kindnet-tkf6l
|
||||
2025/07/23 11:23:10 - kube-apiserver-kind-control-plane
|
||||
2025/07/23 11:23:10 - kube-controller-manager-kind-control-plane
|
||||
2025/07/23 11:23:10 - kube-proxy-76tcd
|
||||
2025/07/23 11:23:10 - kube-scheduler-kind-control-plane
|
||||
...
|
||||
2021/12/15 12:08:11 LISTING CONFIGMAPS
|
||||
2021/12/15 12:08:11 - coredns
|
||||
2021/12/15 12:08:11 - extension-apiserver-authentication
|
||||
2021/12/15 12:08:11 - kube-proxy
|
||||
2021/12/15 12:08:11 - kube-root-ca.crt
|
||||
2021/12/15 12:08:11 - kubeadm-config
|
||||
2021/12/15 12:08:11 - kubelet-config-1.21
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
Run unit tests:
|
||||
```bash
|
||||
go test ./generic
|
||||
```
|
||||
|
||||
Run e2e tests (requires a Kubernetes cluster):
|
||||
```bash
|
||||
go test ./generic -tags=e2e
|
||||
```
|
||||
|
||||
# THIS IS AN EXPERIMENT
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue