Skip to content

Commit b8a271a

Browse files
Fix MarkUnsafe missing Spec in ansible operator (#6376)
* ansible: mark spec as unsafe if required Signed-off-by: Gaël Goinvic <[email protected]> * ansible: add changelog about markUnsafe bugfix Signed-off-by: Gaël Goinvic <[email protected]> * markUnsafe: fix empty array converted to nil Signed-off-by: Gaël Goinvic <[email protected]> --------- Signed-off-by: Gaël Goinvic <[email protected]>
1 parent 7d83efe commit b8a271a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# entries is a list of entries to include in
2+
# release notes and/or the migration guide
3+
entries:
4+
- description: >
5+
markUnsafe now correctly marks as unsafe the spec extra variable.
6+
7+
# kind is one of:
8+
# - addition
9+
# - change
10+
# - deprecation
11+
# - removal
12+
# - bugfix
13+
kind: "bugfix"
14+
15+
# Is this a breaking change?
16+
breaking: false
17+
18+
# NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS
19+
# FILE FOR A PREVIOUSLY MERGED PULL_REQUEST!
20+
#
21+
# The generator auto-detects the PR number from the commit
22+
# message in which this file was originally added.
23+
#
24+
# What is the pull request number (without the "#")?
25+
# pull_request_override: 0

internal/ansible/runner/runner.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ func (r *runner) makeParameters(u *unstructured.Unstructured) map[string]interfa
366366

367367
specKey := fmt.Sprintf("%s_spec", objKey)
368368
parameters[specKey] = spec
369+
if r.markUnsafe {
370+
parameters[specKey] = markUnsafe(spec)
371+
}
369372

370373
for k, v := range r.Vars {
371374
parameters[k] = v
@@ -391,7 +394,7 @@ func (r *runner) makeParameters(u *unstructured.Unstructured) map[string]interfa
391394
func markUnsafe(values interface{}) interface{} {
392395
switch v := values.(type) {
393396
case []interface{}:
394-
var p []interface{}
397+
p := make([]interface{}, 0)
395398
for _, n := range v {
396399
p = append(p, markUnsafe(n))
397400
}

0 commit comments

Comments
 (0)