Skip to content

'jsonpatch remove operation does not apply' when updating rolebinding #140

@henrjk

Description

@henrjk

The symptom I am seeing is

Patching rolebinding/admin-0 ... failed
2019/10/11 07:17:26 Update aborted: Error from server: jsonpatch remove operation does not apply: doc is missing path: "/groupNames/0"

Excerpt from the tailor update log:

...
~ rolebinding/admin-0 to update
--- Current State (OpenShift cluster)
+++ Desired State (Processed template)
@@ -1,16 +1,14 @@
 apiVersion: authorization.openshift.io/v1
-groupNames:
-- dedicated-admins
-- system:serviceaccounts:dedicated-admin
+groupNames: null
 kind: RoleBinding
 metadata:
   name: admin-0
 roleRef:
   name: admin
 subjects:
-- kind: Group
-  name: dedicated-admins
-- kind: SystemGroup
-  name: system:serviceaccounts:dedicated-admin
-userNames: null
+- kind: ServiceAccount
+  name: jenkins
+  namespace: asap-cd
+userNames:
+- system:serviceaccount:asap-cd:jenkins

...
Apply changes? [y/n]: y

===== Applying changes related to context directory . =====
Creating rolebinding/admin-2 ... done
Creating rolebinding/view-0 ... done
Deleting rolebinding/dedicated-project-admin ... done
Patching rolebinding/admin-0 ... failed
2019/10/11 07:17:26 Update aborted: Error from server: jsonpatch remove operation does not apply: doc is missing path: "/groupNames/0"

After this excerpt from issuing tailor with --diff=json

...
~ rolebinding/admin-0 to update
[
  {
    "op": "replace",
    "path": "/groupNames"
  },
  {
    "op": "remove",
    "path": "/groupNames/0"
  },
  {
    "op": "remove",
    "path": "/groupNames/1"
  },
  {
    "op": "replace",
    "path": "/subjects/0/kind",
    "value": "ServiceAccount"
  },
  {
    "op": "replace",
    "path": "/subjects/0/name",
    "value": "jenkins"
  },
  {
    "op": "add",
    "path": "/subjects/0/namespace",
    "value": "asap-cd"
  },
  {
    "op": "remove",
    "path": "/subjects/1"
  },
  {
    "op": "add",
    "path": "/userNames/0",
    "value": "system:serviceaccount:asap-cd:jenkins"
  }
]
...

Definition of admin-0 in rb.yml

- apiVersion: authorization.openshift.io/v1
  groupNames: null
  kind: RoleBinding
  metadata:
    name: admin-0
  roleRef:
    name: admin
  subjects:
  - kind: ServiceAccount
    name: jenkins
    namespace: asap-cd
  userNames:
  - system:serviceaccount:asap-cd:jenkins

and exported from asap-demo1:

- apiVersion: authorization.openshift.io/v1
  groupNames:
  - dedicated-admins
  - system:serviceaccounts:dedicated-admin
  kind: RoleBinding
  metadata:
    creationTimestamp: null
    name: admin-0
  roleRef:
    name: admin
  subjects:
  - kind: Group
    name: dedicated-admins
  - kind: SystemGroup
    name: system:serviceaccounts:dedicated-admin
  userNames: null

I would guess replace operations need to always have a value.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions