Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Send annotation value via temp file
Browse files Browse the repository at this point in the history
It can contain shell characters such as single quote and !, so put
the contents in a file before calling `kubectl annotate`.

Interestingly there is no option in `kubectl` to take the value from
a file, so we still have to `cat` it on the command-line.
  • Loading branch information
bboreham committed Oct 19, 2020
1 parent 9269d80 commit 686821f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/plan/resource/kubectl_annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ func (ka *KubectlAnnotateSingleNode) Apply(ctx context.Context, runner plan.Runn
return false, fmt.Errorf("unexpected output in node name: %q", output)
}

cmd := fmt.Sprintf("kubectl annotate %q %s=%q", nodeName, ka.Key, ka.Value)
path, err := writeTempFile(ctx, runner, []byte(ka.Value), "node_annotation")
if err != nil {
return false, errors.Wrap(err, "writeTempFile")
}
//nolint:errcheck
defer runner.RunCommand(ctx, fmt.Sprintf("rm -vf %q", path), nil)

cmd := fmt.Sprintf("kubectl annotate %q %s=$(cat %s)", nodeName, ka.Key, path)

if stdouterr, err := runner.RunCommand(ctx, resource.WithoutProxy(cmd), nil); err != nil {
return false, errors.Wrapf(err, "failed to apply annotation %s on %s; output %s", ka.Key, nodeName, stdouterr)
Expand Down

0 comments on commit 686821f

Please sign in to comment.