Skip to content

Commit ea9ba5c

Browse files
Merge pull request #2175 from openshift-cherrypick-robot/cherry-pick-2174-to-release-0.9
[release-0.9] 🐛 Fix permissionclaim patch thrashing
2 parents 616e12e + 7a02b74 commit ea9ba5c

8 files changed

+49
-3
lines changed

config/crds/apis.kcp.dev_apibindings.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ spec:
5353
records if the user accepts or rejects it.
5454
properties:
5555
group:
56+
default: ""
5657
description: group is the name of an API group. For core groups
5758
this is the empty string '""'.
5859
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$
@@ -125,6 +126,7 @@ spec:
125126
allow the service provider access to.
126127
properties:
127128
group:
129+
default: ""
128130
description: group is the name of an API group. For core groups
129131
this is the empty string '""'.
130132
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$
@@ -146,6 +148,10 @@ spec:
146148
- resource
147149
type: object
148150
type: array
151+
x-kubernetes-list-map-keys:
152+
- group
153+
- resource
154+
x-kubernetes-list-type: map
149155
boundExport:
150156
description: "boundExport records the export this binding is bound
151157
to currently. It can differ from the export that was specified in
@@ -291,6 +297,7 @@ spec:
291297
allow the service provider access to.
292298
properties:
293299
group:
300+
default: ""
294301
description: group is the name of an API group. For core groups
295302
this is the empty string '""'.
296303
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$
@@ -312,6 +319,10 @@ spec:
312319
- resource
313320
type: object
314321
type: array
322+
x-kubernetes-list-map-keys:
323+
- group
324+
- resource
325+
x-kubernetes-list-type: map
315326
phase:
316327
description: 'phase is the current phase of the APIBinding: - "":
317328
the APIBinding has just been created, waiting to be bound. - Binding:

config/crds/workload.kcp.dev_synctargets.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ spec:
195195
items:
196196
properties:
197197
group:
198+
default: ""
198199
description: group is the name of an API group. For core groups
199200
this is the empty string '""'.
200201
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$

config/root-phase0/apiexport-workload.kcp.dev.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ metadata:
55
name: workload.kcp.dev
66
spec:
77
latestResourceSchemas:
8-
- v220923-836dfac8.synctargets.workload.kcp.dev
8+
- v221011-1af9d713.synctargets.workload.kcp.dev
99
status: {}

config/root-phase0/apiresourceschema-synctargets.workload.kcp.dev.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: apis.kcp.dev/v1alpha1
22
kind: APIResourceSchema
33
metadata:
44
creationTimestamp: null
5-
name: v220923-836dfac8.synctargets.workload.kcp.dev
5+
name: v221011-1af9d713.synctargets.workload.kcp.dev
66
spec:
77
group: workload.kcp.dev
88
names:
@@ -189,6 +189,7 @@ spec:
189189
items:
190190
properties:
191191
group:
192+
default: ""
192193
description: group is the name of an API group. For core groups
193194
this is the empty string '""'.
194195
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$

pkg/apis/apis/v1alpha1/types_apibinding.go

+6
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,17 @@ type APIBindingStatus struct {
174174
// state in spec.permissionClaims.
175175
//
176176
// +optional
177+
// +listType=map
178+
// +listMapKey=group
179+
// +listMapKey=resource
177180
AppliedPermissionClaims []PermissionClaim `json:"appliedPermissionClaims,omitempty"`
178181

179182
// exportPermissionClaims records the permissions that the export provider is asking for
180183
// the binding to grant.
181184
// +optional
185+
// +listType=map
186+
// +listMapKey=group
187+
// +listMapKey=resource
182188
ExportPermissionClaims []PermissionClaim `json:"exportPermissionClaims,omitempty"`
183189
}
184190

pkg/apis/apis/v1alpha1/types_apiexport.go

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ type GroupResource struct {
220220
//
221221
// +kubebuilder:validation:Pattern=`^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$`
222222
// +optional
223+
// +kubebuilder:default=""
223224
Group string `json:"group,omitempty"`
224225

225226
// resource is the name of the resource.

pkg/openapi/zz_generated.openapi.go

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/reconciler/apis/permissionclaimlabel/permissionclaimlabel_reconcile.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ func (c *controller) reconcile(ctx context.Context, apiBinding *apisv1alpha1.API
132132
}
133133

134134
logger := logging.WithObject(logger, u)
135+
136+
if gvr == apisv1alpha1.SchemeGroupVersion.WithResource("apibindings") && logicalcluster.From(u) == clusterName && u.GetName() == apiBinding.Name {
137+
// Don't issue a generic patch when obj == the APIBinding being reconciled. That will be covered when
138+
// this call to reconcile exits and the controller patches this APIBinding. Otherwise, the generic patch
139+
// here will conflict with the controller's attempt to update the APIBinding's status.
140+
continue
141+
}
142+
135143
logger.V(4).Info("patching to get claim labels updated")
136144

137145
// Empty patch, allowing the admission plugin to update the resource to the correct labels
@@ -180,7 +188,7 @@ func (c *controller) reconcile(ctx context.Context, apiBinding *apisv1alpha1.API
180188

181189
fullyApplied := expectedClaims.Difference(applyErrors)
182190
apiBinding.Status.AppliedPermissionClaims = []apisv1alpha1.PermissionClaim{}
183-
for _, s := range fullyApplied.UnsortedList() {
191+
for _, s := range fullyApplied.List() {
184192
claim := claimFromSetKey(s)
185193
apiBinding.Status.AppliedPermissionClaims = append(apiBinding.Status.AppliedPermissionClaims, claim)
186194
}

0 commit comments

Comments
 (0)