I prepared a job yaml file and deployed it. Job will send post request to grafana api create user method. However it returns error.
error: "curl: (3) URL using bad/illegal format or missing URL"
How Should I change command lines?
yaml file:
apiVersion: batch/v1
kind: Job
metadata:
name: grafanauser-ttl
spec:
ttlSecondsAfterFinished: 100
template:
spec:
containers:
- name: grafanauser
image: curlimages/curl:7.72.0
command:
- '/bin/sh'
- '-ec'
- 'curl -X POST "http://admin:[email protected]/api/admin/users" \
-H "Content-Type:application/json" -d \
"{"name":"test","email":"[email protected]","login":"test","password":"test","OrgId": 1}"'
restartPolicy: OnFailure
CodePudding user response:
Your curl
command isn't properly formated that's why you're seeing this issue. There's a couple of other threads regarding this error message you're receiving from curl.
However a quick fix would be to supply the curl in a single line. The following would work:
---
apiVersion: batch/v1
kind: Job
metadata:
name: grafanauser-ttl
spec:
ttlSecondsAfterFinished: 100
template:
spec:
containers:
- name: grafanauser
image: curlimages/curl:7.72.0
command:
- /bin/sh
- -ec
- 'curl -X POST "http://admin:[email protected]/api/admin/users" -H "Content-Type:application/json" -d "{"name":"test","email":"[email protected]","login":"test","password":"test","OrgId": 1}"'
restartPolicy: OnFailure
I don't have the service running, but you shouldn't receive the curl error anymore:
$ kubectl logs grafanauser-ttl-xjt2q
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: grafana.utility.svc.cluster.local
CodePudding user response:
You shell command line translates to
curl -X POST "http://admin:[email protected]/api/admin/users" -H "Content-Type:application/json" -d "{"name":"test","email":"[email protected]","login":"test","password":"test","OrgId": 1}"
which will make shell strip away all the quotes:
curl -X POST http://admin:[email protected]/api/admin/users -H Content-Type:application/json -d {name:test,email:[email protected],login:test,password:test,OrgId: 1}
and curl will choke on the final 1}
(its last argument)
Try rewriting it using YAML block literal:
command:
- '/bin/sh'
- '-ec'
- |
curl -X POST "http://admin:[email protected]/api/admin/users" \
-H "Content-Type:application/json" -d \
'"{"name":"test","email":"[email protected]","login":"test","password":"test","OrgId": 1}'