Skip to content

Commit

Permalink
Fix MarkUnsafe missing Spec in ansible operator (#6376)
Browse files Browse the repository at this point in the history
* ansible: mark spec as unsafe if required

Signed-off-by: Gaël Goinvic <gaelg@element.io>

* ansible: add changelog about markUnsafe bugfix

Signed-off-by: Gaël Goinvic <gaelg@element.io>

* markUnsafe: fix empty array converted to nil

Signed-off-by: Gaël Goinvic <gaelg@element.io>

---------

Signed-off-by: Gaël Goinvic <gaelg@element.io>
  • Loading branch information
gaelgatelement committed Jul 26, 2023
1 parent 7d83efe commit b8a271a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions changelog/fragments/10-mark-unsafe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# entries is a list of entries to include in
# release notes and/or the migration guide
entries:
- description: >
markUnsafe now correctly marks as unsafe the spec extra variable.
# kind is one of:
# - addition
# - change
# - deprecation
# - removal
# - bugfix
kind: "bugfix"
# Is this a breaking change?
breaking: false
# NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS
# FILE FOR A PREVIOUSLY MERGED PULL_REQUEST!
#
# The generator auto-detects the PR number from the commit
# message in which this file was originally added.
#
# What is the pull request number (without the "#")?
# pull_request_override: 0
5 changes: 4 additions & 1 deletion internal/ansible/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ func (r *runner) makeParameters(u *unstructured.Unstructured) map[string]interfa

specKey := fmt.Sprintf("%s_spec", objKey)
parameters[specKey] = spec
if r.markUnsafe {
parameters[specKey] = markUnsafe(spec)
}

for k, v := range r.Vars {
parameters[k] = v
Expand All @@ -391,7 +394,7 @@ func (r *runner) makeParameters(u *unstructured.Unstructured) map[string]interfa
func markUnsafe(values interface{}) interface{} {
switch v := values.(type) {
case []interface{}:
var p []interface{}
p := make([]interface{}, 0)
for _, n := range v {
p = append(p, markUnsafe(n))
}
Expand Down

0 comments on commit b8a271a

Please sign in to comment.