Skip to content

Commit

Permalink
Merge pull request #2175 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2174-to-release-0.9

[release-0.9] 🐛 Fix permissionclaim patch thrashing
  • Loading branch information
openshift-merge-robot committed Oct 11, 2022
2 parents 616e12e + 7a02b74 commit ea9ba5c
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 3 deletions.
11 changes: 11 additions & 0 deletions config/crds/apis.kcp.dev_apibindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ spec:
records if the user accepts or rejects it.
properties:
group:
default: ""
description: group is the name of an API group. For core groups
this is the empty string '""'.
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$
Expand Down Expand Up @@ -125,6 +126,7 @@ spec:
allow the service provider access to.
properties:
group:
default: ""
description: group is the name of an API group. For core groups
this is the empty string '""'.
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$
Expand All @@ -146,6 +148,10 @@ spec:
- resource
type: object
type: array
x-kubernetes-list-map-keys:
- group
- resource
x-kubernetes-list-type: map
boundExport:
description: "boundExport records the export this binding is bound
to currently. It can differ from the export that was specified in
Expand Down Expand Up @@ -291,6 +297,7 @@ spec:
allow the service provider access to.
properties:
group:
default: ""
description: group is the name of an API group. For core groups
this is the empty string '""'.
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$
Expand All @@ -312,6 +319,10 @@ spec:
- resource
type: object
type: array
x-kubernetes-list-map-keys:
- group
- resource
x-kubernetes-list-type: map
phase:
description: 'phase is the current phase of the APIBinding: - "":
the APIBinding has just been created, waiting to be bound. - Binding:
Expand Down
1 change: 1 addition & 0 deletions config/crds/workload.kcp.dev_synctargets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ spec:
items:
properties:
group:
default: ""
description: group is the name of an API group. For core groups
this is the empty string '""'.
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$
Expand Down
2 changes: 1 addition & 1 deletion config/root-phase0/apiexport-workload.kcp.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ metadata:
name: workload.kcp.dev
spec:
latestResourceSchemas:
- v220923-836dfac8.synctargets.workload.kcp.dev
- v221011-1af9d713.synctargets.workload.kcp.dev
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apis.kcp.dev/v1alpha1
kind: APIResourceSchema
metadata:
creationTimestamp: null
name: v220923-836dfac8.synctargets.workload.kcp.dev
name: v221011-1af9d713.synctargets.workload.kcp.dev
spec:
group: workload.kcp.dev
names:
Expand Down Expand Up @@ -189,6 +189,7 @@ spec:
items:
properties:
group:
default: ""
description: group is the name of an API group. For core groups
this is the empty string '""'.
pattern: ^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/apis/v1alpha1/types_apibinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,17 @@ type APIBindingStatus struct {
// state in spec.permissionClaims.
//
// +optional
// +listType=map
// +listMapKey=group
// +listMapKey=resource
AppliedPermissionClaims []PermissionClaim `json:"appliedPermissionClaims,omitempty"`

// exportPermissionClaims records the permissions that the export provider is asking for
// the binding to grant.
// +optional
// +listType=map
// +listMapKey=group
// +listMapKey=resource
ExportPermissionClaims []PermissionClaim `json:"exportPermissionClaims,omitempty"`
}

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/apis/v1alpha1/types_apiexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ type GroupResource struct {
//
// +kubebuilder:validation:Pattern=`^(|[a-z0-9]([-a-z0-9]*[a-z0-9](\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?)$`
// +optional
// +kubebuilder:default=""
Group string `json:"group,omitempty"`

// resource is the name of the resource.
Expand Down
18 changes: 18 additions & 0 deletions pkg/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ func (c *controller) reconcile(ctx context.Context, apiBinding *apisv1alpha1.API
}

logger := logging.WithObject(logger, u)

if gvr == apisv1alpha1.SchemeGroupVersion.WithResource("apibindings") && logicalcluster.From(u) == clusterName && u.GetName() == apiBinding.Name {
// Don't issue a generic patch when obj == the APIBinding being reconciled. That will be covered when
// this call to reconcile exits and the controller patches this APIBinding. Otherwise, the generic patch
// here will conflict with the controller's attempt to update the APIBinding's status.
continue
}

logger.V(4).Info("patching to get claim labels updated")

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

fullyApplied := expectedClaims.Difference(applyErrors)
apiBinding.Status.AppliedPermissionClaims = []apisv1alpha1.PermissionClaim{}
for _, s := range fullyApplied.UnsortedList() {
for _, s := range fullyApplied.List() {
claim := claimFromSetKey(s)
apiBinding.Status.AppliedPermissionClaims = append(apiBinding.Status.AppliedPermissionClaims, claim)
}
Expand Down

0 comments on commit ea9ba5c

Please sign in to comment.