<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Liviu Costea on Medium]]></title>
        <description><![CDATA[Stories by Liviu Costea on Medium]]></description>
        <link>https://medium.com/@clm160?source=rss-760814c24284------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*NcC8uXxjd6fM7Oky.jpg</url>
            <title>Stories by Liviu Costea on Medium</title>
            <link>https://medium.com/@clm160?source=rss-760814c24284------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 07:38:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@clm160/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Enabling docker builds with BuildKit]]></title>
            <link>https://itnext.io/enabling-docker-builds-with-buildkit-a931c6f9aa91?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/a931c6f9aa91</guid>
            <category><![CDATA[multi-stage-builds]]></category>
            <category><![CDATA[docker-build]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Wed, 04 Nov 2020 18:28:09 GMT</pubDate>
            <atom:updated>2020-11-04T18:28:09.847Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introducing Docker BuildKit</h4><p>I am working as a SRE and a lot of the work that I do is around docker containers. And a lot of the work around docker containers is on building them. Some Dockerfiles are really simple, like when just adding a Go binary to an alpine/scratch image, while some are more complicated especially when using multistage builds. In the later cases usually you also build your binaries with docker, besides creating the images. And sometimes in cases like these running those docker build commands might take more than a few minutes (for example <a href="https://github.com/argoproj/argo-cd/blob/master/Dockerfile">Argo-CD</a> takes around 12–15 min, though not just one image is created).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*ReyHydAQoMTVnUT252KUwQ.png" /></figure><p>Starting with Docker 18.09 there is a new way of building images called <a href="https://docs.docker.com/develop/develop-images/build_enhancements/">BuildKit</a>. This is considered the V2 of docker build and it currently isn&#39;t the default way even for Docker 19.03, you need to enable it. The easiest way to make it active is to set an environment variable: <em>DOCKER_BUILKIT=1</em>. This V2 adds many interesting features and some of them are out of box. Also the resulting docker image are similar to the ones created with normal build, so there shouldn’t be any problems running that image or pushing it to a registry.</p><h4>BuildKit performance improvements</h4><p>In the normal docker build each layer is built sequentially, you need to wait for layer n to build n+1. This limitation wasn&#39;t very visible initially, but with the introduction of multi-stage builds it became a bigger issue because you can start more steps in parallel until to the point they depend on each other. So valuable time can be gained here by introducing some parallelism.</p><p>In order to find which steps can be built in parallel and which ones need to wait for each other BuildKit will build a graph of the dependencies and use it to increase the build efficiency. The output of a docker build command will be completely different to what you were used until now, with some steps running in parallel, similar to the below (where you can see #4 running in parallel with #10):</p><pre>#2 [internal] load build definition from Dockerfile<br>#2 transferring dockerfile: 1.15kB done<br>#2 DONE 0.0s<br><br>#1 [internal] load .dockerignore<br>#1 transferring context: 2B done<br>#1 DONE 0.0s<br><br>#3 [internal] load metadata for docker.io/library/openjdk:8<br>#3 DONE 1.7s<br><br>#4 [1/8] FROM docker.io/library/openjdk:8@sha256:291ef47999c4ee7160cc1208ff...<br>#4 resolve docker.io/library/openjdk:8@sha256:291ef47999c4ee7160cc1208ff49244bf93a43b7eca1c31842615fc529efc24e done<br>#4 ...<br><br>#10 [internal] load build context<br>#10 transferring context: 10.60kB done<br>#10 DONE 0.0s<br><br>#4 [1/8] FROM docker.io/library/openjdk:8@sha256:291ef47999c4ee7160cc1208ff...</pre><p>Performance is not the only improvement that BuildKit delivers, but we can have it out of the box without any changes to the Dockerfile. And this is what I would like to check next, how to enable BuildKit on multi-stage docker builds and if it is really a noticeable improvement.</p><h4>Building ArgoCD with BuildKit</h4><p>So let&#39;s see if we can really benefit of BuildKit by introducing it to a real project and comparing it with the normal build. And a good candidate is <a href="https://github.com/argoproj/argo-cd">ArgoCD</a>, because of the complex Dockerfile it has and the amount of time it takes for the images to be built (they build more than one from just a single Dockerfile by using multiple targets). My plan would be to clone it locally, push it to my account (not a fork because I don&#39;t plan to create a PR), disable the existing GitHub workflows, add 2 simple new workflows that only build the images the standard way and the BuildKit way and then compare the results of running it for lets say 5 times.</p><p>So first I created an empty new project on github called argocd-buidkit. Then I took the original argo-cd project, cloned it locally, removed the remote, added this argocd-buldkit as a new remote and pushed to it. And at the end I ended up with <a href="https://github.com/lcostea/argocd-buildkit">argocd-buildkit repo</a>.</p><p>Then I created 2 new GitHub Actions, one to build the images the normal way and one with an additional env variable that would enable BuildKit. Here is the second one with the additional variable, the only difference from the first being the addition of the last 2 lines (28 &amp; 29).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a4fb9fa6315b659d5fa5ebcfc3344b6/href">https://medium.com/media/1a4fb9fa6315b659d5fa5ebcfc3344b6/href</a></iframe><p>You can check out the runs I performed in the <a href="https://github.com/lcostea/argocd-buildkit/actions">actions section of the argocd-buildkit project</a>.</p><p>1st run:</p><ul><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/340202242">Docker-Image-Standard</a>: 13m 27s</li><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/340202240">Docker-Image-BuildKit</a>: 12m 13s</li></ul><p>2nd run:</p><ul><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/340424391">Docker-Image-Standard</a>: 14m 11s</li><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/340424392">Docker-Image-BuildKit</a>: 10m 56s</li></ul><p>3rd run:</p><ul><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/340568618">Docker-Image-Standard</a>: 12m 43s</li><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/340568617">Docker-Image-BuildKit</a>: 11m 19s</li></ul><p>4th run:</p><ul><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/340591871">Docker-Image-Standard</a>: 13m 49s</li><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/340591887">Docker-Image-BuildKit</a>: 12m 29s</li></ul><p>5th run:</p><ul><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/341238041">Docker-Image-Standard</a>: 12m 59s</li><li><a href="https://github.com/lcostea/argocd-buildkit/actions/runs/341238096">Docker-Image-BuildKit</a>: 12m 59s</li></ul><p>There clearly are some differences, with the BuildKit version taking up to 3.5 minutes less compared to the standard run, but also one time taking exactly the same. And it is important to specify that this is not an experimental feature of docker build, because experimental features are not recommended to use in production. This instead is an opt-in one.</p><p>But are there any known projects that actually use BuildKit to create their docker images? In the CNCF space I found <a href="https://github.com/dexidp/dex">dex</a>, an identity service that uses <a href="https://openid.net/connect/">OpenID Connect</a> to drive authentication for other apps. And dex is used internally by ArgoCD. If you head over to its workflows, in the docker section you will see that it uses <a href="https://docs.docker.com/buildx/working-with-buildx/">buildx</a> (which is actually an experimental feature, but it will probably stop being experimental in <a href="https://github.com/moby/moby/milestone/76">20.10</a> version), which underneath is using BuildKit to create the docker images.</p><p>So there should not be problems using BuildKit, which besides performance comes with <a href="https://docs.docker.com/develop/develop-images/build_enhancements/">many other features</a>. But if you still have doubts you can try first with your internal images, like the ones used in CI/CD or your internal tools and after you build more confidence you can go for your production ones.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a931c6f9aa91" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/enabling-docker-builds-with-buildkit-a931c6f9aa91">Enabling docker builds with BuildKit</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ArgoCD: Setup external clusters by name]]></title>
            <link>https://itnext.io/argocd-setup-external-clusters-by-name-d3d58a53acb0?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3d58a53acb0</guid>
            <category><![CDATA[argo]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[gitops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Sat, 24 Oct 2020 10:25:10 GMT</pubDate>
            <atom:updated>2020-10-24T10:25:10.037Z</atom:updated>
            <content:encoded><![CDATA[<p>ArgoCD is probably the most advanced GitOps tool we can use at this moment. It was featured in the Trial quadrant of the <a href="https://www.thoughtworks.com/radar/platforms/argo-cd">Thoughtworks Radar, May 2020 edition</a> and it is also part of the <a href="https://radar.cncf.io/2020-06-continuous-delivery">CNCF Continuous Delivery Radar from June 2020</a> on Asses. The project was admitted into <a href="https://www.cncf.io/blog/2020/04/07/toc-welcomes-argo-into-the-cncf-incubator/">CNCF in April 2020</a> and since then it attracted more and more users and contributors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RgMWYxzOW5dJaslhW3wJ4Q.png" /></figure><p>The latest version of ArgoCD, when I am writing this, is <a href="https://github.com/argoproj/argo-cd/releases/tag/v1.7.0">1.7.0</a>, released on 25 August 2020. It has many new features and 2 of them seem to be more interesting: ability to use only signed commits for applying state changes and allowing usage of cluster names for application destination (in previous version you could have only used cluster url). Next I would like to go through some examples on how to use the cluster name instead of url. This allows a better user experience because cluster urls are sometimes generated, when using managed services like EKS or AKS, so it is much harder to know if that is really the dev cluster you are applying your application on or maybe some production one. While this feature seems to be really easy to use, just pass the cluster name instead of url, it has some gotchas you need to pay attention to.</p><p>All the files needed for the commands below can be found in this repo: <a href="https://github.com/lcostea/argocd-cluster-name-article">https://github.com/lcostea/argocd-cluster-name-article</a>. So please clone it and then cd into it:</p><pre>git clone <a href="https://github.com/lcostea/argocd-cluster-name-article.git">https://github.com/lcostea/argocd-cluster-name-article.git</a><br>cd <a href="https://github.com/lcostea/argocd-cluster-name-article.git">argocd-cluster-name-article</a></pre><h4>Install ArgoCD 1.7.8</h4><p>First, lets install ArgoCD 1.7.8, which is now the latest patch. I have kind installed locally, so I am going to spin a new cluster. If you don’t have kind, <a href="https://kind.sigs.k8s.io/docs/user/quick-start/#installation">here are instructions for installing it</a>.</p><pre>kind create cluster --name argocd1.7</pre><p>After the cluster is up and running and your context is pointing at it, we will install ArgoCD, first create the &quot;argocd&quot; namespace and then we will apply the 1.7.8 manifests (please stick to this argocd namespace, other name will create problems when using manifests directly and not kustomize):</p><pre>kubectl create namespace argocd</pre><pre>kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v1.7.8/manifests/install.yaml</pre><p>Next lets check that all the pods are up and running and once they are we can try to connect to the ArgoCD UI</p><pre>#wait for all pods to be running<br>kubectl get pod -n argocd<br>kubectl port-forward svc/argocd-server -n argocd 8083:80</pre><p>Open the browser on localhost:8083 and if there are any alerts on the certificate it should be ok because it is a self generated one. On the username put &quot;admin&quot;, while the password you can get by running this command (it is the name of the server pod):</p><pre>kubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d’/’ -f 2</pre><h4>First app with cluster name</h4><p>On the UI you should see a message like &quot;No applications yet&quot;. So lets create one and we will use the cluster name and not the url. We can use the name even when we deploy apps on the local cluster. The app will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3743c1caa2ae80305a67c6eb2904744a/href">https://medium.com/media/3743c1caa2ae80305a67c6eb2904744a/href</a></iframe><pre>kubectl create namespace guestbook</pre><pre># the file is located in the repo you cloned when we started<br>kubectl apply -n argocd -f local-server-guestbook-app.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*jNQg3CviNXr6Dcs2ShOEhQ.png" /><figcaption>local-server-guestbook-app as seen in ArgoCD UI</figcaption></figure><p>So you can see how you can use name for the local cluster:</p><pre>name: in-cluster</pre><p>This should be a little easier to remember than</p><pre>server: <a href="https://kubernetes.default.svc/">https://kubernetes.default.svc</a></pre><p>Now you can see the app in the ArgoCD UI with status OutOfSync. You can wait for ArgoCD to sync it automatically, or if you don’t want to wait use the sync button on the app. After the sync you can see all the components in the UI, like deployment, service, replicaset, pod.</p><h4>Connect to ArgoCD with the cli</h4><p>Before we go to create the second cluster we will use the cli to connect to our 1.7.8 instance. First let&#39;s download the argocd cli, you can find <a href="https://argoproj.github.io/argo-cd/cli_installation/">instructions on this page for all operating systems</a>. After we have the cli available we will connect with it to our argocd 1.7.8 installation (we assume that the port-forward is still working). You will use to set the same password as the one used in the UI:</p><pre>argocd login localhost:8083 --username admin --password &lt;same_password_used_in_ui&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VYWGN3YVLcBZSTE_1B4Y9g.png" /></figure><p>You might get an error about the server certificate, in this case it would be ok to proceed (by typing &quot;<em>y&quot;</em>) as ArgoCD generated its own certificate. We can test that we are connected by listing the apps installed on our instance:</p><pre>argocd app list</pre><p>We should see the <em>local-server-guestbook-app</em> entry.</p><h4>Adding an external cluster to ArgoCD</h4><p>Next we will need a new cluster where ArgoCD can install applications, so lets create a new one with kind. But before we do that we need to create a configuration file for this second cluster, so ArgoCD (installed in the first cluster) can connect to its control plane.</p><p>The file with the kind configuration will look like this and you can find it in the repo being called <em>kind-dev-cluster-config.yaml</em>. You need to update the value in apiServerAddress to match your private ip. To find out your IP you can use either <em>ipconfig</em> on Windows or <em>ifconfig</em> on Linux/MacOS.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2566e7b0881c7fd693fa7c8e0cb8a98e/href">https://medium.com/media/2566e7b0881c7fd693fa7c8e0cb8a98e/href</a></iframe><p>After you have updated the file, we can create the second cluster and we will also add a guestbook namespace in it.</p><pre>kind create cluster --name dev-cluster --config kind-dev-cluster-config.yaml</pre><p>After the creation of cluster is complete then you can add it to argocd. If the IP you set in its config file above is not correct this step will not succeeded. Notice we updated the name of the cluster on argocd from <em>kind-dev-cluster</em> to <em>dev-cluster</em>. So the context name remained <em>kind-dev-cluster</em>, while the cluster on ArgoCD can be addressed using <em>dev-cluster.</em> And if everything is ok, we can query the list of clusters from argocd where we can see the newly one added.</p><pre>argocd cluster add kind-dev-cluster --name dev-cluster<br>argocd cluster list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*zraNxKq3HBxGZ7BiOgPKvw.png" /><figcaption>Adding a new cluster to ArgoCD</figcaption></figure><p>Next we are going to apply the same application we installed on the local cluster to the external one. But before we can do that we need to change the context back to the argocd cluster, by running:</p><pre>kubectl config use-context kind-argocd1.7</pre><h4>Add an app to the external cluster</h4><p>Before we can apply our application this time we will use an <a href="https://argoproj.github.io/argo-cd/operator-manual/declarative-setup/#projects">AppProject</a>. This is a custom resource that allows us to set some constraints on a group of applications. In our case we will allow the apps that use this AppProject to deploy manifests only in our <em>dev-cluster</em> in the <em>guestbook</em> namespace, this is the part specified in <em>destinations</em>. But most important to mention here is that cluster name is not supported in appproject files, here we will still use the cluster url. And the reason is that the name can be easily updated, while the url should be unique (or at least very close to it). So when we apply such an appproject we want to clearly identify the destination cluster with the constraints.</p><p>Of course you don’t need to use a specific appproj, you can always rely on the default one (like we used in the local app). Still for production installations they are recommended, being one more layer of precautions that you don’t mess with other clusters or namespaces.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95e3082e691bd65221b7c46a875ffe04/href">https://medium.com/media/95e3082e691bd65221b7c46a875ffe04/href</a></iframe><p>The file with the appproject is <em>remote-server-guestbook-proj.yaml</em>, while the application can be found in <em>remote-server-guestbook-app.yaml</em> so we can go on and apply them both:</p><pre>kubectl apply -n argocd -f remote-server-guestbook-proj.yaml<br>kubectl apply -n argocd -f remote-server-guestbook-app.yaml</pre><p>And if you give it a few minutes this app will sync itself and the UI should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ktTI9nO_L05D5-GIj9sew.png" /><figcaption>ArgoCD with local and remote apps</figcaption></figure><p>That’s about it, now you have an external cluster added in ArgoCD and an app applied with its name. So you can play around adding more applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3d58a53acb0" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/argocd-setup-external-clusters-by-name-d3d58a53acb0">ArgoCD: Setup external clusters by name</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tag example with go-git library]]></title>
            <link>https://medium.com/hackernoon/tag-example-with-go-git-library-4377a84bbf17?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/4377a84bbf17</guid>
            <category><![CDATA[go-git]]></category>
            <category><![CDATA[releases]]></category>
            <category><![CDATA[systems-engineering]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Sun, 31 May 2020 06:36:26 GMT</pubDate>
            <atom:updated>2020-06-01T14:44:25.628Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BKLHuyJDlOh1Rf7MrJu1mw.png" /><figcaption>go-git tag repo example</figcaption></figure><p>One of the library I use pretty much as a systems engineer is <a href="https://github.com/go-git/go-git">go-git</a>. It allows one to interact with git directly from go, without being a C or shell wrapper. But it had quite a steep learning curve for such a simple library, it took me many hours of looking at examples, browsing through the open and closed GitHub issues to find how to do quite simple things. And the longer it takes to do it, the bigger the pressure to start again on the bash road, <a href="https://twitter.com/thockin/status/1263621195288637440">even if you know it is going to turn out bad</a>:</p><h3>Tim Hockin on Twitter</h3><p>Programming in bash is like rubbing a cat&#39;s tummy. You know it&#39;s going to end with bloodshed, but you also know you&#39;re going to do it again.</p><p>In our flows, after we validate a new binary for our application and mark it as ready for production deployment, we tag all our repos, including e2e test ones with the version that we will release. And to do that we have a cli written in go with one of the commands doing the tagging. Sounds simple, but there is a little bit of logic in it: it clones a repo, checks out a specific branch, checks if a tag exists and if not creates it from branch head and then pushes it back to the remote. In our real world scenario things are a little more complicated (they always are) as we do have to calculate the tag and the checkout branch, based on some parameters.</p><p>TLDR: If you don&#39;t want to go through the explanations and jump straight to the working code, you can find it on <a href="https://github.com/lcostea/go-git-tag-example">github.com/lcostea/go-git-tag-example</a>. Otherwise let me walk you through the exercise.</p><p>First lets create a folder and do a go mod init so we can start our new go app (instead of lcostea.io you can use your own domain, or anything else like example.com)</p><pre>mkdir go-git-tag</pre><pre>cd go-git-tag</pre><pre>go mod init lcostea.io/go-git-tag</pre><p>This will create a go.mod file in your folder. Next we will create the main.go where all our code will be written. Inside the file we will need these imports:</p><pre>package main</pre><pre>import (</pre><pre>  &quot;fmt&quot;</pre><pre>  &quot;io/ioutil&quot;</pre><pre>  &quot;os&quot;</pre><pre>  &quot;time&quot;</pre><pre>  &quot;github.com/go-git/go-git/v5&quot;</pre><pre>  &quot;github.com/go-git/go-git/v5/config&quot;</pre><pre>  &quot;github.com/go-git/go-git/v5/plumbing/object&quot;</pre><pre>  &quot;github.com/go-git/go-git/v5/plumbing/transport/ssh&quot;</pre><pre>  log &quot;github.com/sirupsen/logrus&quot;</pre><pre>)</pre><p>We will then create the clone function, using the go-git library. There are 2 ways to clone: using https and using ssh. We will explore the second option, which is the most used one right now. It is easy to setup an <a href="https://www.ssh.com/ssh/identity-key">Identity file</a> for each git service (like github.com, gitlab.com, bitbucket.com etc), place it in ~/.ssh/config and stop worrying about credentials.</p><p>Unfortunately go-git library <a href="https://github.com/src-d/go-git/issues/1220">doesn’t use your configured identity files</a>, so we would need to specify them in code, so see below how I used my GitHub public key.</p><pre>func publicKey() (*ssh.PublicKeys, error) {</pre><pre>  var publicKey *ssh.PublicKeys</pre><pre>  sshPath := os.Getenv(&quot;HOME&quot;) + &quot;/.ssh/github_rsa&quot;</pre><pre>  sshKey, _ := ioutil.ReadFile(sshPath)</pre><pre>  publicKey, err := ssh.NewPublicKeys(&quot;git&quot;, []byte(sshKey), &quot;&quot;)</pre><pre>  if err != nil {</pre><pre>    return nil, err</pre><pre>  }</pre><pre>  return publicKey, err</pre><pre>}</pre><p>Next we will implement the actual cloning part:</p><pre>func cloneRepo(url, dir string) (*git.Repository, error) {</pre><pre>  log.Infof(&quot;cloning %s into %s&quot;, url, dir)</pre><pre>  auth, keyErr := publicKey()</pre><pre>  if keyErr != nil {</pre><pre>    return nil, keyErr</pre><pre>  }</pre><pre>  r, err := git.PlainClone(dir, false, &amp;git.CloneOptions{</pre><pre>    Progress: os.Stdout,</pre><pre>    URL:      url,</pre><pre>    Auth:     auth,</pre><pre>  })</pre><pre>  if err != nil {</pre><pre>    if err == git.ErrRepositoryAlreadyExists {</pre><pre>      log.Info(&quot;repo was already cloned&quot;)</pre><pre>      return git.PlainOpen(dir)</pre><pre>    } else {</pre><pre>      log.Errorf(&quot;clone git repo error: %s&quot;, err)</pre><pre>      return nil, err</pre><pre>    }</pre><pre>  }</pre><pre>  return r, nil</pre><pre>}</pre><p>The library exposes some common errors you might encounter when doing operations with git, you can find a comprehensive list in <a href="https://github.com/go-git/go-git/blob/master/repository.go">repository.go</a>. So if you run the code more than once, you might have already downloaded the repo, so we can try to recover from a &quot;repository already exists&quot; error. Just note that there might be something totally different in that folder and you would still get the error.</p><p>Moving on, we would like to set the actual tag, but before doing that we need to see if it actually exists, maybe somebody else added it before we did. If the tag exists we will not do anything, our job is done.</p><pre>func tagExists(tag string, r *git.Repository) bool {</pre><pre>  tagFoundErr := &quot;tag was found&quot;</pre><pre>  tags, err := r.TagObjects()</pre><pre>  if err != nil {</pre><pre>    log.Errorf(&quot;get tags error: %s&quot;, err)</pre><pre>    return false</pre><pre>  }</pre><pre>  res := false</pre><pre>  err = tags.ForEach(func(t *object.Tag) error {</pre><pre>    if t.Name == tag {</pre><pre>      res = true</pre><pre>      return fmt.Errorf(tagFoundErr)</pre><pre>    }</pre><pre>    return nil</pre><pre>  })</pre><pre>  if err != nil &amp;&amp; err.Error() != tagFoundErr {</pre><pre>    log.Errorf(&quot;iterate tags error: %s&quot;, err)</pre><pre>    return false</pre><pre>  }</pre><pre>  return res</pre><pre>}</pre><p>The interesting part here is how to go through the list of tags and return an indicator when we actually find it. Normally I would expect such an indicator to be a <a href="https://yourbasic.org/golang/iterator-generator-pattern/">bool value</a>, but I guess in this case also the error is working, as it probably can give an error when accessing these tags. So I created a specific error message tagFoundErr := &quot;tag was found&quot; and used it to step out of the iterator.</p><p>Now, if it doesn&#39;t exists, we are going to create the tag. Nothing too complicated here, we take the HEAD of the branch and create an annotated tag for it.</p><pre>func setTag(r *git.Repository, tag string, tagger *object.Signature) (bool, error) {</pre><pre>  if tagExists(tag, r) {</pre><pre>    log.Infof(&quot;tag %s already exists&quot;, tag)</pre><pre>    return false, nil</pre><pre>  }</pre><pre>  log.Infof(&quot;Set tag %s&quot;, tag)</pre><pre>  h, err := r.Head()</pre><pre>  if err != nil {</pre><pre>    log.Errorf(&quot;get HEAD error: %s&quot;, err)</pre><pre>    return false, err</pre><pre>  }</pre><pre>  _, err = r.CreateTag(tag, h.Hash(), &amp;git.CreateTagOptions{</pre><pre>    Tagger:  tagger,</pre><pre>    Message: tag,</pre><pre>  })</pre><pre>  if err != nil {</pre><pre>    log.Errorf(&quot;create tag error: %s&quot;, err)</pre><pre>    return false, err</pre><pre>  }</pre><pre>  return true, nil</pre><pre>}<br></pre><p>Next, moving on to the pushing of the tag.</p><pre>func pushTags(r *git.Repository) error {</pre><pre>  auth, _ := publicKey()</pre><pre>  po := &amp;git.PushOptions{</pre><pre>    RemoteName: &quot;origin&quot;,</pre><pre>    Progress:   os.Stdout,</pre><pre>    RefSpecs:    []config.RefSpec{config.RefSpec(&quot;refs/tags/*:refs/tags/*&quot;)},</pre><pre>    Auth:       auth,</pre><pre>  }</pre><pre>  err := r.Push(po)</pre><pre>  if err != nil {</pre><pre>    if err == git.NoErrAlreadyUpToDate {</pre><pre>      log.Info(&quot;origin remote was up to date, no push done&quot;)</pre><pre>      return nil</pre><pre>    }</pre><pre>    log.Errorf(&quot;push to remote origin error: %s&quot;, err)</pre><pre>    return err</pre><pre>  }</pre><pre>  return nil</pre><pre>}</pre><p>The important part here is the tag refspec: refs/tags/*:refs/tags/*. All tags live in the refs/tags, no matter if you create it locally or comes from remote, if it is annotated or light. So we need to include this and it should be the equivalent of git push --tag. Also this makes sure that all tags you created locally will be pushed to remote.</p><p>Finally below are the last 2 functions used: main and the defaultSignature function useful when setting the tag.</p><pre>func defaultSignature(name, email string) *object.Signature {</pre><pre>  return &amp;object.Signature{</pre><pre>    Name:  name,</pre><pre>    Email: email,</pre><pre>    When:  time.Now(),</pre><pre>  }</pre><pre>}</pre><pre>func main() {</pre><pre>//you will probably want to modify these variables, if you are going to use this example</pre><pre>  url := &quot;git@github.com:lcostea/sample-controller-workshop.git&quot;</pre><pre>  dir := &quot;/tmp/sample-controller-workshop&quot;</pre><pre>  name := &quot;Liviu Costea&quot;</pre><pre>  email := &quot;_your_email_address_@gmail.com&quot;</pre><pre>  tag := &quot;v0.1.0&quot;</pre><pre>  r, err := cloneRepo(url, dir)</pre><pre>  if err != nil {</pre><pre>    log.Errorf(&quot;clone repo error: %s&quot;, err)</pre><pre>    return</pre><pre>  }</pre><pre>  if tagExists(tag, r) {</pre><pre>    log.Infof(&quot;Tag %s already exists, nothing to do here&quot;, tag)</pre><pre>    return</pre><pre>  }</pre><pre>  created, err := setTag(r, tag, defaultSignature(name, email))</pre><pre>  if err != nil {</pre><pre>    log.Errorf(&quot;create tag error: %s&quot;, err)</pre><pre>    return</pre><pre>  }</pre><pre>  if created {</pre><pre>    err = pushTags(r)</pre><pre>    if err != nil {</pre><pre>      log.Errorf(&quot;push tag error: %s&quot;, err)</pre><pre>      return</pre><pre>    }</pre><pre>  }</pre><pre>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4377a84bbf17" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/tag-example-with-go-git-library-4377a84bbf17">Tag example with go-git library</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes: one cluster for all or one per stage?]]></title>
            <link>https://medium.com/@clm160/kubernetes-one-cluster-for-all-or-one-per-stage-8af900c45e4c?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/8af900c45e4c</guid>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Thu, 16 May 2019 05:29:18 GMT</pubDate>
            <atom:updated>2019-05-16T05:29:18.992Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A-J-3MMAlYl5wkBzRpbycA.jpeg" /><figcaption>Image source: <a href="https://kubernetes.io/docs/tutorials/kubernetes-basics/">https://kubernetes.io/docs/tutorials/kubernetes-basics/</a></figcaption></figure><p>Kubernetes is a distributed container scheduler so it allows a more efficient way of using your resources. You run containers on a pool of nodes, which makes is possible to use those nodes at maximum capacity. But starting with it is not easy, concepts like pods, kubeletes, kube-proxy, controllers, NodePort, ClusterIp services and many others will keep you busy when you begin the journey.</p><p>One of the early decisions you will have to take is how to handle all the stages you will need: development, test, production or sandbox and maybe including some temporary ones, like performance testing, security or other compliance or new clients/features demo.</p><p>So <em>should you create and manage a separate cluster for each stage or one cluster to fit all should be enough?</em></p><p>Beginnings can be overwhelming, the ecosystem around kubernetes is big and getting bigger at a tremendous pace, just to get familiar with the concepts it comes with, you need at least 2–3 months. There are many things to grasp and to experiment and there is also the pressure to deliver something, to take actions and to move on to the next challenges. And these decisions might hurt a lot after a while, some will put a stop or even might kill your transition. And one of those important decisions is if to go with a single Kubernetes cluster and use separate namespaces for your development, testing, sandbox or to have a cluster per stage?</p><p>Reading about Kubernetes you will find out that it is based on Google’s ideas of running containers in production, their Borg project. And Borg has what it takes to run clusters of thousands of nodes, so having a few stages in the same cluster should not have any performance implications (just to chose the correct master size). Even more than that, it is actually a good thing because a cluster with many nodes will turn up to be more stable allowing more options when pods have to be rescheduled. And on a cloud environment with different availability zones (or just zones like Google Cloud names them) your kubernetes cluster should have at least 9 worker nodes to be able to talk about high availability (3 nodes in 3 distinct availability zones). So clearly it is not about performance or kubernetes not being able to handle large amounts of nodes.</p><p>And if you find out about namespaces, you will see that they are pretty good for isolations, it has first class support for network policies (there is a <a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/#behavior-of-to-and-from-selectors">namespace selector</a>), while <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole">RBAC roles</a> work on the namespace level. So it won&#39;t be too complicated to separate stages in the same cluster by using one or more namespaces per stage.</p><p>So why should you use separate clusters and not just one?</p><p>A few weeks ago I was lucky to be the moderator of the panel discussion on the DevOps track at <a href="https://devexperience.ro/">DevExperience.ro</a>, a conference from Iasi, Romania targeted at senior developers and devops. And because the trend right now is about Cloud Native technologies, our discussion topics were almost all around Kubernetes. And one of the questions that popped out was one cluster fits all or separate clusters per environment? I had great speakers on stage with me to address such questions, there was <a href="https://www.linkedin.com/in/mt165/">Matt Turner</a>, <a href="https://www.linkedin.com/in/viktorfarcic/">Viktor Farcic</a> and <a href="https://www.linkedin.com/in/daniel-patriche/">Daniel Patriche</a>. And they all agreed that one cluster for everything would be a good idea, but not from day 1. There are too many risks to take care of, so no need to add one more to the table by running production and non-production workloads on the same cluster. Even if you run one of those cloud flavours like GKE, AKS or EKS there are still problems that can appear after an upgrade. The control plane is managed for you and doing an upgrade is just making a change in the settings, but that can turn bad for your workloads. You can easily find stories of failures, there is even a <a href="https://github.com/hjacobs/kubernetes-failure-stories">Github repository full of them</a>. So why test an upgrade directly on your production, why not verify it first in a less risky place?</p><p>Of course there are big benefits of one cluster for everything, especially from operational perspective. There is only one cluster to manage, monitor, audit and upgrade, one set of credentials to store and rotate. But it is too risky from day one, you can ruin your business pretty easy with one wrong commit (if you&#39;re doing gitops).</p><p>So have a few clusters to start with, test your assumptions and learn to operate them in production, even if it is managed for you there are still things to handle and master, like tooling for manifests, pipelines and gitops operators or service meshes. Once you are comfortable with those, now you will be in a state with the right knowledge to revisit your initial decision.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8af900c45e4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helm from the trenches]]></title>
            <link>https://medium.com/hackernoon/helm-from-the-trenches-17f87859ee47?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/17f87859ee47</guid>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Sat, 16 Feb 2019 12:14:49 GMT</pubDate>
            <atom:updated>2019-02-23T20:48:54.045Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are working with Kubernetes then you should use <a href="https://www.helm.sh/">Helm</a> to be able to easily change the YAML resources for your applications. Helm is like a package manager for deploying applications on a cluster, it gives you a list of already created apps (charts) ready to install and you can also start creating your own and publish them in your own chart museum. Like on an operating system, life without a package manager would be much harder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*9mJCHusRXGq9PViqeajcZw.png" /><figcaption>Helm charts for an easier Kubernetes installation (image source: <a href="https://helm.sh/">https://helm.sh</a>)</figcaption></figure><p>I am using Helm day by day, and these are the things I found out while creating new charts or modifying existing ones. If I knew all these before starting with helm than things would have been smoother and I would of wasted less time searching error messages and solutions to all sort of problems or maybe just spent less time refactoring.</p><p>As prerequisites I assume you already have kubectl setup and you do have access to a cluster, no matter if it is one created on a cloud platform or just <a href="https://kubernetes.io/docs/tasks/tools/install-minikube/">minikube</a>. I also expect that you do have some knowledge on how to use helm and you installed some charts already and you fill confident about getting involved more in helm.</p><p>Before starting any work it is a good idea to take a look at the list of packages found in <a href="https://github.com/helm/charts/tree/master/stable">helm stable repository</a>. There is a lot to learn from those charts and we will use them as examples to illustrate a couple of ideas you can use to create your own charts. The helm stable repo is automatically added when helm is installed, so you can already start downloading and using any of those charts.</p><h4>Always use helm create for a new chart</h4><p>To start a chart is not very complicated, you only need to create some files inside a folder, like Chart.yaml, values.yaml and the actual resources (like a deployment) in the templates folder. You might be tempted to create them one by one by hand, it does seem like a good exercise. Or you might build your own scaffolding for it while learning go, node.js or some other language. But that&#39;s not a good idea. Instead you should always try to use the helm create command. Simply because it is always up to date with the recommended practices. For example if you run helm create test-chartright now the labels it sets are the <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/">latest recommended ones</a>, like app.kubernetes.io/name,, app.kubernetes.io/instance or app.kubernetes.io/managed-by. And if you just browse some charts from <a href="https://github.com/helm/charts/tree/master/stable">helm stable repo</a> you can see that they don&#39;t use such labels, simply because when they were created there were other recommendations.</p><p>Also if you look at the deployment it created (in templates/deployment.yaml file), you can see other interesting things, like that it is a good idea to parameterise the image repository and tag for your container (especially the tag because it will change quite often), but it is not common to parameterise things like liveness or readiness probe paths. If in the future it will be useful to have other values parameterised, be sure that the templating will be updated. So by using helm create to start your chart you make sure latest best practices are followed, of course with one condition: have the latest helm client version installed.</p><h4>Helm lint your chart including custom values</h4><p>It is a good practice to lint your charts before trying to install them. The linting will apply the templating (which happens on the client) and will verify that the output is a well formatted yaml.</p><p>Sometimes by default some resources will be excluded when the templating is applied. For example a web api can have an ingress rule added to enable outside communication only when some variable it set to <em>true (</em>and by default it is<em> false)</em>. So that will not be linted because the ingress resource will not be created. For such cases the <a href="https://docs.helm.sh/helm/#helm-lint">lint command</a> can take other values files instead of the default one (and set the variable to true in this file).</p><p>A good practice would be to create a <em>ci</em> folder on the same level as your <em>templates</em> one and put there the additional values files you want to verify. So if you have a file called <em>ingress-enabled-values.yaml</em> in your ci folder just run helm lint --values ci/ingress-enables-values.yaml In the stable charts you can see <a href="https://github.com/helm/charts/tree/master/stable/karma">that several have the ci folder</a> and I noticed that more and more are adding this folder lately (this folder might not be used just for linting, but mainly for test releases — for which I intend to write a separate article).</p><h4>Use dry-run and <em>debug</em> to see what the chart will install</h4><p>We will take a look at the <a href="https://github.com/helm/charts/tree/master/stable/postgresql">Postgresql chart</a> and see what will it install for us without actually doing the installation, just by using the 2 flags: dry-run and debug</p><p>helm install stable/postgresql --name standalone --dry-run --debug</p><p>What it will be displayed on the screen are all those YAML files that will be sent to the tiller (helm server component) in order to be applied on the cluster. Also you can add your local file (using -f values.yamlflag) that can override some of the default setting and this is very useful when you want to check how you can modify the resources to deploy, without installing the application yet.</p><p>Even more, this way of rendering the chart locally and verifying its output can be found in a <a href="https://github.com/lrills/helm-unittest">library that you can use for unit testing</a>. Take a look at it and if you find it useful add it to your chart pipelines. Unfortunately right now the library looks that is not maintained anymore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*WAliQmzjOx5qPuk4lxW1TA.png" /><figcaption>context is important for subcharts (image source: <a href="https://podfanatic.com/">https://podfanatic.com</a>)</figcaption></figure><h4>Understand the context, especially when using subcharts</h4><p>This is a very important thing to grasp when using subcharts. To explain what the context means we will take a look at the <a href="https://github.com/helm/charts/tree/master/stable/kong">kong chart</a>. Kong is a nice api gateway built on nginx, which is able to extend with a series of <a href="https://docs.konghq.com/hub/">plugins</a>. Kong uses Postgres or Cassandra for keep its state, so they are requirements in the chart.</p><p>If you look at the <a href="https://github.com/helm/charts/blob/master/stable/postgresql/templates/_helpers.tpl">Postgres chart templates functions file</a> you will see there a few functions that are using <em>.Chart.Name</em> value and you can also see that the chart name is <a href="https://github.com/helm/charts/blob/master/stable/postgresql/Chart.yaml"><em>postgresql</em></a><em>. </em>So whenever we will use {{ template &quot;postgresql.fullname&quot; . }} we should get a value with <em>postgresql</em> inside because <em>.Chart.Name</em> is part of the method.</p><p>But when the template is used inside kong chart and the postgresql is a subchart, the .Chart.Name will actually point to the kong chart name. Because that&#39;s the context now, we are not anymore under postgresql, in our example we will be under <a href="https://github.com/helm/charts/blob/master/stable/kong/Chart.yaml">kong chart name</a>. So using {{ template &quot;postgresql.fullname&quot; . }} will actually result in a name with <em>kong</em> inside (again, when used under kong chart — not postgresql subchart).</p><p>helm install stable/kong --name apigateway</p><p>Right now this issue is solved by adding another method with the <em>postgresql</em> name hardcoded. So this means code duplication and we have to remember not to use the method defined in postgresql chart, instead we need to use the one below. But until we will have a better solution provided by Helm, the community uses this one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b941910c082ae547570b4fa3419dc012/href">https://medium.com/media/b941910c082ae547570b4fa3419dc012/href</a></iframe><p><strong>Check installation on a separate test namespace</strong></p><p>Before saving the chart on your own chart museum, do a real installation of it on a test namespace. This helm release should not affect any other applications running in the cluster, that&#39;s why it is good to create first a test namespace with a random name. After the installation is done check that all the pods are in a Running state and all the config maps and secrets are attached, that all ingress rules are connected to services, resources and limits are defined and so on.</p><p>Try also an upgrade of the current release with some different values. And check that the upgrade went ok, following the same rules as above.</p><p>At the end cleanup the release and also delete the test namespace. This is a good functional test that your chart is ready to be used by other developers. Most likely such a test needs to be part of your <em>publish to chart museum</em> pipeline, along with a static analysis done by helm lint.</p><p><strong>Other useful helm commands</strong></p><p>Here are a few helm commands that are useful, but you might not be very familiar with them:</p><p>helm template [LOCAL-CHART-NAME] -x templates/file.yaml Useful for big charts, when the debug and dry-run flags are producing a very big output which will be hard to follow. Using -x with the path to the resource to output, will ease the checking and debugging.</p><p>helm history [RELEASE]— you can use this to see the revisions of a release, we need this in order to be able to call helm rollback [RELEASE] [REVISION] in case something went wrong with our installation/upgrade.</p><p>helm upgrade --reuse-values — the reuse-values flag is very useful when you want to do a small change to a release without running the helm install/upgrade again with all the parameters. For example when you have a typo in your installation and you fix your code, but just don&#39;t want to wait another 5 minutes for your pipeline to run</p><p>helm upgrade --install — this is helpful especially when running the command in pipelines, you don&#39;t need to write code to check if the release already exists, it will do this for you: if the release is found it will do an upgrade with the new values supplied, if there is no release then it installs it</p><p>helm install/upgrade --debug — I know I already mentioned the debug flag above on doing a fake installation, but it is so helpful that I will do it again. It is important to add it to your command especially when running in a pipeline, because it allows you to see what actually happened in case of an install or upgrade. Without it the output is not very informative and it doesn&#39;t help you too much when trying to understand what went wrong on the pipeline and what values were supplied to the command.</p><p>helm install/upgrade --set name=sandbox — You have the possibility to overwrite values to an installation/upgrade by using the set flag. This is useful to set a value that is calculated during the pipeline, like the git commit hash. But with this flag I would <em>not recommend</em> using especially on your pipeline because the value becomes hidden. Instead after calculating it, commit it to your repository in a values.yaml file and use that one. This way you have the history of changes in your repo and you follow the gitops approach.</p><p>And that&#39;s it, now you should be more prepared for working with Helm charts. And if you have other ideas on useful stuff on Helm, do let me know and I will add them to the article (along with the credits).</p><p><em>If you liked this and want more food for thought </em><a href="https://mailchi.mp/8eac933e024a/cloud-native-newsletter"><em>you can also register for my newsletter for people interested in Cloud Native technologies</em></a><em>. I am sending it at least once a month.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17f87859ee47" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/helm-from-the-trenches-17f87859ee47">Helm from the trenches</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Cloud Native path]]></title>
            <link>https://medium.com/hackernoon/the-cloud-native-path-b8ae6b14b79e?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8ae6b14b79e</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cloud-native]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Mon, 17 Sep 2018 05:25:17 GMT</pubDate>
            <atom:updated>2018-09-17T17:12:25.359Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*_HUyB-RR9rodjmYOAZJVXg.png" /><figcaption>Orchestration on cloud (k8 on Azure)</figcaption></figure><p>It is probably not the first time you heard the Cloud Native term. It is fashionable these days and it is propagated by many consultants and technology companies. Of course they are all saying you have to get aboard this train, the benefits are huge and you surely can&#39;t afford to lose it. But what does it exactly means and why wasn&#39;t cloud computing enough? To answer this let me shortly explained what I understood a couple of years ago by cloud computing and what I learned after it.</p><h3>Liviu Costea on Twitter</h3><p>Today we created our first auto scale group on #aws, starting and stopping instances based on queue values</p><h4>Autoscaling</h4><p>I deployed a first production app on AWS back in 2012. It wasn&#39;t designed for the cloud, we were spinning up a vm, connecting to it, copying the binaries and starting the web server. But version after version we learned and understood what the power of the cloud meant in a word: <em>autoscaling</em>.</p><p>In order to support both scaling up and down, your application had to be stateless: you can&#39;t save things to the local disk or the session details in process because that vm can always be terminated as a result of a scale down event. The same was with logs: if before writing logs on the disk was enough as you could always retrieve them, now that luxury was gone. But this was great because this is how many teams adopted tools like Kibana or Graylog. Another thing autoscaling brought to the table was that you didn&#39;t have to over provision, you started with a processing power and then based on metrics you were able to reduce or increase that power. And the good part of the cloud was that our bill was for exactly what we used, if a vm only ran for 2 hours, we only paid those hours and nothing else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*RcyN7K1KDkNR80EXb5oJ3A.png" /><figcaption>Autoscaling on AWS</figcaption></figure><p>The true gain wasn&#39;t the money. I worked with some companies that didn’t move to the cloud just because they had a big infrastructure investment already done and when they calculated their monthly cloud bill even with all the discounts the received, it was just too much.</p><p>The cloud meant no upfront investment, but on the longer run you actually were paying more, so for companies already with a big investment in infrastructure it was far from feasible. But that was a very simplistic view. The main gain came from the flexibility we gained by being able to handle the spikes we had from our clients and reduce costs when there was less traffic. And more important was that we outsourced completely our infrastructure to pretty good engineers that were providing us a realiable API for it. We all know good developers are hard to find.</p><h4>Automation</h4><p>Soon we realized it was pretty repetitive work what we were doing: copy the binaries on the existing vm, create a new image for the vm and create a new auto scaling group. Also the term immutable infrastructure was getting more attention, so the next natural step for us was to start using a configuration management tool like Ansible or Chef and later adding Terraform for infrastructure. This allowed us to always create a new vm for a new version and just replace the older vm with the new one in the load balancer. Which brought us really close to no downtime deployments, we just had to separate the database deployments than the code ones (or the db to support 2 different code versions).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wz9PbUoWiqSTST0P_WT8mA.png" /><figcaption>devops.com</figcaption></figure><p>What happened since I started automating application installation until today? Well now I see everything in pipelines. Do you need a completely new environment to test your new features. A pipeline should do that, no matter if the output is a new kubernetes cluster or a new set of vms for your app and db or just a new s3 bucket and a route53 entry for a static site hosting. Need to run upgrade scripts for your database? Sure, there should be a pipeline to handle that (and totally separated from the code one). And so on for application deployment. Just remember to separate CI from CD.</p><h4>Move to microservices</h4><p>Even from the first monolith that I worked with we had discussions about separating the product verticals. If you sell on your website both hotel rooms and car rentals, why a deploy to one of the product should affect the other? And back then they always did. We could just disable car rentals from the website, do an upgrade to it and then enable it back. So our move to microservices was the normal path, even though when we started with it we were actually building a distributed monolith.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*VPRiTkyZDqCn62UEF76aQA.png" /><figcaption><a href="http://people.groupon.com/">people.groupon.com</a></figcaption></figure><p>And while using microservices you will soon have to start with containers because you simply realize running one microservice per vm is just too much, especially when you end up with a big number of them. So we started with autoscaling, used some automation and this brought us to the path of microservices and later containerisation. And there is still one last step to reach cloud native and that is to use a container orchestration engine.</p><h4>Orchestration</h4><p>Running microservices and containers becomes pretty hard when you reach a big number of microservices. New hosts have to be added, while some will need maintenance. New versions of microservices are being added constantly and we need different ways to deploy those new versions. So the next natural step is to start using a container orchestration engine like ECS, Docker Swarm or Kubernetes. Actually first you probably end up writing many scripts for orchestration, but you should soon realise that such a solution just doesn&#39;t scale. And in the last years Kubernetes is by far the default choice for orchestration and somehow it became the starting point when taking the cloud native way.</p><h4>Cloud native</h4><p>So at the beginning I said cloud computing for me is equivalent of doing autoscaling and I tried to explain how I came to the concusion that autoscaling means using the power of the cloud versus the classic hosting solutions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*wupcY2GEfamIwX0ydGDvNQ.png" /><figcaption>pivotal.io</figcaption></figure><p>And now if you are taking the cloud native way you are most likely doing kubernetes or some other solution of container orchestration. Because that means you are running containers, you have an microservices architecture in place, automation and pipelines are in use for deployments and your hosts and microserices are autoscaling based on monitoring that you do for your application. And these are the pillars for cloud native computing.</p><p>I remember going from a classic application to one that was able to autoscale was a pretty hard transformation that lasted more than 1 year (almost 2 for us). Now going from cloud computing up to container orchestration with having all the pipelines in place is also a journey that I think it will take a little more, while some even say this road is never ending. And of course it is totally worth it, you can&#39;t miss this train.</p><h4>References:</h4><p>AWS: What is Cloud Computing? <a href="https://aws.amazon.com/what-is-cloud-computing/">https://aws.amazon.com/what-is-cloud-computing/</a></p><p>Pivotal.io: What are Cloud-Native Applications? <a href="https://pivotal.io/cloud-native">https://pivotal.io/cloud-native</a></p><p>Container-Solutions: Six steps to Successful Cloud Native migration <a href="https://container-solutions.com/six-steps-to-successful-cloud-native-migration-part-1/">https://container-solutions.com/six-steps-to-successful-cloud-native-migration-part-1/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8ae6b14b79e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/the-cloud-native-path-b8ae6b14b79e">The Cloud Native path</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL APIs for backend devs]]></title>
            <link>https://medium.com/hackernoon/graphql-apis-for-backend-devs-bba579e72eba?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/bba579e72eba</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[rest]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Tue, 22 May 2018 12:02:52 GMT</pubDate>
            <atom:updated>2018-05-22T19:01:49.486Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*FnsL3hkbTOPm5Eto9g4Zwg.jpeg" /><figcaption>From SOAP to REST and probably GraphQL</figcaption></figure><p>During my software development career I built and consumed a lot of web services. Usually they were consumed from server side apps built with .NET, One of the biggest project I have worked on was a platform where we merged a lot of data from different sources and displayed the results to the user on a web interface(yes, I was working on some kind of broker firm at that point).</p><h4>SOAP Web Services — with XSD</h4><p>Almost all of those web endpoints were using SOAP and they were pretty easy to query because we always got a schema (an XSD) file from our partner. Receiving the XSD is a very good start because the client is generated for you by the tools. On the other hand it is not the best solution, sometimes we had to manually change the generated code because of the differences of stacks between the client and server. Which could lead to issues when upgrading to a new version, because you could overwrite the changes, so we had to spend some time comparing changes in source control and we ended up making the upgrade manually, change by change. The generated code in c# uses partial classes, so theoretically any change that you would need to do can be done outside the generated code. But I still remember cases when the change was so big that we couldn’t do it in another file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*qobC5Tck5kuytV5GKH1YyQ.jpeg" /><figcaption>XSD code generation in action</figcaption></figure><h4>REST — loose coupled web services</h4><p>But nothing compares to the first time we had to use a REST endpoint. This company advertised their new <em>great shiny cutting edge out of this world </em>API. Everything was looking great, until we started to actually build our .NET client for it. Imagine 5 or 6 endpoints each returning tens maybe hundreds of parameters with several levels of nesting. And you had to write those boilerplate properties one by one, browsing through examples, wondering which is an array, if it can be an int or to leave as string and so on.</p><p>And then they ask you why does it take 3 months to connect to their new API? <em>Duhhh…</em></p><p>So XSD helped you a lot on day 1: get your client fast at a running state and then worry about future upgrades and versioning later. Most of the time we would consume much more data than needed. I don’t remember spending time removing the fields which we didn’t need to make the process lighter. While on the REST side, there was a lot of code to be written, and that was important because do a mistake there and all your deserialization fails. Indeed we could get to a more flexible client in the end, by adding only the needed fields, but it was an error prone process.</p><p>SOAP was still coupling the client and server with that schema generation, while REST came with the real loose coupled promise enabled, just that we weren’t ready for it (at least on the backend side). And because the problem was real, projects like <a href="https://swagger.io/">SWAGGER</a> appeared, which translated your api to a open source DSL which other clients can consume automatically. Lately there is an increase of providing some sort of SDK along with the API for REST endpoints, which requires an extra effort but is a step in the right direction, because clients can connect much faster to you. But there are still many companies that lack that understanding.</p><h4>Entering GraphQL</h4><p>Now when you hear about GraphQL the main thing that you read about is that you can pick the columns that can be returned from the server. And how great is that for building your mobile and web clients without the needs of creating several REST endpoints just because they need different fields to manipulate and display. If you browse the jobs that have GraphQL as a requirement, you will see almost all in the front end and mobile development. That’s where it is really popular.</p><p>What about backend development? If you are building an external API for your product, can GraphQL be a reasonable choice? Do you have any advantages on switching from a REST API with Swagger to a GraphQL one?</p><h4>GraphQL Schema</h4><p>For me as an API builder and consumer the most important benefit in creating a GraphQL API is the schema and all the tools it gives you out of the box for versioning it.</p><p>GraphQL offers a schema out of the box with scalar and complex types (which are made of other complex types or scalar types), queries, mutations (whihc are also some special types) and many other elements that help your API definition.</p><p>In the image below (screenshot from <a href="https://www.graphqlhub.com/">https://www.graphqlhub.com</a> of the Twitter API — not official) you can see a Tweet object composed from some scalar types like String, Int, ID and a few object types like TwitterUser or Retweet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*d1oMk0u0DEHgv6ZU-LdLeQ.png" /><figcaption>TwitterAPI defined at GraphQLHub.com seen in a Graphiql UI</figcaption></figure><p>When the industry moved from SOAP to REST it took a while to understand the new concept. That there weren’t anymore methods exposed on a protocol, but the schema was about creating endpoints and exposing data around those endpoints. With REST it was about using Uniform Resource Identifiers and how the HTTP verbs can be transformed into actions. The same path it will apply to the transition to GraphQL. Like I said, first time you read about it you see that you can chose your columns on the client. Then you find out that it has a schema with types, which is a big advantage over REST. And maybe just after that or maybe a few more steps you will realize that in order to build a GraphQL API it is all about seeing data as graphs. When you start defining a new schema, it is not about exposing methods, or creating endpoints, it is actually about how your data is connected because it always is.</p><h4>It’s graphs all the way down</h4><p>Lets take a simple example, but complex enough to explain the concept: books and authors. In a REST architecture you would build 2 endpoints, one for authors and one for books. Thinking about the GraphQL schema, it is clear that there are going to be 2 types: Author and Book and a query to expose those 2 types. But these objects are closely related, because an author has written one or more books. So on the Author type we will add a list of Books.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*SKDttmmI918jevWuFMf_Dw.png" /><figcaption>authors query — an author has a list of books</figcaption></figure><p>Even more, the relation between authors and books is n to n, because a book can have more than one author. Which is exactly the case in our example, the book <em>Origins: Fourteen Billion Years of Cosmic Evolution </em>was written by 2 authors: Neil deGrasse Tyson and Donald Goldsmith. Which means we will add a list of authors to our Book type and we already have a cycle in our graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*w6AS412biFRQEWVF7MEaOg.png" /></figure><p>And now we have the full information in one query: we have the author with his books and we can also include all the authors of a book if we need the info. So it is not anymore about endpoints and URI, instead it is about the data and the connection between the nodes of the data. And on our GraphQL query we can clearly see the relation between our types.</p><p><em>Thanks for reading. Btw, if you are from Iasi, Romania you can join my free </em><a href="https://www.meetup.com/Microservices-Iasi/events/249451432/"><em>GraphQL in .NET Core workshop happening on 5 June</em></a><em>. Being a workshop there are limited places, but if many more people are interested we can have a second run.</em></p><p><a href="https://mailchi.mp/c6f9b64a7def/dotnet-newsletter"><em>You can also register for my newsletter for software developers interested in .NET technologies</em></a><em>. I am planning to send that twice a month, starting June 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bba579e72eba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/graphql-apis-for-backend-devs-bba579e72eba">GraphQL APIs for backend devs</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[7 things you didn’t know about .NET code]]></title>
            <link>https://medium.com/hackernoon/7-things-you-didnt-know-about-net-code-a7acf4b2c455?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7acf4b2c455</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[aspnet]]></category>
            <category><![CDATA[dotnet]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Fri, 13 Apr 2018 11:55:11 GMT</pubDate>
            <atom:updated>2018-05-22T06:45:51.940Z</atom:updated>
            <content:encoded><![CDATA[<p>These are a few things (in no specific order) I found out during many hours of work, discussions with colleagues and a-ha moments. And I would like to share them with everyone and don’t be ashamed if you don’t know some or even all of them. In some cases it took me years to get to know them. So embrace them and it might make you a better .NET developer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HhXGK7Sd8x4LOyoswciC-Q.png" /><figcaption>Geeky stuff</figcaption></figure><h4>Number 1: Out parameter always changes value</h4><p>Here is some simple code and a simple question:</p><pre>int testParameter = -1;</pre><pre>Int32.TryParse(“abc”, out testParameter);</pre><p>What will the value of <em>testParameter</em> be after the TryParse executes?</p><p>Easy to try for yourself, just put this in console application and display the value of testParameter. If you expected it to be -1 then you are wrong. Even if the TryParse will not succeed, the value of the int will become the default value, so it will be 0 (zero). This is what MSDN says about the out parameter: <a href="https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx"><em>This parameter is passed uninitialized; any value originally supplied in result will be overwritten.</em></a></p><h4>Number 2: Enums can have extension methods</h4><p>We had a big Enum in code with the possible values of a variable. I am not getting into details why we need it or if it was the best choice for us, it’s not the case here. Lets say it looked something like this (trust me, it was bigger, this is just a smaller similar example):</p><pre>enum Day {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};</pre><p>Now imagine that if you would like to see if it is weekend, your code will be similar to this:</p><pre>if (dayParameter == Day.Sun || dayParameter == Day.Sat) ….</pre><p>So I created a method called IsItWeekend(dayParameter). Then one colleague said why don’t we create an extension method, instead of having the above method in every class we might need it?</p><p>And to be honest I didn’t think it would be possible to create an extension method on Enums, but 2 days later I came back to him and said: ‘sorry, I was wrong, it is possible to do it’. And I found that it really is powerful because the most used alternative is to create a Helper class and I don’t like them at all. I am not getting into details on how to create such an extension method because there is a <a href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-create-a-new-method-for-an-enumeration">very good article on MSDN about it</a>. I believe it is more important to remember that it can be done.</p><h4>Number 3: Use HashSet for distinct items</h4><p>I find this code quite a lot in many projects:</p><pre>List&lt;string&gt; uniqueItems = new List&lt;string&gt;();<br>if(!uniqueItems.Contains(parameter))<br>{<br>   uniqueItems.Add(parameter);<br>}</pre><p>So is there a problem with this? It works, but Contains performs a linear search on the list and that is O(n). Which can translate into performance issues in production if you end up having many of these (usually big CPU usage). Until .NET 3.0 people were creating Dictionaries with the key collection used for distinct lists and with the values set as NULL. But since .NET Framework 3.5 we have a new class called <a href="https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1?view=netframework-4.7.1">HashSet&lt;T&gt;</a>. This is a collection without any duplicate elements and <a href="https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.contains">Contains method is O(1) operation</a>. So our code quickly becomes:</p><pre>HashSet&lt;string&gt; uniqueItems = new HashSet&lt;string&gt;();<br>if(!uniqueItems.Contains(parameter))<br>{<br>   uniqueItems.Add(parameter);<br>}</pre><p>Even more, we can remove the Contains call because Add will not add the element if it already exists, it just returns false (or true if it will be added). So again the code becomes like this:</p><pre>HashSet&lt;string&gt; uniqueItems = new HashSet&lt;string&gt;();<br>uniqueItems.Add(parameter);</pre><h4>Number 4: Many value types don’t live on the Stack</h4><p><em>Value types are allocated on the Stack and reference types are allocated on the Heap.</em> That’s what we learned, that’s what we say in interviews and we get away with it. Probably a lot of .NET books that are for beginners are saying this, so we read it from our first steps with C#. But it is wrong, it is just a myth, there are so many value types saved on the heap and here are two important examples of when that happens.</p><ul><li>If the value type is a instance variable of an object then it gets saved on the Heap. Simple because that is where the whole object lives, so that’s where the value types get allocated too.</li><li>Another case is for static variables: a value type static variable is allocated on the Heap. And it makes sense because there is only one instance of that variable.</li></ul><p>So what is the difference between value types and reference types, you might ask? That’s very simple: value types are passed by value (even if it is an instance variable of a reference type) while reference types are passed by reference. Which means that next time in an interview you can give a more accurate answer.</p><p>For more details on the subject of value types and reference types <a href="http://www.yoda.arachsys.com/csharp/parameters.html">here is a great article by Jon Skeet</a>.</p><h4>Number 5: Response.Redirect on out of process sessions</h4><p>This is one of my favorites because I found it around 2014 when we wanted to change an existing application to use out of process session. Our aim was to support multiple servers, but we didn’t want to use sticky sessions — we were deploying on AWS so using sticky sessions meant loosing all the advantage of auto scaling. We did learn a lot from going out of process with the session and using Response.Redirect was one of the outcomes. Lets say we have some simple code like this:</p><pre>Session[“FlowId”] = Guid.NewGuid();<br>//more code goes here<br>Response.Redirect(Url.Action(“Account”, “Login”));</pre><p>This works perfectly when the session is in process, but when it goes out of process that Session[“FlowId”] item will not get saved. It happens because Response.Redirect throws a ThreadAbort exception and because of that the thread never gets to the part where it saves the Session object in the outside store. When the Session is used in process all the changes are done on spot, which means that throwing the exception doesn’t affect the saving.</p><p>So what is the solution for making it work? Simple, Response.Redirect has an overload that takes a second parameter endResponse, just pass false and the exception will not get thrown. <a href="https://msdn.microsoft.com/en-us/library/a8wa7sdt(v=vs.110).aspx">It is even recommended to set it to false because of performance reasons</a>.</p><pre>Session[“FlowId”] = Guid.NewGuid();<br>//more code goes here<br>Response.Redirect(Url.Action(“Account”, “Login”), false);</pre><h4>Number 6: A generic type creates different classes</h4><p>We have the following class:</p><pre>public class GenericCache&lt;T&gt;<br>{<br>     public static int ctorCalls = 0;<br>     private List&lt;T&gt; list;<br>     public GenericCache()<br>     {<br>         ctorCalls++;<br>         list = new List&lt;T&gt;();<br>     }<br> }</pre><p>The implementation is pretty dumb, just for education purposes (so don’t ask me why ctorCalls is a public field). But such a class can be found quite frequently in a big application. There always has to be a Cache class (so you can save expensive I/O calls) and it will be a matter of time until it becomes generic (because you will use it for many of your classes).</p><pre>GenericCache&lt;string&gt; genericCache = new GenericCache&lt;string&gt;();<br>GenericCache&lt;int&gt; genericCacheInt = new GenericCache&lt;int&gt;();<br>Console.WriteLine(GenericCache&lt;DateTime&gt;.ctorCalls);</pre><p>In the lines above the constructor of the generic Cache class is called twice and then we want to print the value of ctorCalls to the console.</p><p>So what value will it display? Well if you say 2 then you are wrong. It is what generic does behind the curtains: GenericCache&lt;string&gt; will be a different type (class) than GenericCache&lt;int&gt; and GenericCache&lt;DateTime&gt;. Which means the static variable ctorCalls will have 3 instances, one for each generic type. So the value displayed to the console will be 0.</p><h4>Number 7: Order of logical operations (AND and OR)</h4><p>Ending with an easy and powerful one. This can create you a lot of headaches if not handled properly: <em>&amp;&amp; (AND) is more powerful than || (OR)</em>. Lets take a few examples to see what that means and how it can affect your code:</p><pre>bool result;</pre><pre>result = (true || true) &amp;&amp; false; //this gives false</pre><pre>result = true || (true &amp;&amp; false); //this gives true</pre><pre>result = true || true &amp;&amp; false;// what will be the result of this?</pre><p>L̵i̵k̵e̵ ̵I̵ ̵s̵a̵i̵d̵ ̵a̵b̵o̵v̵e̵ ̵A̵N̵D̵ ̵i̵s̵ ̵m̵o̵r̵e̵ ̵p̵o̵w̵e̵r̵f̵u̵l̵ ̵t̵h̵a̵n̵ ̵O̵R̵,̵ ̵w̵h̵i̵c̵h̵ ̵m̵e̵a̵n̵s̵ ̵i̵t̵ ̵w̵i̵l̵l̵ ̵b̵e̵ ̵r̵u̵n̵ ̵f̵i̵r̵s̵t̵,̵ ̵e̵v̵e̵n̵ ̵i̵f̵ ̵i̵t̵ ̵i̵s̵ ̵t̵h̵e̵ ̵s̵e̵c̵o̵n̵d̵ ̵o̵p̵e̵r̵a̵t̵i̵o̵n̵.̵ ̵S̵o̵ ̵t̵h̵e̵ ̵t̵h̵i̵r̵d̵ ̵c̵a̵s̵e̵ ̵a̵f̵t̵e̵r̵ ̵w̵e̵ ̵d̵o̵ ̵t̵h̵e̵ ̵A̵N̵D̵ ̵o̵p̵e̵r̵a̵t̵i̵o̵n̵ ̵w̵i̵l̵l̵ ̵b̵e̵c̵o̵m̵e̵:̵ ̵r̵e̵s̵u̵l̵t̵ ̵=̵ ̵t̵r̵u̵e̵ ̵|̵|̵ ̵f̵a̵l̵s̵e̵ ̵s̵o̵ ̵i̵t̵ ̵w̵i̵l̵l̵ ̵g̵i̵v̵e̵ ̵y̵o̵u̵ ̵t̵r̵u̵e̵.̵ ̵S̵o̵ ̵i̵t̵ ̵i̵s̵ ̵e̵x̵a̵c̵t̵l̵y̵ ̵t̵h̵e̵ ̵s̵a̵m̵e̵ ̵w̵i̵t̵h̵ ̵t̵h̵e̵ ̵s̵e̵c̵o̵n̵d̵ ̵o̵p̵e̵r̵a̵t̵i̵o̵n̵.̵ ̵N̵o̵w̵ ̵m̵y̵ ̵s̵u̵g̵g̵e̵s̵t̵i̵o̵n̵ ̵i̵s̵ ̵t̵o̵ ̵a̵l̵w̵a̵y̵s̵ ̵u̵s̵e̵ ̵p̵a̵r̵e̵n̵t̵h̵e̵s̵i̵s̵ ̵f̵o̵r̵ ̵t̵h̵e̵ ̵o̵r̵d̵e̵r̵ ̵o̵f̵ ̵o̵p̵e̵r̵a̵t̵i̵o̵n̵s̵ ̵t̵o̵ ̵l̵o̵o̵k̵ ̵m̵o̵r̵e̵ ̵c̵l̵e̵a̵r̵.̵</p><p>The above explanation is not correct, the result will be true, but not because of the operator precedence, but because short circuit is applied. It knows the first value is true so it doesn’t go to execute the || and &amp;&amp; operators it just stops and returns true.</p><p>Until I find a better example I will just put here the link to <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/#conditional-and-operator">C# operators, that says AND conditional parameter is above OR.</a> And thanks to <a href="http://twitter.com/kabtoffe">@kabtoffe</a> for pointing this out.</p><p>That’s it and I hope it is helpful to you. And please leave a comment if you know other interesting things that should be on the list of gotchas for .NET/C# code.</p><p><em>If you liked this and want more food for thought y</em><a href="https://mailchi.mp/c6f9b64a7def/dotnet-newsletter"><em>ou can also register for my newsletter for software developers interested in .NET technologies</em></a><em>. I am planning to send that twice a month, starting June 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7acf4b2c455" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/7-things-you-didnt-know-about-net-code-a7acf4b2c455">7 things you didn’t know about .NET code</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[After thoughts after Voxxed Days Bucharest 2018]]></title>
            <link>https://medium.com/@clm160/after-thoughts-after-voxxed-days-bucharest-2018-b025eb6af23b?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/b025eb6af23b</guid>
            <category><![CDATA[future-technology]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[conference]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Wed, 28 Mar 2018 06:19:20 GMT</pubDate>
            <atom:updated>2018-03-28T06:31:57.241Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*hwtIF9IZx74okj767BC_YA.jpeg" /></figure><p>Last week I attended <a href="https://voxxeddays.com/romania/bucharest/2018-03-22/">Voxxed Days Bucharest 2018</a>. This was a nice event, very well organized and even if I am a .NET developer and the conference is leaning more towards the Java side I still found some interesting talks and ideas.</p><p>Out of all 2 things remained in mind (even after a couple of day after it finished) and entered my to do list of things to check out in the next months.</p><h4>GraphQL</h4><p>The first one is GraphQL. I knew about it for quite some time, did some reading, but I haven’t gave it too much attention. But there were some really good presentations around this subject, some just saying how great it is, but some presented real projects done with it. So I am giving it a try. There are libraries that allow creating API with GraphQL support in .NET so in the next months I plan to study this subject in depth.</p><h4>Chat bots</h4><p>Second thing that caught my attention are chat bots. Again this is something I read about, but I didn’t get to study it very carefully. There were some interesting presentations around it, including a small 2 hours workshop that showed how easily you can build a chat bot that takes some simple commands. So for sure I will give that a try in the next months.</p><p>That’s it and now I can’t wait for the next edition and good luck to the organizers to get to the Devoxx level.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b025eb6af23b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Confessions of a technical interviewer]]></title>
            <link>https://medium.com/hackernoon/confessions-of-a-technical-interviewer-a977e7cadfd8?source=rss-760814c24284------2</link>
            <guid isPermaLink="false">https://medium.com/p/a977e7cadfd8</guid>
            <category><![CDATA[management]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[experience]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[work]]></category>
            <dc:creator><![CDATA[Liviu Costea]]></dc:creator>
            <pubDate>Tue, 20 Mar 2018 10:02:37 GMT</pubDate>
            <atom:updated>2018-03-20T10:02:37.855Z</atom:updated>
            <content:encoded><![CDATA[<p>Since I started my career as a software developer back in 2003 I have been involved in a lot of interviews in all possible situations.</p><p>I was the one who was applying for the job, the one that had a saying in the hiring, the one who took the decision of hiring/not hiring, while at <a href="http://wantsome.ro/curs-programare-dot-net-iasi">Wantsome.ro</a>, where I am teaching a .NET programming course, I am working with people to help them pass technical interviews.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wPz5ZkVRos0AZIbc7AFEw.jpeg" /><figcaption>It shouldn’t happen, but it can get tough during interviews</figcaption></figure><p>And I had failures in all situations, in some interviews I didn’t get a job offer even though I believe I was pretty qualified for it, while in some other cases I took wrong decisions and hired some developers I really wish I didn’t. But most interesting I was able to recognize 3 kinds of interviewers. And based on the interviewer type you can find out a lot about the company you are applying to and your possible future colleagues. So let me explain how a junior interviewer behaves and what means to be a senior one, no matter how many years of experience they had in the field of software development.</p><h4>Junior interviewers</h4><p>By junior interviewer I don’t mean someone who is a junior developer and also an interviewer. It doesn’t really matter how many years of experience he has, it is more about what he is after during a technical discussion with a candidate.</p><p>Now everybody asks the basic questions like OOP ones, framework related, regarding your previous projects and experiences. So it is not about these. Instead the junior interviewer will always look for ways to impress you with his knowledge. He cares less of how much you know or what you should know and he will ask questions about strange situations that he found, confronted and solved or maybe details about a specific class from a framework. During the interview it is more about him shining than discovering the candidate.</p><p>And I can confess that in my first years as an interviewer I was doing that a lot. Questions about situations you only find once in a few years, very specific cases about how the framework you use is behaving, stuff that if a developer knows doesn’t tell you anything about his coding or problem solving skills. In 80–90% of the cases the person being interviewed said ‘<em>I don’t know/ I never got in such a situation</em>’ and that was the end of questions like that. But for me that was a sign that I knew more, that I was the senior, that I was shining.</p><p>I still hear about this quite often at the place where I teach, my students told me about some strange questions they received. While they apply for junior positions they don’t always get interviewed by senior developers and skilled interviewers so they get into all sort of situations. The only thing they can do is not to worry about them and instead concentrate on the important stuff, like algorithms and problem solving techniques, OOP basics, web — HTTP — MVC details. And if you take the feedback from your interview and see where you need to get better, an offer will come sooner or later and might be even from the same company who said no 6 months ago.</p><h4>Advanced Junior interviewers</h4><p>In some of the interviews I have been involved I noticed this trend of digging around things the candidate doesn’t master very well. It is like that if the interviewer feels that you are not very good at doing something he will keep asking you about that. Now this is a little more advanced that those strange questions, but it is still not a step in the right direction because the interviewer should focus more on what the candidate knows and what is he experienced on. As an interviewer, once you found something that you feel your candidate doesn’t know well enough, mark it down and move on. If you just circle around what he doesn’t understood well enough, there a lot of things that he might know and you might miss them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*zo4poZ2CSfvFXD0YUciwyQ.png" /><figcaption>Try to see what the candidate knows, don’t concentrate on his weaknesses</figcaption></figure><p>I believe that from a certain level any developer can block another one with a question, there are so many things to learn out there that everyone has gaps in his knowledge, it is just a matter of time until they will be found. If you concentrate on those once you find them the whole interview experience goes down and the candidate will not feel good about not knowing to explain the concept well enough. And it can get worse when it becomes the center piece of the interview and what everyone will remember about it in the next months or maybe years. And as an interviewer your goal is to find out what that person knows and to see if she can be a good fit for your job description.</p><h4>Senior interviewers</h4><p>Now at some point I realized the strange questions were not helping at all. And also if I find a gap when someone explains a concept after a few tries to see if she doesn’t understand it, I will move on. There are so many things you can ask during an interview and there is a limited time for it. Such a discussion should be more related to the day to day work and less about strange things happening with your framework that you will see once every 2 years. And because I want to get as much as possible from the candidate the atmosphere is as informal as it can be.</p><p>And that’s when I introduced live coding during the interviews. I tried to cover OOP basics not by asking what is polymorphism, inheritance or composition, instead we worked on a design of a real task you would possible get from a client. How would you implement it, how to make it flexible and scalable, what tests should be in place. And this helped me avoid hiring some developers that were really good at talking about concepts, but they couldn’t write any code at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*8HU57ryiCKpGvPk8BfdJCg.jpeg" /><figcaption>Concentrate on experiences and possible situations, avoid trivia questions</figcaption></figure><p>A way to easily spot a valid candidate is if he is clear in explaining his past experiences and what he build makes sense, like not reinventing the wheel. Even for developers applying for their first job, they have small projects that they built during their studies. I aim to avoid the trivia questions and talk more about experiences and how to handle all sorts of situations. Even if the candidate missed one or two important concepts it might be OK. The software world is very vast and there are a tone of other things he could know. And one of the tasks at my job is to find those things and if I think they can help us then welcome to the team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a977e7cadfd8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/confessions-of-a-technical-interviewer-a977e7cadfd8">Confessions of a technical interviewer</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>