-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
virtual/apiexport: serve wildcard apibindings #1563
virtual/apiexport: serve wildcard apibindings #1563
Conversation
aa75aae
to
87b4206
Compare
87b4206
to
beadb4a
Compare
beadb4a
to
85afb43
Compare
85afb43
to
a0911ae
Compare
088814c
to
1adfa3f
Compare
This PR is getting interesting (and it is just an example of more to come): We want to make APIBindings available to the owner of the corresponding APIExport. But the owner can also claim permission on APIBindings. The later shows a superset of bindings (all, not only those belonging to the APIExport addressed by the VW). So the challenging bit: label selectors do not allow disjunction. So we cannot say "show me all bindings for the current export, plus those that are claimed". At the same time, we cannot easily do disjunction on the storage layer in the VW. So this is tricky. What I could imagine: now we set the claim label to: func ToLabelKeyAndValue(permissionClaim apisv1alpha1.PermissionClaim) (string, string, error) {
bytes, err := json.Marshal(permissionClaim)
if err != nil {
return "", "", err
}
hash := fmt.Sprintf("%x", sha256.Sum224(bytes))
labelKeyHashLength := validation.LabelValueMaxLength - len(apisv1alpha1.APIExportPermissionClaimLabelPrefix)
return apisv1alpha1.APIExportPermissionClaimLabelPrefix + hash[0:labelKeyHashLength], hash, nil
} We could change that a little to claimed.internal.apis.kcp.dev/<hash(root:org:ws:export-name)>: <hash(claim)> With that we can express what the APIExport VW needs: Then admission can either set the claim hash, if there is one, or the constant if there isn't and it's a binding against the APIExport. |
1adfa3f
to
2d0514a
Compare
2d0514a
to
8d2ed6a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just have some questions but overall makes sense and looks good
I wonder if a comment explaining what API export/build BuildVirtualWorkspace is doing and what someone should expect in the return may be valuable?
pkg/virtual/apiexport/controllers/apireconciler/apiexport_apireconciler_reconcile.go
Show resolved
Hide resolved
Another question, around the options, is there ever a time when someone would want the APIExport VW but not have the bindings? |
No. With this PR the APIBinding is part of the virtual workspace API contract. You cannot specify and should ne depend on what you cannot see in a VW. |
@shawn-hurley has a point with #1563 (comment). /hold Will turn into a hash after vacation. |
bb710ea
to
8db6aac
Compare
/hold cancel |
8db6aac
to
a89c119
Compare
9dd8890
to
802d071
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
submitting what i have so far so you don't have to wait for them all at the end. will continue reviewing.
// Verify the labels | ||
value, found := apiBinding.Labels[apisv1alpha1.InternalAPIBindingExportLabelKey] | ||
if apiBinding.Spec.Reference.Workspace == nil && found { | ||
return admission.NewForbidden(a, fmt.Errorf("metadata.labels.%s must not be set", apisv1alpha1.InternalAPIBindingExportLabelKey)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the field
helpers (e.g. field.NewInvalid(field.NewPath
- whatever is most appropriate here)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
logicalcluster.New(apiBinding.Spec.Reference.Workspace.Path), | ||
apiBinding.Spec.Reference.Workspace.ExportName, | ||
); value != expected { | ||
return admission.NewForbidden(a, fmt.Errorf("metadata.labels.%s must be set to %q", apisv1alpha1.InternalAPIBindingExportLabelKey, expected)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the field
helpers (e.g. field.NewInvalid(field.NewPath
- whatever is most appropriate here)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/virtual/apiexport/controllers/apireconciler/apiexport_apireconciler_reconcile.go
Show resolved
Hide resolved
6854549
to
82188c9
Compare
Linker killed 🤷♂️ /retest |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ncdc The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Virtual workspaces should make the defining objects of workspaces visible. For APIExports, this is the APIBindings, for initializing workspace this would be the Workspace.
This PR adds the APIBindings (both wildcard requests and normal requests) to the APIExport VW.
It does that by adding a "reflexive claim label" to APIBindings marking the binding visible for the corresponding APIExport. The APIExport VW then can filter via a "IN" label selector, matching either the reflexive label or a real claim label:
This way the APIExport owners will always see "their own" bindings, but are able to claim access to all bindings, overriding the reflexive labels.