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)
| 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. |
| 72 | func (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. |
| 91 | func (c *Controller) handleErr(err error, key interface{}) { |
no test coverage detected