# Vendor-Agnostic Reconfiguration of Kubernetes Clusters in Cloud Federations
## 6 Design and Implementation of the Autonomic Feature Management Controller
### Controller Implementation
#### 6.2.2 Controller Architecture  
The controller is implemented based on Kubebuilder [51], which provides abstraction over boilerplate code for developing custom controllers, allowing us to focus on the implementation of the control logic. Figure 8 shows the architecture of the controller. Kubebuilder scaffolds the following modules to facilitate the control loop implementation:  
* **Informer** is responsible for watching our custom API resource _Featureconfig_ in the host cluster. If a _Featureconfig_ object changes, the informer updates the corresponding object in the _Cache_ and enqueues the object's key (name and namespace) as an event into the _WorkQueue_;
* **Cache** is a local store that caches resource objects managed by the controller to reduce the load of the host cluster's API server;
* **WorkQueue** stores events that need to be processed, which are the key (name and namespace) of changed Featureconfig objects;
* **Generic Controller** is responsible for dequeuing an event from the _WorkQueue_ and calling the _Reconcile_ method in the _FeatureconfigReconciler_ with this event;
* **Client** can be used by our reconciler to communicate with the API server of the host cluster. If the object of the reconciler wants to fetch is already in the _Cache_, the _Client_ will fetch the object from the _Cache_ directly instead of sending a request to the API server. These modules mainly watch for _Featureconfig_ objects and drive the execution of the **FeatureConfigReconciler** module, which is the principle component added by our work. The control loop logic of this component is implemented in the _Reconcile_ method. Algorithm 1 describes the steps of the method. First, the controller fetches the user-specified desired features from the _Cache_ using the _Client_, based on the name of a _Featureconfig_ object. Then, we get the list of all member clusters including their API server endpoint. These are managed by the Kubefed host cluster as _kubefedclusters_ API objects. Then, we get the list of reconfigurators for configuring the features. A single reconfigurator can be used for reconfiguring multiple features as different features can be enabled by changes to the same configuration manifest. We then run in parallel for each member cluster a separate control loop in a concurrent actor. The control loop first gets the credentials to access the member cluster's API server. Thereafter, for each relevant feature, the reconfigurator uses these credentials to communicate with the member cluster's API server to monitor whether the desired features are supported and to apply the appropriate reconfigurator. Figure 8: Architecture of the controller. ```
Data: The key of a Featureconfig object Result: All member clusters support features specified in the Featureconfig object \(Desired\_features:=Client.GetFeatureConfig(key)\); \(Member\_clusters:=Client.GetMemberClusters(KubeFedCluster)\); for\(feature\in Desired\_features\)do \(rcClasses:=new\;ReconfiguratorClass[]\); \(rcClass:=FeatureConfigReconfiguratorClass(feature)\); if\(rcClass\
otin\)\(reconfiguratorClasses\)then \(rcClasses.append(rcClass)\);  end if end for for\(cluster\in Member\_clusters\)do \(new\;Actor(Cluster:=cluster,\) \(Reconfigurators:=map(rcClass\in rcClasses=>rcClass.instance()\) \(connection\_Credentials:=Client.GetClusterCredential(Cluster))\) { for\(rc\in Reconfigurators\)do \(isReconfigurator,err:=rc.Reconfigurator(Desired\_features,connection\_Credentials)\); if\(isReconfigurator\)then \(err:=rc.Wait\_for\_up(Desired\_features,connection\_Credentials)\)  end if if\(err\)then \(report\_err(rc)\);  end if else \(report\_success(rc)\);  end if \(\}.Run()\)  end for
```  
**Algorithm 1**Reconcile method in FeatureconfigReconiler. We have implemented reconfigurators in a generic way by implementing the _Reconfigurator_ interface (Listing 2). ```
1 Reconfigure (desired_features,member_credential) (bool, error)
2 Wait_for_up(desired_features,member_credential) error
```  
**Algorithm 2**Reconfigurator Interface.