kubero-dev / kubero-dev/kubero

Deploy fails for escaped quotes

Open
#710 0 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
4.4k
Forks
213
PR merge metrics
No merged PRs in 30d

Description

### 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 --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_

Contributor guide

Open the contributing guide

Research direction

Search the repository for the generated `kubectl patch kuberoapps` command and inspect the job specification entry point that builds it. Reproduce the Dockerfile deployment flow described in the issue, then verify that the generated patch-file command preserves the repository and tag and that the KuberoApp deploy succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
kubernetes, shell, typescript
Domain
ci-cd, devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.