-
-
Save sub-mod/fe29ed45e89afdfdbf55613ac120ea0c to your computer and use it in GitHub Desktop.
Revisions
-
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ It should be noted that the **reflect.Type** is usually a Kind of Kubernetes Obj ### Toy Example Usage of Reflector ### Before going deeper into the implementation of Reflector, let's have a look at how Reflector can be used from a [example](https://github.com/songbinliu/KubeReflectorTest). This example will watch the changes(including ADD, DELETE, MODIFY) of all the Pods in the Kubernetes cluster. According to the changes, it will add(or update) Pod object into the *Store* if a Pod is created(or updated), and delete a Pod object from the *Store* if the Pod is killed in the Kubernetes. In addition, it will also print all the Pod names every 30 seconds: If a Pod is deleted, then its name won't appear; if a Pod is created, its name will appear. ```go -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ Here is the definition of Reflector. As shown in the definition, there are two important compoents of a Reflector: - **ListerWatcher** It provides two functions: *List* and *Watch*. These two functions will talk with Kubernetes API-server, and get the Events. - **Store** -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ ## Kubernetes Reflector ## Reflector is a key component for Kubernetes clients, kube-scheduler and Replication Controller. Reflector is in the middle between client and Kubernetes API-server. It provides a framework to monitor the changes of the Kubernetes cluster. ### Definition of Reflector ### Here is the definition of Reflector. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ Reflector is a key component for Kubernetes clients, kube-scheduler and Replication Controller. Reflector is in the middle between client and Kubernetes API-server. ### Definition of Reflector ### Here is the definition of Reflector.  @@ -19,7 +19,7 @@ As shown in the definition, there are two important compoents of a Reflector: It should be noted that the **reflect.Type** is usually a Kind of Kubernetes Object, such as Pod, Node. ### Toy Example Usage of Reflector ### Before going deeper into the implementation of Reflector, let's have a look at how Reflector can be used from a example. This example will watch the changes(including ADD, DELETE, MODIFY) of all the Pods in the Kubernetes cluster. According to the changes, it will add(or update) Pod object into the *Store* if a Pod is created(or updated), and delete a Pod object from the *Store* if the Pod is killed in the Kubernetes. In addition, it will also print all the Pod names every 30 seconds: If a Pod is deleted, then its name won't appear; if a Pod is created, its name will appear. @@ -60,7 +60,7 @@ func main() { From this example, we can see that Reflector uses Kube-client to list and watch all the Pods, and store the changes in the *Store*.  ### Implementation of Reflector ### The implementation of Reflector is in [Kubernetes Go Client](https://github.com/kubernetes/client-go/blob/master/tools/cache/reflector.go) tools/cache/ package. **Reflector.RunUntil()** function will periodly call **Reflector.ListAndWatch()** function. As the name suggests, **Reflector.ListAndWatch()** will first list all the Objects and store them in the *Store*; then it will *watch* the changes and handle the changes with **Reflector.watchHandler()** function.Following is the skech of the **Reflector.ListAndWatch()** and **Reflector.watchHandler()** functions. @@ -78,6 +78,6 @@ Second, the Reflector will call *kubeclient.Watch()*. As this *Watch()* call has As shown in the definition of *Reflector.watchHandler()*, Reflector keeps a connection to the *APIserver*, and receives changes(*Events*) from this connection. It will update the content of the *Store* according to the *Event.Type*. The content of the *Store* will be consumed by other components. ### Usage of Reflector ### **Reflector** provides an efficient framework to monitor the changes of the Kubernetes cluster. Many other tools are build base on **Reflector**, by consuming the content of the *Reflector.Store*. For example, *ReplicationController* will watch the number of living Pods, and create or kill Pod as necessary. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,12 +34,11 @@ func main() { stopCh := make(chan struct{}) store := cache.NewStore(cache.MetaNamespaceKeyFunc) selector := fields.Everything() namespaceAll := "" listWatch := cache.NewListWatchFromClient(client.CoreV1Client.RESTClient(), "pods", namespaceAll, selector) r := cache.NewReflector(listWatch, &v1.Pod{}, store, 0) @@ -76,5 +75,9 @@ Second, the Reflector will call *kubeclient.Watch()*. As this *Watch()* call has **Reflector.watchHandler()**  As shown in the definition of *Reflector.watchHandler()*, Reflector keeps a connection to the *APIserver*, and receives changes(*Events*) from this connection. It will update the content of the *Store* according to the *Event.Type*. The content of the *Store* will be consumed by other components. #### Usage of Reflector #### **Reflector** provides an efficient framework to monitor the changes of the Kubernetes cluster. Many other tools are build base on **Reflector**, by consuming the content of the *Reflector.Store*. For example, *ReplicationController* will watch the number of living Pods, and create or kill Pod as necessary. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,4 +76,5 @@ Second, the Reflector will call *kubeclient.Watch()*. As this *Watch()* call has **Reflector.watchHandler()**  As shown in the definition of *Reflector.watchHandler()*, Reflector keeps a connection to the *APIserver*, and receives changes(Events) from this connection. It will update the content of the *Store* according to the *Event.Type*. Other components may consume the content of the *Store*. For example, *ReplicationController* will watch the number of living Pods, and create or kill Pod as necessary. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,8 @@ It should be noted that the **reflect.Type** is usually a Kind of Kubernetes Obj #### Example Usage of Reflector #### Before going deeper into the implementation of Reflector, let's have a look at how Reflector can be used from a example. This example will watch the changes(including ADD, DELETE, MODIFY) of all the Pods in the Kubernetes cluster. According to the changes, it will add(or update) Pod object into the *Store* if a Pod is created(or updated), and delete a Pod object from the *Store* if the Pod is killed in the Kubernetes. In addition, it will also print all the Pod names every 30 seconds: If a Pod is deleted, then its name won't appear; if a Pod is created, its name will appear. ```go func main() { client := getKubeClient() -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ It should be noted that the **reflect.Type** is usually a Kind of Kubernetes Obj #### Example Usage of Reflector #### Before going deeper into the implementation of Reflector, let's have a look at how Reflector can be used from a example. This example will watch the changes(including ADD, DELETE, MODIFY) of all the Pods in the Kubernetes cluster, and store all the existing Pods into the *Store*, and delete the deleted Pods from the *Store*. In addition, it will also print all the Pod names every 30 seconds: If a Pod is deleted, then its name won't appear; if a Pod is created, its name will appear. ```go func main() { client := getKubeClient() -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ ## Kubernetes Reflector ## Reflector is a key component for Kubernetes clients, kube-scheduler and Replication Controller. Reflector is in the middle between client and Kubernetes API-server. #### Definition of Reflector #### @@ -21,7 +21,7 @@ It should be noted that the **reflect.Type** is usually a Kind of Kubernetes Obj #### Example Usage of Reflector #### Before going deeper into the implementation of Reflector, let's have a look at how Reflector can be used from a example. This example will watch the changes(including ADD, DELETE, MODIFY) of all the Pods in the Kubernetes cluster, and store all the existing Pods into the *Store*. In addition, it will also print all the Pod names every 30 seconds: If a Pod is deleted, then its name won't appear; if a Pod is created, its name will appear. ```go func main() { client := getKubeClient() @@ -69,7 +69,6 @@ As the name suggests, **Reflector.ListAndWatch()** will first list all the Objec  As shown in the definition of *Reflctor.ListAndWatch()*, Reflector first call *kubeclient.List()* to get all the Objects (in the previous example, they are Pods), and add all these Objects into the *Store* by **Reflector.syncWith()**. Second, the Reflector will call *kubeclient.Watch()*. As this *Watch()* call has timeout, it will call *kubeclient.Watch()* repeatedly. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,7 +68,10 @@ As the name suggests, **Reflector.ListAndWatch()** will first list all the Objec **Reflctor.ListAndWatch()**  As shown in the definition of *Reflctor.ListAndWatch()*, Reflector first call *kubeclient.List()* to get all the Objects (in the previous example, they are Pods), and add all these Objects into the *Store* by **Reflector.syncWith()**. Second, the Reflector will call *kubeclient.Watch()*. As this *Watch()* call has timeout, it will call *kubeclient.Watch()* repeatedly. **Reflector.watchHandler()**  -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,6 +68,8 @@ As the name suggests, **Reflector.ListAndWatch()** will first list all the Objec **Reflctor.ListAndWatch()**  As shown in the definition of *Reflctor.ListAndWatch()*, Reflector first call *kubeclient.List()* to get all the Objects (in the previous example, they are Pods), and add all these Objects into the *Store* by **Reflector.syncWith()**. Then Reflector will call *kubeclient.Watch()*. As this *Watch()* call has timeout, it will call *kubeclient.Watch()* repeatedly. **Reflector.watchHandler()**  -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -69,6 +69,6 @@ As the name suggests, **Reflector.ListAndWatch()** will first list all the Objec  **Reflector.watchHandler()**  -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -65,5 +65,10 @@ The implementation of Reflector is in [Kubernetes Go Client](https://github.com/ As the name suggests, **Reflector.ListAndWatch()** will first list all the Objects and store them in the *Store*; then it will *watch* the changes and handle the changes with **Reflector.watchHandler()** function.Following is the skech of the **Reflector.ListAndWatch()** and **Reflector.watchHandler()** functions. **Reflctor.ListAndWatch()**  **Reflector.watchHandler()**  -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,8 +61,9 @@ From this example, we can see that Reflector uses Kube-client to list and watch  #### Implementation of Reflector #### The implementation of Reflector is in [Kubernetes Go Client](https://github.com/kubernetes/client-go/blob/master/tools/cache/reflector.go) tools/cache/ package. **Reflector.RunUntil()** function will periodly call **Reflector.ListAndWatch()** function. As the name suggests, **Reflector.ListAndWatch()** will first list all the Objects and store them in the *Store*; then it will *watch* the changes and handle the changes with **Reflector.watchHandler()** function.Following is the skech of the **Reflector.ListAndWatch()** and **Reflector.watchHandler()** functions. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,8 +58,11 @@ func main() { ``` From this example, we can see that Reflector uses Kube-client to list and watch all the Pods, and store the changes in the *Store*.  #### Implementation of Reflector #### The implementation of Reflector is in [Kubernetes Go Client](https://github.com/kubernetes/client-go/blob/master/tools/cache/reflector.go) tools/cache/ package. **Reflector.RunUntil()** function will periodly call **Reflector.ListAndWatch()** function. As the name suggests, **Reflector.ListAndWatch()** will first list all the Objects and store them in the *Store*; then it will *watch* the changes and handle the changes with **Reflector.watchHandler()** function. Following is the skech of the **Reflector.ListAndWatch()** and **Reflector.watchHandler()** functions. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,7 +58,7 @@ func main() { ``` From this example, we can see that Reflector uses Kube-client to list and watch all the Pods, and store the changes in the *Store*. {:height="50%" width="50%"} #### Implementation of Reflector #### The implementation of Reflector is in [Kubernetes Go Client](https://github.com/kubernetes/client-go/blob/master/tools/cache/reflector.go) tools/cache/ package. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,7 +58,7 @@ func main() { ``` From this example, we can see that Reflector uses Kube-client to list and watch all the Pods, and store the changes in the *Store*.  #### Implementation of Reflector #### The implementation of Reflector is in [Kubernetes Go Client](https://github.com/kubernetes/client-go/blob/master/tools/cache/reflector.go) tools/cache/ package. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,7 +58,7 @@ func main() { ``` From this example, we can see that Reflector uses Kube-client to list and watch all the Pods, and store the changes in the *Store*.  #### Implementation of Reflector #### The implementation of Reflector is in [Kubernetes Go Client](https://github.com/kubernetes/client-go/blob/master/tools/cache/reflector.go) tools/cache/ package. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -60,4 +60,6 @@ func main() { From this example, we can see that Reflector uses Kube-client to list and watch all the Pods, and store the changes in the *Store*.  #### Implementation of Reflector #### The implementation of Reflector is in [Kubernetes Go Client](https://github.com/kubernetes/client-go/blob/master/tools/cache/reflector.go) tools/cache/ package. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,6 +58,6 @@ func main() { ``` From this example, we can see that Reflector uses Kube-client to list and watch all the Pods, and store the changes in the *Store*.  -
songbinliu revised this gist
Jun 2, 2017 . No changes.There are no files selected for viewing
-
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,5 +58,6 @@ func main() { ``` From this example, we can see that Reflector uses Kube-client to list and watch all the Pods, and store the changes in the *Store*.  -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,12 +16,12 @@ As shown in the definition, there are two important compoents of a Reflector: It is usually a in-memory storage, such as HashMap, or Queue(for FIFO). Reflector will add the Events into this Store. It should be noted that the **reflect.Type** is usually a Kind of Kubernetes Object, such as Pod, Node. #### Example Usage of Reflector #### Before going deeper into the implementation of Reflector, let's have a look at how Reflector can be used from a example. This example will watch the changes(including ADD, DELETE, MODIFY) of all the Pods in the Kubernetes cluster, and print out the changes. In addition, it will also print all the Pod names every 30 seconds. ```go func main() { client := getKubeClient() @@ -57,3 +57,6 @@ func main() { ``` From this example, we can see that Reflector uses Kube-client to list and watch all the Pods, and store the changes in the *Store*. -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 0 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,28 +56,4 @@ func main() { } ``` -
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 23 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,5 +56,28 @@ func main() { } ``` .gist-highlight { border-left: 3ex solid #eee; position: relative; } .gist-highlight pre { counter-reset: linenumbers; } .gist-highlight pre div:before { color: #aaa; content: counter(linenumbers); counter-increment: linenumbers; left: -3ex; position: absolute; text-align: right; width: 2.5ex; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } -
songbinliu revised this gist
Jun 2, 2017 . No changes.There are no files selected for viewing
-
songbinliu revised this gist
Jun 2, 2017 . No changes.There are no files selected for viewing
-
songbinliu revised this gist
Jun 2, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,7 +41,6 @@ func main() { namespace, selector) r := cache.NewReflector(listWatch, &v1.Pod{}, store, 0) r.RunUntil(stopCh) -
songbinliu revised this gist
Jun 2, 2017 . No changes.There are no files selected for viewing
-
songbinliu revised this gist
Jun 2, 2017 . No changes.There are no files selected for viewing
NewerOlder