Home > Back-end >  Bash during k8s init container cannot understand bash
Bash during k8s init container cannot understand bash

Time:07-15

Hi looking for some help in explaining what this line is doing. I am completely lost in what it is saying. I know it is exiting there because I can see my log line 25 but NOT log line 27.

[[ `hostname` =~ -([0-9] )$ ]] || exit 1
      initContainers:
      - name: init-mysql
        image: mysql:5.7
        command:
        - bash
        - "-c"
        - |
          set -ex
          # Generate mysql server-id from pod ordinal index.
          echo "Running line25" >> /var/lib/mysql/temp.log
          [[ `hostname` =~ -([0-9] )$ ]] || exit 1
          echo "Running line27" >> /var/lib/mysql/temp.log

CodePudding user response:

It runs the hostname command, and then compares its output to the regular expression -([0-9] )$. The parentheses are redundant, so it could be simplified to -[0-9] $; this is "a string that ends with - and 1 or more digits".

If the output of hostname doesn't match the expression, exit 1 is called. You can look at the output of hostname separately to see its value.

  • Related