Skip to content

fix(templates): pass update-parameter to kubectl without eval - #67

Merged
ulucinar merged 3 commits into
crossplane:mainfrom
jcogilvie:fix-eval-arg
Oct 23, 2026
Merged

ulucinar merged 3 commits into
crossplane:mainfrom
jcogilvie:fix-eval-arg

Conversation

@jcogilvie

Copy link
Copy Markdown
Contributor

Description of your changes

Fixes #66.

Since v2.2.0 the update step passed its kubectl command to retry_kubectl "...", which ran it with eval. {{ $resource.UpdateParameter }} was inserted raw inside that double-quoted string, so the " characters in the update-parameter annotation ended the string and kubectl received invalid JSON ({description:x}). Values with spaces failed earlier with Unterminated quoted string.

  • 01-update.yaml.tmpl: retry_kubectl now takes the command as arguments and runs "$@" instead of eval; the patch lines no longer wrap the command in double quotes.
  • All templates: replace the bash-only ((attempt++)) with attempt=$((attempt+1)). Chainsaw runs scripts with sh (dash), where ((attempt++)) fails, so the counter never advanced and the retry loop never reached max_attempts.
  • Add TestUpdateScriptPreservesParameter, which renders the update step, runs the script under sh with a stub kubectl, and asserts the parameter arrives unchanged (including spaces).

Known limitation (unchanged): an update-parameter containing a single quote still breaks the surrounding -p '...'.

I have:

  • Run go test ./internal/templates.

How has this code been tested

Unit tests, including the new script-level test above. Not run against a real cluster.

retry_kubectl ran its command through eval inside a double-quoted string,
so the double quotes in update-parameter were stripped. Run the command
from its arguments instead, and replace the bash-only ((attempt++)) with
POSIX arithmetic so the retry loop terminates under dash.

Fixes crossplane#66

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>
@jcogilvie
jcogilvie marked this pull request as ready for review October 20, 2026 18:55

@ulucinar ulucinar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jcogilvie for fixing the eval issue and the arithmetic command issue. While we are there, for consistency, we may also consider using the similar attempt=$((attempt+1)) in the files under hack:

  • hack/check_endpoints.sh
  • hack/patch-ns.sh
  • hack/patch.sh

Comment thread internal/templates/01-update.yaml.tmpl Outdated
jcogilvie and others added 2 commits October 22, 2026 16:22
Use POSIX arithmetic in the hack scripts and printf for the attempt
message in the update template so escape sequences in the command are
not interpreted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>
@ulucinar
ulucinar merged commit f85cc37 into crossplane:main Oct 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2.2.0: update-parameter annotation is mangled by retry_kubectl quoting

2 participants