https://pulumi.com logo
Title
l

limited-rainbow-51650

06/12/2020, 2:57 PM
In a Pod spec, how should I convert a command with an input pipe like below into the TS counterpart?
command:
  - bash
  - -ec
  - |
      # Execute entrypoint as usual after obtaining ZOO_SERVER_ID based on POD hostname
      HOSTNAME=`hostname -s`
      if [[ $HOSTNAME =~ (.*)-([0-9]+)$ ]]; then
        ORD=${BASH_REMATCH[2]}
        export ZOO_SERVER_ID=$((ORD+1))
      else
        echo "Failed to get index from hostname $HOST"
        exit 1
      fi
      exec /entrypoint.sh /run.sh
g

gorgeous-egg-16927

06/12/2020, 4:13 PM
command
takes list of strings, so you should be able to do something like this:
command: [
  "bash",
  "-ec",
  `|
  #Execute entrypooint...
  `]
Note the backticks on the multiline string
l

limited-rainbow-51650

06/12/2020, 4:20 PM
@gorgeous-egg-16927 I get this in the generated YAML on the cluster:
- |-
          |
          # Execute entrypoint as usual after obtaining ZOO_SERVER_ID based on POD hostname
Where does the first pipe character come from? Here is my code:
const command = 
`|
# Execute entrypoint as usual after obtaining ZOO_SERVER_ID based on POD hostname
HOSTNAME=\`hostname -s\`
if [[ $HOSTNAME =~ (.*)-([0-9]+)$ ]]; then
  ORD=\${BASH_REMATCH[2]}
  export ZOO_SERVER_ID=$((ORD+1))
else
  echo "Failed to get index from hostname $HOST"
  exit 1
fi
exec /entrypoint.sh /run.sh`

...

                            command: [
                                'bash',
                                '-ec',
                                command
                            ],
g

gorgeous-egg-16927

06/12/2020, 4:24 PM
It might have something to do with the backticks around
hostname -s
. Not sure where the extra pipe is coming from
l

limited-rainbow-51650

06/12/2020, 4:25 PM
I escaped correctly within the string. Isn’t the first pipe (
|-
) put there by Pulumi?
g

gorgeous-egg-16927

06/12/2020, 4:26 PM
No, I don’t know of anything in Pulumi that would be doing that
The easiest thing might be to use ConfigFile to apply the YAML, and then see what the Pulumi preview shows