this thread is a continuation of "Contribution to Keycloak.X Operator" [3] as Google Groups keeps deleting my responses on that thread.
Our use case: We have multiple Kubernetes clusters which run isolated from each other. Each Kubernetes cluster contains a Keycloak instance with a preconfigured realm. The preconfiguration always happens with an import of an exported realm JSON via CLI if the associated realm does not exist and it happens before actual Keycloak startup. We need this setup across all Kubernetes clusters so we can assure that the Keycloak configuration is the same across all clusters. You can think of Kubernetes clusters which serve a suite of softwares, with the different clusters representing different deployment environments (Test, staging, ...).
Maintaining, reviewing and versioning the exported JSONs in Git is difficult as we need to handle huge realm JSON files. Things like changes in IDs of the entity in the export JSON (which are irrelevant for the import step) bloat the Git diff. It makes working with these JSONs in Git inconvenient. But having these realm settings split in separate resources makes it easier to maintain the configs (=> More CRDs?).
That's why using an operator crossed our minds. We can declaratively define how a Keycloak should be configured without going through the hassle of exporting and re-importing configurations. Changes are kept in sync in one-way (k8s custom resources -> Keycloak), and these custom resources can be shipped as e. g. Helm Chart. This enables deployment approaches such as "GitOps for Keycloak" or Infrastructure-as-a-Code. In a happy day scenario, we just need to deploy a Keycloak instance, the operator and the configs as custom resources. Then, the configuration happens automatically. If there are any updates to the config, the operator simply applies them to the Keycloak entities with nearly no downtime unlike the strategy of exporting the realm as JSON, deleting Keycloak and re-importing it.
I understand why you might refrain from any CRD changes, especially if the new storage system comes around the corner sooner or later and because of the Keycloak configuration method via Admin REST API being prone to breaking changes. I have read in the architecture design documentation that there is a concept of having Keycloak configuration in GitOps style [1]. But I assume it will take some time until the new storage is production-ready. The waiting time stalls the development of Keycloak configuration logic in the new Keycloak.X operator. Please correct me if I get something wrong. In the meantime, we probably have to keep relying on the old operator.
The old operator (Keycloak Realm Operator) can manage clients and users in a one-way-sync-manner. But the way the Realm Operator reconciles realms is very basic: If the realm does not exist, create it. If it does exist, don't do anything, regardless if there are any changes in the custom resources. I wish it would handle realms like clients and users. I bring this up in this GitHub discussion: [2].
I'm open to suggestions for handling such auto-configurations across multiple Kubernetes clusters.
[1]
https://github.com/keycloak/keycloak-community/blob/93a7b6f2185decf5e65a2dce72f80f1d06aae9d4/design/keycloak.x/operator.md#configuring-keycloak-business-objects-using-kubernetes-resources[2]
https://github.com/keycloak/keycloak/discussions/17245#discussion-488926