JMESPath conditions for name or namespace are ignored. When a JMESPath condition is used for a label, all labels are ignored. In our setup this resulted in strange sporadic failures where totally different resources from other tests were matched.
Related issue
Fixes #2138
Proposed Changes
The current code uses the getters and setters from Unstructured, i.e.:
temp.SetNamespace(obj.GetNamespace())
temp.SetLabels(obj.GetLabels())
... perform templating on temp
obj.SetNamespace(temp.GetNamespace())
obj.SetLabels(temp.GetLabels())
The problem here is that the Get... methods will return empty values if the values are not strings, and by setting them back to obj the existing structured values are overwritten.
The fix involves two changes:
Instead of using obj.GetLabels(), which returns nil if any label value is not a string, filter all string labels ignoring any other label.
Instead of copying the properties back using the setters, use obj.Object = maps.Merge(obj.Object, merged.UnstructuredContent()) to avoid that structured values will be removed from obj simply because they are absent in the templated object.
…bels
Explanation
JMESPath conditions for name or namespace are ignored. When a JMESPath condition is used for a label, all labels are ignored. In our setup this resulted in strange sporadic failures where totally different resources from other tests were matched.
Related issue
Fixes #2138
Proposed Changes
The current code uses the getters and setters from Unstructured, i.e.:
The problem here is that the
Get...
methods will return empty values if the values are not strings, and by setting them back toobj
the existing structured values are overwritten.The fix involves two changes:
obj.GetLabels()
, which returnsnil
if any label value is not a string, filter allstring
labels ignoring any other label.obj.Object = maps.Merge(obj.Object, merged.UnstructuredContent())
to avoid that structured values will be removed fromobj
simply because they are absent in the templated object.Checklist
Further Comments