Tuesday 1 March 2022

Fun with variables and space

Whilst doing some work with IBM Kubernetes Service (IKS), I wanted to define an environment variable containing a specific version of Kubernetes.

Having checked what's available: -

ic cs versions


Kubernetes Versions   

1.19.16 (deprecated, unsupported in 13 days)   



1.22.7 (default)   



OpenShift Versions   

3.11.570_openshift (deprecated, unsupported in 96 days)   



4.8.31_openshift (default)   


To assess the differences across versions, see 'https://ibm.biz/iks-versions'.

I was specifically interested in 1.23.4.

Reflecting the fact that the patch version ( .4 ) may well increment, I chose to define my variable thusly: -

export my_version=$(ic cs versions | grep 1.23)

which should mean that my variable contains 1.23.4 or, when it increments, 1.23.5 or 1.23.6 etc.

However, when I created my cluster using the IBM Cloud CLI via: -

ic cs cluster create vpc-gen2 ...

I saw: -

The requested container platform version is not available or not valid. (E0035)

I double-checked my variable: -

echo $my_version


which looked OK.

Then I dug deeper: -

echo $my_version | hexdump

0000000 31 2e 32 33 2e 34 20 20 20 0a

noting the additional 0x20 characters.

So, in other words, the command: -

ic cs versions | grep 1.23

is returning a couple of extra space characters.

This was easily fixed: -

export my_version=$(ic cs versions | grep 1.23 | sed 's: ::g')

which looks much better: -

echo $my_version | hexdump

0000000 31 2e 32 33 2e 34 0a                           

and, better still, my cluster creates OK

No comments:

Visual Studio Code - Wow 🙀

Why did I not know that I can merely hit [cmd] [p]  to bring up a search box allowing me to search my project e.g. a repo cloned from GitHub...