implement resources API part 2#17749
Open
aalves08 wants to merge 1 commit into
Open
Conversation
…ersistentvolume list view (to be deleted)
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #16898
Implements Resources API Part 2: create, update, patch, and delete operations at both the
ResourcesApilevel (resources.cluster.*/resources.mgmt.*) and theResourceInstanceApilevel (resourceInstance.*).NOTE: demo interaction with
persistentvolumelist view to test (to be deleted in the end)Occurred changes and/or fixed issues
New write operations added to the Resources API:
resources.cluster.create(data)canCreateresources.cluster.patch(type, id, data)resources.cluster.update(type, id, data)resources.cluster.delete(type, id)resourceInstance.patch(data)canEditresourceInstance.update()canEditresourceInstance.delete()canDeleteAll methods are available on both
clusterandmgmtscopes (ClusterApiandMgmtApiare type aliases toResourcesApi).Existing read operations (
find,findAll,findFiltered) now wrap results inResourceInstanceImpl, so every resource returned by the API haspatch(),update(), anddelete()available out of the box.Technical notes summary
ResourceInstanceImplwrapping: All resources returned from the API (find, findAll, findFiltered, create) are now wrapped inResourceInstanceImpl. This provides the instance-level methods (patch, update, delete) on every returned resource._modelis non-enumerable: The underlying store model reference is stored viaObject.definePropertywithenumerable: false. This preventsstructuredCloneandJSON.stringifyfrom attempting to serialize store internals (functions, dispatch refs, circular references), which is critical for Vue 3 reactive compatibility.declarekeyword for_model: Usesdeclare _model: anyinstead of a class field initializer to avoid TypeScript emitting a runtime assignment that would override the non-enumerableObject.definePropertyset in the constructor.invalidatePageCache: false: TheresourceInstance.patch()method explicitly passesinvalidatePageCache: falsewhen dispatchingloadafter a successful patch. Without this, the store mutation defaultsinvalidatePageCachetotrue, which clears paginated list data and causes resources to disappear from list views.toJSONfallback:ResourceInstanceImpl.toJSON()defensively checks for_model.toJSONbefore calling it, falling back to a shallow spread. This prevents errors when the model lacks atoJSONmethod (e.g. in test mocks).resourceUrlhelper: A new private method onResourcesApiClassImplbuilds resource URLs fromschema.linkFor('collection') + '/' + resourceId. It reuses the existingisNamespaced()validation to enforcenamespace/nameformat for namespaced resources.CreateResourceDatatype: New type exported from the barrel —{ type: ResourceType } & Record<string, any>— enforces the mandatorytypeproperty on create data.delete()added alongsideremove():remove()is kept for backward compatibility.delete()is the new public method that adds RBAC checking before delegating tomodel.remove().Areas or cases that should be tested
resources.cluster.create()with valid data, verify permission denial whencanCreateis falseresources.cluster.patch()sends only partial data withapplication/merge-patch+jsoncontent type, verify namespace validationresourceInstance.patch()checkscanEdit, sends partial data, merges response back into the instance, and does not invalidate paginated list viewsresources.cluster.update()runscleanForSaveand sends full data with PUTresourceInstance.update()checkscanEditand delegates tomodel.save()resources.cluster.delete()sends DELETE request with correct URLresourceInstance.delete()checkscanDeleteand delegates tomodel.remove()resources.mgmt.*Areas which could experience regressions
findFiltered/findPage): TheResourceInstanceImplwrapping infindFilterednow maps over both array results and transient.dataarrays. Verify paginated lists still render correctly.find/findAllconsumers: Any code that usestoStrictEqualorinstanceofchecks against raw store models will seeResourceInstanceImplinstances instead. Property access is unchanged since getters proxy through to the model.ResourceInstanceApi: The interface now exposespatch(),update(), anddelete()— no breaking changes, but extensions get new methods in IntelliSense._modelnon-enumerable change should be transparent, but verify that resource data remains reactive when stored in Vue component state.Screenshot/Video
N/A — API-only changes with no UI modifications.
Checklist
Admin,Standard UserandUser Base