diff --git a/README.md b/README.md index b4305415d..605d654db 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # lvm-operator Operator that manages Topolvm + +# Contents +- [docs/design](doc/design/) diff --git a/controllers/lvmcluster_controller.go b/controllers/lvmcluster_controller.go index 995e22a41..876d33f31 100644 --- a/controllers/lvmcluster_controller.go +++ b/controllers/lvmcluster_controller.go @@ -82,7 +82,7 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, req ctrl.Request, for _, unit := range unitList { err := unit.ensureDeleted(r, *lvmCluster) if err != nil { - return result, fmt.Errorf("failed cleaning up: %s %w", unit.getDescription(), err) + return result, fmt.Errorf("failed cleaning up: %s %w", unit.getName(), err) } } } @@ -91,7 +91,7 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, req ctrl.Request, for _, unit := range unitList { err := unit.ensureCreated(r, *lvmCluster) if err != nil { - return result, fmt.Errorf("failed reconciling: %s %w", unit.getDescription(), err) + return result, fmt.Errorf("failed reconciling: %s %w", unit.getName(), err) } } @@ -101,8 +101,8 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, req ctrl.Request, for _, unit := range unitList { err := unit.updateStatus(r, *lvmCluster) if err != nil { - failedStatusUpdates = append(failedStatusUpdates, unit.getDescription()) - unitError := fmt.Errorf("failed updating status for: %s %w", unit.getDescription(), err) + failedStatusUpdates = append(failedStatusUpdates, unit.getName()) + unitError := fmt.Errorf("failed updating status for: %s %w", unit.getName(), err) logger.Error(unitError, "") } } @@ -115,10 +115,19 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, req ctrl.Request, } +// NOTE: when updating this, please also update doc/design/README.md type reconcileUnit interface { - getDescription() string + + // getName should return a camelCase name of this unit of reconciliation + getName() string + + // ensureCreated should check the resources managed by this unit ensureCreated(*LVMClusterReconciler, lvmv1alpha1.LVMCluster) error + + // ensureDeleted should wait for the resources to be cleaned up ensureDeleted(*LVMClusterReconciler, lvmv1alpha1.LVMCluster) error + + // updateStatus should optionally update the CR's status about the health of the managed resource // each unit will have updateStatus called induvidually so // avoid status fields like lastHeartbeatTime and have a // status that changes only when the operands change. diff --git a/doc/design/README.md b/doc/design/README.md new file mode 100644 index 000000000..74d7c7867 --- /dev/null +++ b/doc/design/README.md @@ -0,0 +1,43 @@ +# Operator design + +# Controllers and their managed resources + + +- **lvmcluster-controller:** Running in the operator deployment, it will create all resources that are don't require information from the node. When applicable, the health of the underlying resource is updated in the LVMCluster status and errors are also exposed as events. Overall success also passed on as an event.: + - vgmanager daemonset + - this will require + - lvmd daemonset + - CSIDriver CR + - CSI Driver Controller Deployment (controller is the name of the csi-component) + - CSI Driver Daemonset + - needs an initContainer to block until lvmd config file is read + - StorageClass (TBD) +- **The vg-manager:** A daemonset with one instance per selected node, will create all resources that require knowledge from the node. Errors and PVs being added to a volumegroup will be passed on as events. + - volumegroups + - lvmd config file + + + +Each unit of reconciliation should implement the reconcileUnit interface. +This will be run by the controller, and errors and success will be propogated to the status and events. +This interface is defined in [lvmcluster_controller.go](../../controllers/lvmcluster_controller.go) + +``` +type reconcileUnit interface { + + // getName should return a camelCase name of this unit of reconciliation + getName() string + + // ensureCreated should check the resources managed by this unit + ensureCreated(*LVMClusterReconciler, lvmv1alpha1.LVMCluster) error + + // ensureDeleted should wait for the resources to be cleaned up + ensureDeleted(*LVMClusterReconciler, lvmv1alpha1.LVMCluster) error + + // updateStatus should optionally update the CR's status about the health of the managed resource + // each unit will have updateStatus called induvidually so + // avoid status fields like lastHeartbeatTime and have a + // status that changes only when the operands change. + updateStatus(*LVMClusterReconciler, lvmv1alpha1.LVMCluster) error +} +``` \ No newline at end of file