mirror of
https://github.com/imjasonh/client-go2
synced 2026-07-18 06:37:34 +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
28
main.go
28
main.go
|
|
@ -7,24 +7,10 @@ import (
|
|||
"github.com/imjasonh/client-go2/generic"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
var (
|
||||
podGVR = schema.GroupVersionResource{
|
||||
Group: "",
|
||||
Version: "v1",
|
||||
Resource: "pods",
|
||||
}
|
||||
cmGVR = schema.GroupVersionResource{
|
||||
Group: "",
|
||||
Version: "v1",
|
||||
Resource: "configmaps",
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(clientcmd.NewDefaultClientConfigLoadingRules(), &clientcmd.ConfigOverrides{}).ClientConfig()
|
||||
|
|
@ -32,8 +18,12 @@ func main() {
|
|||
log.Fatalf("ClientConfig: %v", err)
|
||||
}
|
||||
|
||||
// List pods in kube-system.
|
||||
pods, err := generic.NewClient[*corev1.Pod](podGVR, config).List(ctx, "kube-system")
|
||||
// List pods in kube-system using automatic GVR inference.
|
||||
podClient, err := generic.NewClient[*corev1.Pod](config)
|
||||
if err != nil {
|
||||
log.Fatal("creating pod client:", err)
|
||||
}
|
||||
pods, err := podClient.List(ctx, "kube-system")
|
||||
if err != nil {
|
||||
log.Fatal("listing pods:", err)
|
||||
}
|
||||
|
|
@ -42,7 +32,11 @@ func main() {
|
|||
log.Println("-", p.Name)
|
||||
}
|
||||
|
||||
cmc := generic.NewClient[*corev1.ConfigMap](cmGVR, config)
|
||||
// For ConfigMaps, we'll also use automatic GVR inference
|
||||
cmc, err := generic.NewClient[*corev1.ConfigMap](config)
|
||||
if err != nil {
|
||||
log.Fatal("creating configmap client:", err)
|
||||
}
|
||||
cmc.Start(ctx)
|
||||
|
||||
// Start an informer to log all adds/updates/deletes for ConfigMaps.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue