Repository navigation
API Default Values Principles #38551
Replies: 2 comments 2 replies
|
A follow-up discussion around defaults is at #39547. |
Updated Defaults proposalDefaults will be in the end persisted. The reasoning is:
ConsThe most prominent downside of persisting defaults is it would not be possible to GET a resource without the defaults (as it was suggested by the former design proposal). This mostly affects the declarative/reconciling scenarios where the client wants to compare the actual and desired state. However, we believe this is not strictly necessary. The client can simply do PUT rightaway (instead of doing GET and the comparison before that). This assumes that if a resource is declaratively managed, there's only a single actor for a given resource instance. In other words, if e.g. a Client is managed via an Operator CR, it won't be possible to mutate it via other actors like Admin UI. This will be enforced via Fine Grained permissions. Another affected area is user UX. It is very confusing (especially in the CLI scenarios) that when a resource is created only with a handful of fields, it suddenly has many more fields due to the defaults after it's created. This might be solved though, e.g. by tracking the default fields so that they are excluded when doing GET. However, this adds some complexity and considering the limited scenarios that would benefit from it, it doesn't seem really worth it. See the discussion in #39547 for more context. |
Uh oh!
There was an error while loading. Please reload this page.
Summary
This discussion thread provides options and discusses the advantages and trade-offs of providing default values for the v2 Admin APIs.
The following design assumptions have been taken into consideration for this proposal:
Proposed API Behavior
This proposal introduces two modes for each resource for HTTP GET: "Requested," which returns exactly what was sent by the POST, and "Runtime," which represents the resource used by the Keycloak runtime. A new query parameter (
runtime=true) will be introduced to the APIs to obtain the latter.Let's consider a very simplistic Client API example. For the sake of this example, let's assume it consists of only two fields:
client_id, which must be supplied by the client, andprotocol, which defaults to"openid-connect"if not supplied. Here's how the API would behave:HTTP POST:
HTTP GET:
HTTP PUT:
Ephemeral Default Values
Default values might either be persisted in the resource model or remain ephemeral.
The obvious advantage of persisting default values is its simplicity in handling migrations. Once a client is created via the API, corresponding default values are pulled and persisted in the model, making it ready to use. The main trade-off is that if a default value gets updated later, none of the existing clients will receive the new value.
On the other hand, ephemeral default values are pulled every time the client is manipulated by the API or used by Keycloak runtime. The main advantage here is design simplicity, but the trade-off lies in maintaining backward compatibility.
After a discussion tracked here, we decided to pursue ephemeral default values.
Alternatives Considered
When working on this proposal, the working group considered several different approaches. Some of them are outlined below:
specandstatus.References
https://docs.google.com/document/d/1UUGeudHOalWTHX31vvTi8-PPpzOXxRQb0pSUR8eetEA/edit?tab=t.0#heading=h.2r8egkh457sa
All reactions