示例#1
0
// newSourceApiserverFromLW holds creates a config source that watches an pulls from the apiserver.
func newSourceApiserverFromLW(lw cache.ListerWatcher, updates chan<- interface{}) {
	send := func(objs []interface{}) {
		var bpods []api.BoundPod
		for _, o := range objs {
			pod := o.(*api.Pod)
			bpod := api.BoundPod{}
			if err := api.Scheme.Convert(pod, &bpod); err != nil {
				glog.Errorf("Unable to interpret Pod from apiserver as a BoundPod: %v: %+v", err, pod)
				continue
			}
			// Make a dummy self link so that references to this bound pod will work.
			bpod.SelfLink = "/api/v1beta1/boundPods/" + bpod.Name
			bpods = append(bpods, bpod)
		}
		updates <- kubelet.PodUpdate{bpods, kubelet.SET, kubelet.ApiserverSource}
	}
	cache.NewReflector(lw, &api.Pod{}, cache.NewUndeltaStore(send)).Run()
}