1
0
Fork 0
mirror of https://github.com/imjasonh/client-go2 synced 2026-07-16 20:26:57 +00:00

Playing with generic informers

This commit is contained in:
Jason Hall 2021-12-15 12:05:35 -05:00
parent ec96ad4354
commit fa4eb4d0f2
4 changed files with 52 additions and 5 deletions

11
main.go
View file

@ -36,13 +36,18 @@ func main() {
if err != nil {
log.Fatal("listing pods:", err)
}
log.Println("PODS")
log.Println("LISTING PODS")
for _, p := range pods {
log.Println("-", p.Name)
}
// Create a ConfigMap, then list ConfigMaps.
cmc := generic.NewClient[*corev1.ConfigMap](cmGVR, config)
cmc.Start(ctx)
// Start an informer to log all adds/updates/deletes for ConfigMaps.
cmc.Inform(ctx)
// Create a ConfigMap, then list ConfigMaps.
if err := cmc.Create(ctx, "kube-system", &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "foo-",
@ -57,7 +62,7 @@ func main() {
if err != nil {
log.Fatal("listing configmaps:", err)
}
log.Println("CONFIGMAPS")
log.Println("LISTING CONFIGMAPS")
for _, cm := range cms {
log.Println("-", cm.Name)
}