Operator runtime is a library to build kubernetes operators which adhere to Dsoi-Spec. This library provides high level abstractions and standardisation to focus on building robust reconcile loops for data application with multiple node types. Operator's built using operator runtime
- At DataInfra, we are building cloud native data infrastructure toolings to power self served data platforms, we build a lot of kubernetes operator's for distributed systems. Building reconcile loops for different nodetypes/components is extremely time consuming, error prone and becomes repetitive for mulitple applications. There arn't any useful abstractions which can be consumed by the reconcilation loops, while building operator's we wanted to focus on application building blocks, using the operator runtime we abstracted out the underlying k8s object reconcilation internals.
Using this library we introduce standardisation across
1. Builder Abstractions to build kubernetes objects and reconcile.
2. Triggering Reconcilation on state changes using hashes.
3. Building an internal store for reducing k8s API calls.
4. Event Emitters
- This library abstracts out controller runtime
client.Client
by wrapping it with CRUD methods and inbuilt event recorders. - To build objects initalise the
Builder
and leverage theReconcileInterface
to reconcile objects.
- Operator builder exposes k8s objects, these objects can be built and passed to the NewBuilder. Example:
// construct builder
builder := builder.NewBuilder(
builder.ToNewBuilderConfigMap(pinotConfigMap),
builder.ToNewBuilderDeploymentStatefulSet(pinotDeploymentOrStatefulset),
builder.ToNewBuilderStorageConfig(pinotStorage),
builder.ToNewBuilderRecorder(builder.BuilderRecorder{Recorder: r.Recorder, ControllerName: "pinotOperator"}),
builder.ToNewBuilderContext(builder.BuilderContext{Context: ctx}),
builder.ToNewBuilderService(pinotService),
builder.ToNewBuilderStore(*builder.NewStore(ib.client, ib.commonLabels, pt.Namespace, pt)),
)
- The library makes configmap hashes and passes them as env to deployment and sts objects, which force trigger rollout of pods when the intenral k8s client updates objects.
- once builder is constructed, the
ReconcileInterface
can be called in the build and reoncile objects
// reconcile configmap
result, err := builder.ReconcileConfigMap()
if err != nil {
return err
}
- Reconcile store
if err := builder.ReconcileStore(); err != nil {
return err
}
- Interal Store is an in memory which maintains key values for an object name and its kind. This store acts as an abstracted desired state, and is used as a matchmaker against the current state of CR.
type InternalStore struct {
ObjectNameKind map[string]string
CommonBuilder
}