Skip to content

Instantly share code, notes, and snippets.

@bzub
Created August 6, 2017 20:35
Show Gist options
  • Save bzub/06824111896816095464861e20eba4a0 to your computer and use it in GitHub Desktop.
Save bzub/06824111896816095464861e20eba4a0 to your computer and use it in GitHub Desktop.
kube-router - Watcher Refactoring

Watcher Refactoring Notes

@Thoros Generic Watcher

Generic Watcher Code: https://gist.github.com/Thoro/2e81754c253a85981e06d4fd6839eee7

Use in controllers:

func (nec *NetworkEgressController) OnItemUpdate(update *watchers.Update) { nec.mu.Lock(); defer nec.mu.Unlock() switch v:= update.Item.(type) {
        default:
            glog.Infof("DEFAULT: %v", update.Item)
        case *creamfinance.PodIP:
            nec.OnPodIPUpdate(update.Op, v)
        case *api.Node:
            glog.Infof("Node UPDATE: %v", v.Name)
        case *api.Service:
            nec.OnServiceUpdate(update.Op, v)
        case *apiextensions.NetworkPolicy:
            nec.OnNetworkPolicyUpdate(update.Op, v)
        case *api.Pod:
            nec.OnPodUpdate(update.Op, v)
        case *api.Endpoints:
            glog.Infof("Endpoint UPDATE: %v", v.Name)
    } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment