mirror of
https://github.com/imjasonh/client-go2
synced 2026-07-18 22:58:43 +00:00
just take a GVR in NewClient
This commit is contained in:
parent
5539a6fa1d
commit
08c01c3a33
2 changed files with 26 additions and 31 deletions
20
main.go
20
main.go
|
|
@ -8,9 +8,23 @@ 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/clientcmd"
|
||||
)
|
||||
|
||||
var (
|
||||
podGVR = schema.GroupVersionResource{
|
||||
Group: "",
|
||||
Version: "v1",
|
||||
Resource: "pods",
|
||||
}
|
||||
cmGVR = schema.GroupVersionResource{
|
||||
Group: "",
|
||||
Version: "v1",
|
||||
Resource: "configmaps",
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
// This is load bearing...
|
||||
// Without this, while the client is in generic/, I get a mysterious compiler error:
|
||||
|
|
@ -24,7 +38,7 @@ func main() {
|
|||
}
|
||||
|
||||
// List pods in kube-system.
|
||||
pods, err := generic.NewClient[*corev1.Pod](config).List(ctx, "kube-system")
|
||||
pods, err := generic.NewClient[corev1.Pod](podGVR, config).List(ctx, "kube-system")
|
||||
if err != nil {
|
||||
log.Fatal("listing pods:", err)
|
||||
}
|
||||
|
|
@ -34,8 +48,8 @@ func main() {
|
|||
}
|
||||
|
||||
// Create a ConfigMap, then list ConfigMaps.
|
||||
cmc := generic.NewClient[*corev1.ConfigMap](config)
|
||||
if err := cmc.Create(ctx, "kube-system", &corev1.ConfigMap{
|
||||
cmc := generic.NewClient[corev1.ConfigMap](cmGVR, config)
|
||||
if err := cmc.Create(ctx, "kube-system", corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
GenerateName: "foo-",
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue