-1

Trying to write an sh script with several oc patch commands and need to parametrize several values. Now script looks like:

oc patch svc svc-ingressgateway --type='json' -p='[{"op": "add", "path": "/spec/ports/-", "value": {"name": "http-8080","port": 8080} }]'
oc patch vs vs-ingressgateway --type='json' -p='[{"op": "add", "path": "/spec/hosts/-", "value": "ingress-http-host.smth.com" }]'
oc patch gw gw-ingressgateway --type='json' -p='[{"op": "add", "path": "/spec/servers/-", "value": { "hosts": ["ingress-http-host.smth.com"], "port": {"name":"http-8080", "number":8080,"protocol":"HTTP"} } }]'

Trying to do smth like this:

HTTP_HOST='ingress-http-host.smth.com'
HTTP_PORT='8080'
oc patch svc svc-ingressgateway --type='json' -p='[{"op": "add", "path": "/spec/ports/-", "value": {"name": "http-${HTTP_PORT}","port": ${HTTP_PORT}} }]'
oc patch vs vs-ingressgateway --type='json' -p='[{"op": "add", "path": "/spec/hosts/-", "value": ${HTTP_HOST} }]'
oc patch gw gw-ingressgateway --type='json' -p='[{"op": "add", "path": "/spec/servers/-", "value": { "hosts": [${HTTP_HOST}], "port": {"name":"http-${HTTP_PORT}", "number":${HTTP_PORT},"protocol":"HTTP"} } }]'

but this is wrong, obviously, because the error appears:

Error from server: admission webhook "pilot.validation.istio.io" denied the request: configuration is invalid: domain name "$HTTP_HOST" invalid (label "$HTTP_HOST" invalid) Error from server: admission webhook "pilot.validation.istio.io" denied the request: configuration is invalid: 2 errors occurred: * short names (non FQDN) are not allowed * domain name "$HTTP_HOST" invalid (label "$HTTP_HOST" invalid)

Please, help, if you know how to do such things

  • did you try to run your script line by line to see from which line you get the exception? – OHY Apr 15 '21 at 16:39

1 Answers1

2

The error appears because the shell parameter expansion of ${HTTP_PORT} and ${HTTP_HOST} is not done within single quotes. A way to fix this is ending the quotation just before and beginning a new one just after the parameter expansion. Besides, the braces are unneeded in this case. So, you can effectively replace ${HTTP_....} with '$HTTP_....'

Armali
  • 18,255
  • 14
  • 57
  • 171