You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>There are several other packages in client-go including discovery, d<em>ynamic, and scale</em>. While we are not going to cover these packages, it is important to be aware of their capabilities.</p>
337
337
</blockquote>
338
-
<h2id="A-simple-client-tool-for-Kubernetes"><ahref="#A-simple-client-tool-for-Kubernetes" class="headerlink" title="A simple client tool for Kubernetes"></a>A simple client tool for Kubernetes</h2><p>Again, let us do a quick review of the tool we are going to build to illustrate the usage of the Go client framework. <strong>pvcwatch</strong>, is a simple CLI tool which watches the total claimed persistent storage capacity in a cluster. When the total reaches a specified threshold, it takes an action (in this example, it’s a simple notification on the screen).</p>
<h2id="Setup"><ahref="#Setup" class="headerlink" title="Setup"></a>Setup</h2><p>The client-go project supports both <em>Godep</em> and <em>dep</em> for vendoring management. I use <em>dep</em> for ease of use and continued adoption (yes, yes, I know <em>vgo</em>… I know). For instance, the following is the minimum <em>Gopkg.toml</em>config required to setup your code with dependency on client-go <em>version 6.0</em>and <em>version 1.9</em> of the Kubernetes API:</p>
<p>In the snippet above, we use <code>ListOptions</code> to specify label and field selectors (as well as namespace) to narrow down the PVC resources returned as type <code>v1.PeristentVolumeClaimList</code>. The next snippet shows how we can walk and print the list of PVCs that was retrieved from the server.</p>
@@ -503,10 +500,8 @@ <h3 id="Loop-through-events"><a href="#Loop-through-events" class="headerlink" t
503
500
}
504
501
505
502
</code></pre>
506
-
<p>The <code>watcher</code>’s channel, in the <em>for-range</em> loop above, is used to process incoming event notifications from the server. Each event is assigned to variable <code>event</code> where <code>event.Object</code> value is asserted to be of type <code>PersistentVolumeClaim</code> so we can extract needed info.</p>
<h3id="Processing-ADDED-events"><ahref="#Processing-ADDED-events" class="headerlink" title="Processing ADDED events"></a>Processing ADDED events</h3><p>When a new PVC is added, <code>event.Type</code> is set to value <code>watch.Added</code>. We then use the following code to extract the capacity of the added claim (<code>quant</code>), add it to the running total capacity (<code>totalClaimedQuant</code>). Lastly, we check to see if the total capacity is greater than the established max capacity (<code>maxClaimedQuant</code>). If so, the program can trigger an action.</p>
0 commit comments