kubernetes: strategic patch doesn't keep order of duplicated elements in the list

/kind bug

What happened: given list with duplicated keys D1

mergingList:
 - name: D1
   value: URL1
 - name: A
   value: x
 - name: D1
   value: URL2

and a patch updating non-duplicated key A:

$setElementOrder/mergingList:
 - name: D1
 - name: A
 - name: D1
mergingList:
 - name: A
   value: z

it reorders keys:

mergingList: 
 - name: D1
   value: URL1
 - name: D1
   value: URL2
 - name: A
   value: z

What you expected to happen:

Order of duplicated keys stays the same

mergingList: 
 - name: D1
   value: URL1
 - name: A
   value: z
 - name: D1
   value: URL2

How to reproduce it (as minimally and precisely as possible):

I created test-case which fails on release-1.10 and master: https://github.com/redbaron/kubernetes/commit/971c1b20e51dd2090a9fd585bafa18282c2984f5

Anything else we need to know?:

I am trying to find out why kubectl creates incorrect patch on apply. Although I can’t reproduce it with a simple test case like in this ticket, it look related to it. On a real resource kubectl apply it reorders keys in generated patch, so it generates something like:

$setElementOrder/mergingList:
 - name: D1
 - name: A
 - name: D1
mergingList:
 - name: D1
   value: URL1
 - name: D1
   value: URL2
 - name: A
   value: z

which makes it an invalid patch as order of keys differs from order of values. This reordering might or might not be result of the same underneath bug.

/sig api-machinery

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 3
  • Comments: 40 (30 by maintainers)

Most upvoted comments

If k8s allows pod template to be accepted it should allow pod template to be updated

The likely outcome is to tighten validation to not accept those templates. See https://github.com/kubernetes/kubernetes/pull/64907