ITADN

Deploy fails for escaped quotes

#710Openoleva 创建于 2025-11-13
bug
O
olevacommented
### Which component(s) is affected? _No response_ ### Describe the bug Kubero operator generates a deploy command with escaped quotes that fail in shell: `sh -c "kubectl patch kuberoapps $APP --type=merge -p \"{\"spec\":{\"image\":{\"repository\": \"$REPOSITORY\",\"tag\": \"$TAG\"}}}\""` When sh -c executes this, the escaped quotes \" inside the double-quoted string are misinterpreted, causing malformed JSON. Causing: Error from server (BadRequest): error decoding patch: invalid character 's' looking for beginning of object key string Fix: Use `--patch-file` instead of inline JSON patch. ### Steps to reproduce 1. Install Kubero on Upcloud 2. Link to Docker repo 3. Try to deploy with Source code -> Docker file buildstrategy: dockerfile deploymentstrategy: git autodeploy: true ### Expected behavior The deploy step should successfully patch the KuberoApp resource with the new image repository and tag. -> Build and deployed application ### Screenshots _No response_ ### Additional information When Kubero creates a build job for GitOps deployment, the deploy container uses an inline JSON patch command that fails due to shell quoting issues: Actual command generated by Kubero (from job spec): ``` json { "command": [ "sh", "-c", "kubectl patch kuberoapps $APP --type=merge -p \"{\"spec\":{\"image\":{\"repository\": \"$REPOSITORY\",\"tag\": \"$TAG\"}}}\"" ] } ``` The escaped quotes `\"` inside the double-quoted string in `sh -c` are not properly handled. When executed, the shell misinterprets the JSON structure, resulting in malformed JSON being sent to the Kubernetes API. **Suggested Fix** Replace the inline JSON patch with `--patch-file` approach: **Current (broken):** ```bash sh -c "kubectl patch kuberoapps $APP --type=merge -p \"{\"spec\":{\"image\":{\"repository\": \"$REPOSITORY\",\"tag\": \"$TAG\"}}}\"" ``` **Suggested fix:** ```bash sh -c "printf '{\"spec\":{\"image\":{\"repository\":\"%s\",\"tag\":\"%s\"}}}' \"\$REPOSITORY\" \"\$TAG\" > /tmp/patch.json && kubectl patch kuberoapps \"\$APP\" -n <NAME> --type=merge --patch-file /tmp/patch.json" ``` **patch.json file containing:** The `printf` command generates a JSON file with the following structure (example values): ```json { "spec": { "image": { "repository": "registry.example.com", "tag": "main-EXAMPLE-1763035897983-20251113-1211" } } } ``` ### Debug information _No response_
0 条评论