Skip to main content

Architecture

This Operator is written in Go with help of the Operator-SDK.

Package organization#

System architecture organization in packages

Controller#

The controllers package is responsible for binding the business rules of the Operator with the business rules dictated by the stored procedures and for communicating with the Kubernetes API by reconciling inbound requests triggered by events. This is where the main logic lives.

Kubernetes API extensions#

Folder apis contains 3 distinct packages, config/v1, database/v1 and databaseclass/v1. They contain the types related to the extension applied to the Kubernetes API, i.e. they contain the types of the new API objects. They are the entities and contain no business logic. They can be reused freely throughout the application. Each of these 3 packages contain two other files as well: groupversion_info.go contains information relative to the versioning of the resources and is used by the Kubernetes API, while zz_generated.deepcopy.go contains autogenerated code by the Operator SDK used to allow serialization from and to the Kubernetes API and the Operator. These two files can be found in the other 2 subpackages as well. Each of the aforementioned packages have their relative Custom Resource Definition (CRD) configuration file.

Core packages#

Folder pkg is, by Go convention, a folder which is supposed to contain packages that can be imported freely, i.e. it should not contain any global variables, and it is not tightly coupled with a single implementation. It contains 4 packages:

  • Package database contains all the code relative to the database. It contains the DBMS drivers used to communicate with the DBMS solutions, as well as the types abstracting the various operations, input/output rendering and so on.

Database driver organizations

  • Package pool contains the code relative to the DBMS connection pool. It only holds the DBMS drivers structs responsible for communicating with the DBMS endpoints.
  • Package test contains some utility code useful for testing.
  • Package typeutil contains constants and very generic utility functions (boilerplate). Constants are mainly useful for avoiding hard-coding error messages etc.

During the course of the project, it was attempted to build a robust system architecture by following software engineering principles, especially the SOLID principles.

Command line interface#

Package cmd contains the code relative to the command line interface of the Operator such as reading command line flags, activating/deactivating functionalities, starting the controller and the webhooks, initializing the logger, creating the pool of DBMS connection and so forth. We make use of the excellent Viper library to load flags and configuration files and Cobra for the actual CLI implementation.

Internal#

Folder internal is, by Go convention, a package which cannot be imported from outside this project. It contains the package logging which contains customized logger implementations for the Operator. We use zap for the logging back-end and logr as a front-end (façade).