'kubernetes go sdk simple demo

the demo source code

package main

import (
    "fmt"
    "time"

    "k8s.io/apimachinery/pkg/util/wait"
    "k8s.io/client-go/informers"
    "k8s.io/client-go/kubernetes"
    "k8s.io/client-go/tools/cache"
    "k8s.io/client-go/tools/clientcmd"
)

func main() {

    config, err := clientcmd.BuildConfigFromFlags("", "pre.config")
    if err != nil {
        panic(err.Error())
    }
    // create the clientset
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }
    infromerFactory := informers.NewSharedInformerFactory(clientset, 10*time.Second)
    podInfromer := infromerFactory.Core().V1().Pods()
    podInfromer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
        AddFunc: func(new interface{}) {
            fmt.Printf("add pods %v\n", new)
        },
        UpdateFunc: func(oldObj, newObj interface{}) {
            fmt.Printf("update:old  %v-> new %v\n", oldObj, newObj)
        },
        DeleteFunc: func(obj interface{}) {
            fmt.Printf("delete pods %v\n", obj)
        },
    })
    infromerFactory.Start(wait.NeverStop)
    infromerFactory.WaitForCacheSync(wait.NeverStop)

}

when i run demo code with Visual Studio Code ,but occur error: the Visual Studio console

DAP server listening at: 127.0.0.1:61048 Type 'dlv help' for list of commands. 2022-05-15T14:48:12+08:00 error layer=dap runtime error: bad access

Could not load source '': Unsupported command: cannot process "source" request.

error message

what's wrong the demo code?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source