Built-in Registry
Package registry exports every built-in handler and lowering rule launcher implements,
keyed by the type each one registers under, so a consumer registers the builtins from the
library instead of keeping its own list. kurel build registers exactly these
(pkg/cmd/kurel, newBuiltinTransformer).
| Function | Holds | Register with |
|---|---|---|
ComponentHandlers() | every kind component of pkg/oam/builtin/components | oam.NewTransformer or RegisterComponent |
ComponentLoweringRules() | webservice, worker, helm, postgresql, oci, and the higher-level types of the derived-defaults table: tls-certificate and hardened-deployment, hardened-statefulset, hardened-daemonset, hardened-job, hardened-cronjob | RegisterBuiltinComponentLowering |
TraitHandlers() | every trait of pkg/oam/builtin/traits | RegisterBuiltinTrait |
TraitLoweringRules() | expose | RegisterBuiltinTraitLowering |
PolicyHandlers() | dependency, placement | RegisterPolicy |
ComponentTypeIDs(), TraitTypeIDs(), PolicyTypeIDs() | the identity of every type in the maps above | DeclareTypes |
Each function returns a new map on every call: a caller may delete, replace or add
entries, and the change reaches no other caller. A type launcher adds later appears in the
map of its kind without a change on the caller’s side. Adding one takes two lines in one
commit: its entry in registry.go, at its position in the order sort.Strings gives the
types (prometheus before prometheus-probe, which it prefixes), and its line in kurel’s
testdata/builtin-registries.txt. The table names the maps, not the types: the kind
components themselves, each with what it emits and refuses, are listed in
pkg/oam/builtin/components,
so a new kind changes nothing here but those two lines. A trait is the same: disruption,
the PodDisruptionBudget trait (admitted on webservice, worker, deployment and
statefulset), is one entry in TraitHandlers() and one line in the testdata file, and so is
monitoring, the VictoriaMetrics scrape and rule trait (admitted on webservice and worker).
A type that is a lowering rule is never also a handler of the same position, and
RegisterComponentLowering and RegisterTraitLowering panic on that collision. A consumer
that replaces a handler sets its own under the same key; one that replaces a lowered type
(say webservice) with a handler deletes the type from the lowering-rule map.
ComponentHandlers holds every kind whatever Kubernetes version a cluster runs. The
validatingadmissionpolicy and validatingadmissionpolicybinding kinds are served from
Kubernetes 1.30, and mutatingadmissionpolicy and mutatingadmissionpolicybinding from
1.36. The build does not check the version, so a cluster below it refuses the object at
apply. A consumer that targets such a cluster and wants the refusal at build deletes those
keys from the map.
launcher has no handler for the app-dependency, reconciliation and health-checks
policies or the fluxcd-patches and fluxcd-postbuild traits, so none of the maps holds
them: a consumer that implements them registers its own.
See “Registering the builtins” in pkg/oam
for the registration sequence.
Type identity
Every built-in type has one identity, held by ComponentTypeIDs(), TraitTypeIDs() and
PolicyTypeIDs(), each keyed by the type’s plain name. A type named for its one Kubernetes
kind has the identity kind.group@<API version>: deployment is deployment.apps@v1, and
a core kind has no group (configmap@v1); mariadb is mariadb.k8s.mariadb.com@v1alpha1
(go-kure/launcher#1819), the other four kinds of that API being named for the product. Every other type is
<name>.launcher.gokure.dev@v1, with the domain held in LauncherDomain. That includes
role-deployment, the member type webservice and worker lower into since
go-kure/launcher#1629: it is registered because lowering needs a handler for every member
type, and a document is not meant to author it. The identity deployment.apps@v1 belongs
to the raw deployment kind.
A higher-level type over a kind takes a role name, so tls-certificate is
tls-certificate.launcher.gokure.dev@v1 and the kind keeps certificate.cert-manager.io@v1 and
its short name certificate. After DeclareTypes, Transformer.TypeCatalog() lists every type with
its qualified name (qualifiedName) and, for a component type, its level: base-kind for a
handler and higher-level-model for a lowering rule (oam.ContractMetadata.Level). A client shows
both, so two types that read alike are told apart.
DeclareTypes(t) declares all three maps on a transformer. Call it after the registration
sequence, so every type it names is registered. It returns an error when two types claim one
identity. A document may then author a type as name@version, and the transformer resolves
it to the registered type; the grammar and the resolution rule are in
pkg/oam.
DeclareTypes also marks trusted (Transformer.MarkScopeTrusted) the kind scope of each built-in
component handler that declares one (oam.KindScopeDeclarer), as the five mariadb-operator
kinds do. kure’s scope table holds those kinds too, and the object kind check reads kure’s scope
for a kind kure registers, so the mark changes nothing for them (go-kure/launcher#1868).
Tests
TestRegistries_FreshMapEachCall: a caller’s change to one call’s map does not show in the next call’s.TestRegistries_LoweringRulesClaimTheirKey: each lowering rule is keyed under the type it claims.TestRegistries_RegisterTogether: every entry registers on one transformer without a collision.TestBuiltinDescriptionsCarryNoIssueNumber: no description of a built-in component, trait or policy property names an issue (#and two or more digits), so a consumer that publishes the descriptions never shows a number;TestBuiltinDescriptionWalk_ReachesEveryDescriptionholds the walk to the count of descriptions in each schema’s JSON.- In
pkg/cmd/kurel,TestKindLists_InOrderholds the entries ofComponentHandlersin the order of their type,TestBuiltinRegistries_TypesUnchangedholds kurel’s registered set totestdata/builtin-registries.txt, and the handler-schema tests cover every entry.