Thursday, July 22, 2021

Azure Kubernetes Service- Failed to acquire a token

When invoking ‘kubectl’, it failed with the following error message:

PS /home/bart> kubectl apply -f ./example.yaml

E0720 07:58:14.668222     182 azure.go:154] Failed to acquire a token: unexpected error when refreshing token: refreshing token: adal: Refresh request failed. Status Code = '400'. Response body: {"error":"invalid_grant","error_description":"AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2021-03-31T13:22:18.9100852Z and was inactive for 90.00:00:00.\r\nTrace ID: 68f8e37d-4d18-4e7d-a3e6-b11291831a02\r\nCorrelation ID: 65ee9420-d6f9-4a7c-8214-a82756c7ecc8\r\nTimestamp: 2021-07-20 07:58:14Z","error_codes":[700082],"timestamp":"2021-07-20 07:58:14Z","trace_id":"68f8e37d-4d18-4e7d-a3e6-b11291831a02","correlation_id":"65ee9420-d6f9-4a7c-8214-a82756c7ecc8","error_uri":""}

The error is self explaining. My refresh token has expired and as a consequence it was not possible to get a new access token.

But how can we fix this?

We need to re-invoke the az aks get-credentials command. You’ll have to authenticate again after which the credentials will be downloaded and available in the Kubernetes CLI.

az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

Wednesday, July 21, 2021

Passing a cancellation token to an IAsyncEnumerable

I talked about the concept of asynchronous streams before. Thanks to the introduction of the IAsyncEnumerable interface, it allowed us to combine the richness of LINQ with the readibility of async-await to asynchronously access databases, microservices and remote APIs.

As enumerating async streams will typically result in remote asynchronous operations it can take a while to complete. I was wondering how we could cancel these async operations?

To support this use case, IAsyncEnumerable has an extension method ‘WithCancellation()’. The CancellationToken will be passed on to the  IAsyncEnumerable.GetEnumerator method.

More information about what’s happening behind the scenes can be found here.

Remark: There are some further improvements on the way in ASP.NET Core 6 regarding consuming IAsyncEnumerable streams as mentioned in this post:

Tuesday, July 20, 2021

Kubernetes–What is the difference between resource requests and limits?

In Kubernetes it is a best practice to configure resource limits for your containers. VSCode will even warn you if it couldn’t detect resource limits in your manifest files:

Setting resource limits prevents a container consuming too much resources and impacting other workloads. By setting limits, pods will be terminated by Kubernetes when their limits are exceeded. This helps in keeping the cluster healthy and stable.

The most common resources to specify are CPU and memory, but others exists.

Here is a short example on how to configure this at the container level:

In the example above, the CPU usage is limited to 250m or  250 milliCPU (1/4th of a vCPU/Core) and memory usage is limited to 512Mi or 512MiB.

Next to resource limits, it is also possible to configure resource requests. Setting a resource request indicates the amount of that resource that you expect the container will use. Kubernetes will use this information when determining which node to schedule the pod on.

A node will be ineligible to host a new container if the sum of the workload requests, including the new container’s request, exceeds the available capacity. This remains the case even if the real-time memory use is actually very low.  This is the reason why it is best to keep the requests values as low as possible and setting the limits as high as possible(without bringing other workloads into trouble). Using a low resource request value gives your pods the best chance of getting scheduled to a node.

Limits are also configured in the resource section of your manifest file:

More information:

Monday, July 19, 2021

Windows Terminal–Add Git Bash

I’ve started to love Windows Terminal. So it would be nice if I could add Git Bash to the list of possible terminal experiences.

Before you can start integrating Git Bash,make sure that it is available on your system. You can install it as part of the Git for Windows experience.

Open up Windows Terminal and select the down arrow in the tab bar at the top. Select Settings from the dropdown menu.

This opens the Settings tab for Windows Terminal.

I first tried to add a new Profile for Git Bash using the Add new option on the left but I couldn’t get it working.

What I did instead was choosing the Open JSON file option.

Now I could directly alter the configuration file. In the profiles list I added the following configuration:

Friday, July 16, 2021

.NET Conf–Focus on F#

Great news for all F# developers, a new .NET Conf is coming up at the end of July with only one topic on the agenda; F# !

.NET Conf: Focus on F# is a free, one-day livestream event that features speakers from the community and Microsoft teams working on and using the F# language. Learn how F# lets you write succinct, performant, and robust code backed by a powerful type system and the .NET runtime you can trust to build mission-critical software.

Hear from language designers and experts using F# in a variety of ways from building minimal web APIs to performing data manipulation, interactive programming, machine learning, and data science.

Tune in here on July 29, ask questions live, and learn about what F# can do.


Thursday, July 15, 2021

Front-End Performance Checklist 2021

For everyone who cares about the performance of their web applications (don’t we all?) this is really, really a must read.

It took me 2 days to go through all the material, links and related articles but boy was it worth it!

I hope that the teams I work with are ready because I will have a long list of questions and remarks coming up!

Let’s make 2021… fast! An annual front-end performance checklist (available as PDF, Apple Pages, MS Word), with everything you need to know to create fast experiences on the web today, from metrics to tooling and front-end techniques.

Wednesday, July 14, 2021

NDepend–Find out where a library is used–Part 2

A few weeks ago I was contacted by Patrick Smacchia, the creator of NDepend, if I would check out the latest edition of their code quality tool. As I had an upcoming software audit assignment planned, I thought it would be a great occasion to see what NDepend brings to the table and how it can help me to improve my understanding of an unfamiliar codebase.

Yesterday I shared how I was able to generate the CQLinq query I needed through the class browser. While writing that post I noticed that NDepend also suggested me to use another feature to get there.

When creating a new query, the editor suggests you to have a look at the code search feature:

So let’s do that today.

I opened Search (View –> Search View).

Let’s see if we can find all Repository objects. I change the ‘Element’ value to ‘Type’ and enter ‘Repository’ in the search field. NDepend picks this up and generates a CQLinq query for me.