main
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<!-- Oct 07, 2022 -->
5<meta charset="utf-8" />
6<meta name="viewport" content="width=device-width, initial-scale=1" />
7<title>Tekton development environment</title>
8<meta name="author" content="Vincent Demeester" />
9<meta name="generator" content="Org Mode" />
10<link rel='icon' type='image/x-icon' href='/images/favicon.ico'/>
11<meta name='viewport' content='width=device-width, initial-scale=1'>
12<link rel='stylesheet' href='/css/new.css' type='text/css'/>
13<link rel='stylesheet' href='/css/syntax.css' type='text/css'/>
14<link href='/index.xml' rel='alternate' type='application/rss+xml' title='Vincent Demeester' />
15</head>
16<body>
17<main id="content" class="content">
18<header>
19<h1 class="title">Tekton development environment</h1>
20</header>
21<section id="outline-container-h:07626b12-f046-4671-87cd-858ebde959b9" class="outline-2">
22<h2 id="h:07626b12-f046-4671-87cd-858ebde959b9">Basic development environment setup</h2>
23<div class="outline-text-2" id="text-h:07626b12-f046-4671-87cd-858ebde959b9">
24</div>
25
26<div id="outline-container-h:29af1f1c-bb22-4f51-96b2-a217279e5b04" class="outline-3">
27<h3 id="h:29af1f1c-bb22-4f51-96b2-a217279e5b04">Requirements</h3>
28<div class="outline-text-3" id="text-h:29af1f1c-bb22-4f51-96b2-a217279e5b04">
29<ul class="org-ul">
30<li><code>go</code> : installation depends on your operating system</li>
31<li><code>ko</code> : <code>go get -u github.com/google/go-containerregistry/cmd/ko</code></li>
32<li><code>kubernetes</code>
33<ul class="org-ul">
34<li><code>minikube</code></li>
35<li><code>minishift</code></li>
36<li>…</li>
37</ul></li>
38</ul>
39</div>
40</div>
41
42<div id="outline-container-h:8a457dfb-5144-4bd2-bc16-4a18d7bb54f6" class="outline-3">
43<h3 id="h:8a457dfb-5144-4bd2-bc16-4a18d7bb54f6"><code>Minikube</code></h3>
44<div class="outline-text-3" id="text-h:8a457dfb-5144-4bd2-bc16-4a18d7bb54f6">
45<div class="org-src-container">
46<pre class="src src-bash">$ minikube profile tektoncd
47$ minikube config set kubernetes-version <span class="org-string">"v1.13.2"</span>
48$ minikube config set memory <span class="org-string">"8192"</span>
49$ minikube config set cpus <span class="org-string">"4"</span>
50<span class="org-comment-delimiter"># </span><span class="org-comment">linux-only with libvirt, qemu-kvm</span>
51$ minikube config set vm-driver <span class="org-string">"kvm2"</span>
52$ minikube start
53✅ minikube profile was successfully set to tektoncd
54⚠️ These changes will take effect upon a minikube delete and then a minikube start
55⚠️ These changes will take effect upon a minikube delete and then a minikube start
56⚠️ These changes will take effect upon a minikube delete and then a minikube start
57😄 minikube v0.35.0 on linux (amd64)
58🔥 Creating kvm2 VM (<span class="org-variable-name">CPUs</span>=4, <span class="org-variable-name">Memory</span>=8192MB, <span class="org-variable-name">Disk</span>=20000MB) ...
59📶 <span class="org-string">"tektoncd"</span> IP address is 192.168.39.241
60🐳 Configuring Docker as the container runtime ...
61✨ Preparing Kubernetes environment ...
62🚜 Pulling images required by Kubernetes v1.13.2 ...
63🚀 Launching Kubernetes v1.13.2 using kubeadm ...
64⌛ Waiting for pods: apiserver proxy etcd scheduler controller addon-manager dns
65🔑 Configuring cluster permissions ...
66🤔 Verifying component health .....
67💗 kubectl is now configured to use <span class="org-string">"tektoncd"</span>
68🏄 Done! Thank you for using minikube!
69</pre>
70</div>
71</div>
72</div>
73
74<div id="outline-container-h:b6e6a6cd-6130-4d8a-828e-41e609f66c19" class="outline-3">
75<h3 id="h:b6e6a6cd-6130-4d8a-828e-41e609f66c19"><code>Minishift</code></h3>
76<div class="outline-text-3" id="text-h:b6e6a6cd-6130-4d8a-828e-41e609f66c19">
77<div class="org-src-container">
78<pre class="src src-bash">$ minishift profile set tektoncd
79$ minishift config set openshift-version <span class="org-string">"v3.11.0"</span>
80$ minishift config set memory <span class="org-string">"8192"</span>
81$ minishift config set cpus <span class="org-string">"4"</span>
82$ minishift config set image-caching <span class="org-string">"true"</span>
83$ minishift addons enable admin-user
84$ minishift addons enable anyuid
85$ minishift start
86-- Starting profile <span class="org-string">'tektoncd'</span>
87-- Check if deprecated options are used ... OK
88-- Checking if https://github.com is reachable ... OK
89-- Checking if requested OpenShift version <span class="org-string">'v3.11.0'</span> is valid ... OK
90-- Checking if requested OpenShift version <span class="org-string">'v3.11.0'</span> is supported ... OK
91-- Checking if requested hypervisor <span class="org-string">'kvm'</span> is supported on this platform ... OK
92-- Checking if KVM driver is installed ...
93<span class="org-comment-delimiter"># </span><span class="org-comment">[…]</span>
94-- Starting the OpenShift cluster using <span class="org-string">'kvm'</span> hypervisor ...
95-- Minishift VM will be configured with ...
96 Memory: 8 GB
97 vCPUs : 4
98 Disk size: 20 GB
99<span class="org-comment-delimiter"># </span><span class="org-comment">[…]</span>
100 -- Starting OpenShift cluster ...........
101
102Creating initial project <span class="org-string">"myproject"</span> ...
103Server Information ...
104OpenShift server started.
105
106The server is accessible via web console at:
107 https://192.168.42.95:8443/console
108
109You are logged<span class="org-keyword"> in</span> as:
110 User: developer
111 Password: <any value>
112
113To login as administrator:
114 oc login -u system:admin
115
116
117-- Applying addon <span class="org-string">'admin-user'</span>:..
118-- Applying addon <span class="org-string">'anyuid'</span>:.
119<span class="org-comment-delimiter"># </span><span class="org-comment">[…]</span>
120</pre>
121</div>
122</div>
123</div>
124
125<div id="outline-container-h:4ca1bd38-6613-4b44-a276-f40680d89310" class="outline-3">
126<h3 id="h:4ca1bd38-6613-4b44-a276-f40680d89310">Environments</h3>
127<div class="outline-text-3" id="text-h:4ca1bd38-6613-4b44-a276-f40680d89310">
128<p>
129We need to configure <code>ko</code> (using <code>KO_DOCKER_REPO</code>) so that it can deploy the working copy
130code into our development cluster.
131</p>
132
133<ul class="org-ul">
134<li><code>minikube</code> (or <code>minishift</code>) with <code>docker</code> as container runtime
135<ol class="org-ol">
136<li><p>
137Make sure your local <code>docker</code> command-line points to the VM daemon
138</p>
139<div class="org-src-container">
140<pre class="src src-bash"><span class="org-builtin">eval</span> $(minikube docker-env)
141<span class="org-comment-delimiter"># </span><span class="org-comment">eval $(minishift docker-env) # for minishift</span>
142</pre>
143</div></li>
144<li><p>
145Use <code>ko.local</code> as <code>KO_DOCKER_REPO</code> — it’s a special case handled by <code>ko</code>
146</p>
147<div class="org-src-container">
148<pre class="src src-bash"><span class="org-builtin">export</span> <span class="org-variable-name">KO_DOCKER_REPO</span>=ko.local
149</pre>
150</div></li>
151</ol></li>
152<li>for any cluster using another runtime (or a remote cluster), you need to use a registry
153that will be accessible from the cluster (<code>gcr.io</code> or your own – the docker hub doesn’t
154work with <code>ko</code>).</li>
155</ul>
156</div>
157</div>
158
159<div id="outline-container-h:f8a6a774-f886-492c-a268-2d896cf0918d" class="outline-3">
160<h3 id="h:f8a6a774-f886-492c-a268-2d896cf0918d">Deploy <code>tektoncd/pipeline</code></h3>
161<div class="outline-text-3" id="text-h:f8a6a774-f886-492c-a268-2d896cf0918d">
162<ol class="org-ol">
163<li><p>
164<code>tektoncd/pipeline</code> needs to sit on the right place in your <code>GOPATH</code>
165</p>
166
167<div class="org-src-container">
168<pre class="src src-bash">$ echo $<span class="org-variable-name">GOPATH</span>
169/home/vincent
170$ pwd
171/home/vincent/src/github.com/tektoncd/pipeline
172</pre>
173</div></li>
174
175<li><p>
176Deploy 💃
177</p>
178
179<div class="org-src-container">
180<pre class="src src-bash">$ ko apply -f ./config
1812019/03/13 10:49:22 Building github.com/tektoncd/pipeline/cmd/webhook
1822019/03/13 10:49:22 Building github.com/tektoncd/pipeline/cmd/gsutil
1832019/03/13 10:49:22 Building github.com/tektoncd/pipeline/cmd/controller
1842019/03/13 10:49:22 Building github.com/tektoncd/pipeline/cmd/nop
1852019/03/13 10:49:22 Building github.com/tektoncd/pipeline/cmd/creds-init
1862019/03/13 10:49:22 Building github.com/tektoncd/pipeline/cmd/git-init
1872019/03/13 10:49:22 Building github.com/tektoncd/pipeline/cmd/kubeconfigwriter
1882019/03/13 10:49:22 Building github.com/tektoncd/pipeline/cmd/bash
1892019/03/13 10:49:22 Building github.com/tektoncd/pipeline/cmd/entrypoint
190namespace/tekton-pipelines created
191clusterrole.rbac.authorization.k8s.io/tekton-pipelines-admin created
192serviceaccount/tekton-pipelines-controller created
193clusterrolebinding.rbac.authorization.k8s.io/tekton-pipelines-controller-admin created
1942019/03/13 10:49:23 Using base index.docker.io/library/busybox:latest for github.com/tektoncd/pipeline/cmd/entrypoint
1952019/03/13 10:49:23 Using base gcr.io/distroless/static:latest for github.com/tektoncd/pipeline/cmd/nop
196<span class="org-comment-delimiter"># </span><span class="org-comment">[…]</span>
197deployment.apps/tekton-pipelines-controller created
198deployment.apps/tekton-pipelines-webhook created
199</pre>
200</div></li>
201
202<li><p>
203Enjoy 🔥
204</p>
205
206<div class="org-src-container">
207<pre class="src src-bash">$ kubectl get all -n tekton-pipelines
208NAME READY STATUS RESTARTS AGE
209pod/tekton-pipelines-controller-5875857cf5-k9njx 1/1 Running 0 3m18s
210pod/tekton-pipelines-webhook-54785c88f4-jbkqr 1/1 Running 0 3m18s
211
212NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
213service/tekton-pipelines-controller ClusterIP 10.104.145.40 <none> 9090/TCP 4m31s
214service/tekton-pipelines-webhook ClusterIP 10.97.9.56 <none> 443/TCP 4m31s
215
216NAME READY UP-TO-DATE AVAILABLE AGE
217deployment.apps/tekton-pipelines-controller 1/1 1 1 3m18s
218deployment.apps/tekton-pipelines-webhook 1/1 1 1 3m18s
219
220NAME DESIRED CURRENT READY AGE
221replicaset.apps/tekton-pipelines-controller-5875857cf5 1 1 1 3m18s
222replicaset.apps/tekton-pipelines-webhook-54785c88f4 1 1 1 3m18s
223</pre>
224</div></li>
225</ol>
226</div>
227</div>
228
229<div id="outline-container-h:99cb715a-3807-414e-9b73-2d60bacbe583" class="outline-3">
230<h3 id="h:99cb715a-3807-414e-9b73-2d60bacbe583">An example</h3>
231<div class="outline-text-3" id="text-h:99cb715a-3807-414e-9b73-2d60bacbe583">
232<p>
233Let’s validate it works by running a simple example
234</p>
235
236<div class="org-src-container">
237<pre class="src src-yaml"><span class="org-variable-name">apiVersion</span>: tekton.dev/v1alpha1
238<span class="org-variable-name">kind</span>: Task
239<span class="org-variable-name">metadata</span>:
240 <span class="org-variable-name">name</span>: build-simple
241<span class="org-variable-name">spec</span>:
242 <span class="org-variable-name">steps</span>:
243 - <span class="org-variable-name">name</span>: build-simple
244 <span class="org-variable-name">image</span>: docker.io/library/busybox
245 <span class="org-variable-name">command</span>:
246 - /bin/sh
247 <span class="org-variable-name">args</span>:
248 - -c
249 - <span class="org-string">"echo hello world"</span>
250<span class="org-comment">---</span>
251<span class="org-variable-name">apiVersion</span>: tekton.dev/v1alpha1
252<span class="org-variable-name">kind</span>: TaskRun
253<span class="org-variable-name">metadata</span>:
254 <span class="org-variable-name">name</span>: build-simple
255<span class="org-variable-name">spec</span>:
256 <span class="org-variable-name">taskRef</span>:
257 <span class="org-variable-name">name</span>: build-simple
258 <span class="org-variable-name">trigger</span>:
259 <span class="org-variable-name">type</span>: manual
260</pre>
261</div>
262
263<div class="org-src-container">
264<pre class="src src-bash">$ kubectl apply -f ./test.yaml
265task.tekton.dev/build-simple created
266taskrun.tekton.dev/build-simple created
267</pre>
268</div>
269
270<p>
271Let’s now look at what’s in our namespace
272</p>
273
274<div class="org-src-container">
275<pre class="src src-bash">$ kubectl get all
276NAME READY STATUS RESTARTS AGE
277pod/build-simple-pod-ada879 0/2 Completed 0 10s
278
279NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
280service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 26m
281
282NAME AGE
283task.tekton.dev/build-simple 10s
284
285NAME AGE
286taskrun.tekton.dev/build-simple 10s
287</pre>
288</div>
289</div>
290</div>
291</section>
292<section id="outline-container-h:89f26869-04b1-402f-af3a-77946dec25b2" class="outline-2">
293<h2 id="h:89f26869-04b1-402f-af3a-77946dec25b2">Development workflow</h2>
294<div class="outline-text-2" id="text-h:89f26869-04b1-402f-af3a-77946dec25b2">
295<p>
296When you’re working on <code>pipeline</code>, usually you want :
297</p>
298
299<ol class="org-ol">
300<li>make sure it compiles : <code>go build -v ./..</code></li>
301<li>Running unit tests : <code>go test ./...</code> (bonus use <a href="https://github.com/vdemeester/ram"><code>ram</code></a> for continuous testing)</li>
302<li><p>
303End-to-end tests : <code>go test -tags e2e ./...</code> (or simply using `./test/` package)
304</p>
305
306<p>
307<b>Make sure you re-deploy before running the e2e tests</b> using <code>ko apply -f ./config</code>,
308otherwise you’re testing the wrong code.
309</p></li>
310</ol>
311</div>
312</section>
313
314<section id="outline-container-h:0964e161-7ddd-40f9-a224-207e68b941fe" class="outline-2">
315<h2 id="h:0964e161-7ddd-40f9-a224-207e68b941fe">Code walkthrough</h2>
316<div class="outline-text-2" id="text-h:0964e161-7ddd-40f9-a224-207e68b941fe">
317<p>
318Let’s look into <code>tektoncd/pipeline</code> sources
319</p>
320
321<ul class="org-ul">
322<li>Go packages
323<ul class="org-ul">
324<li><code>cmd</code></li>
325<li><code>pkg</code>
326<ul class="org-ul">
327<li><code>apis</code> : api types</li>
328<li><code>client</code> : generated client</li>
329<li><code>reconcilier</code> : core of the pipeline controller</li>
330</ul></li>
331</ul></li>
332<li>Tests</li>
333<li>CI related files</li>
334</ul>
335</div>
336</section>
337</main>
338<footer id="postamble" class="status">
339<footer>
340 <small><a href="/" rel="history">Index</a> • <a href="/sitemap.html">Sitemap</a> • <a href="https://dl.sbr.pm/">Files</a></small><br/>
341 <small class='questions'>Questions, comments ? Please use my <a href="https://lists.sr.ht/~vdemeester/public-inbox">public inbox</a> by sending a plain-text email to <a href="mailto:~vdemeester/public-inbox@lists.sr.ht">~vdemeester/public-inbox@lists.sr.ht</a>.</small><br/>
342 <small class='copyright'>
343 Content and design by Vincent Demeester
344 (<a rel='licence' href='http://creativecommons.org/licenses/by-nc-sa/3.0/'>Some rights reserved</a>)
345 </small><br />
346</footer>
347</footer>
348</body>
349</html>