MCPcopy
hub / github.com/kubernetes/client-go / syncToStdout

Method syncToStdout

examples/workqueue/main.go:72–88  ·  view source on GitHub ↗

syncToStdout is the business logic of the controller. In this controller it simply prints information about the pod to stdout. In case an error happened, it has to simply return the error. The retry logic should not be part of the business logic.

(key string)

Source from the content-addressed store, hash-verified

70// information about the pod to stdout. In case an error happened, it has to simply return the error.
71// The retry logic should not be part of the business logic.
72func (c *Controller) syncToStdout(key string) error {
73 obj, exists, err := c.indexer.GetByKey(key)
74 if err != nil {
75 klog.Errorf("Fetching object with key %s from store failed with %v", key, err)
76 return err
77 }
78
79 if !exists {
80 // Below we will warm up our cache with a Pod, so that we will see a delete for one pod
81 fmt.Printf("Pod %s does not exist anymore\n", key)
82 } else {
83 // Note that you also have to check the uid if you have a local controlled resource, which
84 // is dependent on the actual instance, to detect that a Pod was recreated with the same name
85 fmt.Printf("Sync/Add/Update for Pod %s\n", obj.(*v1.Pod).GetName())
86 }
87 return nil
88}
89
90// handleErr checks if an error happened and makes sure we will retry later.
91func (c *Controller) handleErr(err error, key interface{}) {

Callers 1

processNextItemMethod · 0.95

Implementers 3

controllertools/cache/controller.go
dummyControllertools/cache/shared_informer.go
sharedIndexInformertools/cache/shared_informer.go

Calls 3

GetByKeyMethod · 0.65
ErrorfMethod · 0.65
GetNameMethod · 0.65

Tested by

no test coverage detected