# The operator
The operator and associated custom resources control the state of ECiDA on the
kubernetes cluster. There are currently 3 relevant custom resources:
Application, Pipeline and Module. These Custom Resource Definitions are
created by operator-sdk's Makefile (using controller-gen). The source of these
custom resources lives in api/v1alpha1/. After modifying these files you can
regenerate the custom resource definitions using make manifests and
regenerate the associated go-code with make generate.
The hierarchy of these resources is one to many for all resources, i.e.: 1
application has many pipelines, 1 pipeline has many modules. Each custom
resource also has its own controller that reconciles the module state. These
controllers live in controllers/.
# The application controller
The application controller's reconcile loop gets triggered everytime a change occurs in an application resource, or a resource that is owned by an application resource. The general steps that this controller performs look like this:
Given the name and namespace of the application resource, check whether an instance of the application resource exists. If not, then this resource has been removed (and thereby everything that had this resouce as owner will be garbage collected).
When the resource does exist, the controller will iterate over the references to pipelines in the repository, and attempt to create Pipeline custom resources for each of them. When doing this, it will compare all of the current and desired pipelines, and ensure that after the reconcilation they will be identical.
After all pipelines are in the desired state, the controller will fetch all pipelines that are marked as "owned by this application". It will for each such pipeline verify that this pipeline is actually in the list of desired pipelines. If it is not, the pipeline will be deleted. This accomplishes declarative deletion.
# The pipeline controller
The pipeline controller is implemented analogously to the application controller, except it manages modules instead.
# The module controller
This controller will create deployments and services for each Module. However, this controller is not implemented yet. Todo.
# The repository
Templates for custom resources are stored in a repository. For now this
repository is implemented as a namespace (ecida-repository) where a
shadow-instance of each resource lives. The controllers are programmed to
ignore any reconcile events that originate from this repository namespace.
A repository reference is then simply a struct that contains the name of the
resource as it is declared in this namespace. Resolution is done using the same
kubernetes client that is used by the operator, but note that this is not a
requirement. For the sake of modularity the client can be swapped out for any
client-go Kubernetes client. The repository resolution module is implemented
in pkg/repository/.
# Factories
A large part of the operator involves creating Kubernetes resources. Since this
is an operator that is so common it is extracted into a separate package that
is dedicated to it. This package can be found in pkg/factories/. Code in this
package is responsible for creating each of the custom resource types, as well
as creating ObjectMeta structs that define the name of resources. This package
is used throughout the controllers to look up objects by name.