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

OK

Kubernetes Versions   

1.19.16 (deprecated, unsupported in 13 days)   

1.20.15   

1.21.10   

1.22.7 (default)   

1.23.4   

1.24.0   


OpenShift Versions   

3.11.570_openshift (deprecated, unsupported in 96 days)   

4.6.48_openshift   

4.7.43_openshift   

4.8.31_openshift (default)   

4.9.21_openshift   

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

1.23.4

which looked OK.

Then I dug deeper: -

echo $my_version | hexdump

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

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                           
0000007

and, better still, my cluster creates OK

No comments:

More fun with pip

Again with the Python and pip  fun, this time on my Mac, where commands such as:  pip3 list and: - pip3 install --upgrade pip were failing w...