#Cluster Controller The cluster controller reconciles on create and update of a `cluster` resource. For a cluster of type GKE a container cluster and a container node pool is created. For any other type cluster, a fluentbit config map is generated and added to a synced object. ## Synced Objects A SyncedObject resource allow us to specify resources that will be sync by flux using chiarot. The SyncedObject controller is responsible to call chariot using the information in the SyncedObject resource. ## Plugins Plugins allow us to add functionality to the cluster controller without modify it, to create a plugin follow the steps below: 1) Implement the `ClusterRegistrationPlugin` interface below found in `controllers/clusterctl/pkg/plugins/plugins.go` ```go type ClusterRegistrationPlugin interface { Reconcile(ctx context.Context, cl client.Client, log logr.Logger, cluster *clusterApi.Cluster) (ctrl.Result, error) Component() string // returns the name of the component that owns the created resources } ``` 2) Register the plugins in `controllers/clusterctl/controller.go` ```go // registerPlugins add new plugins here to be automatically executed by controller. func registerPlugins() { plugins.Register(clusterctlplugin.AgentMonitoringSAPlugin{ SecretManagerProvider: func(ctx context.Context, projectID string) (types.SecretManagerService, error) { return secretMgrApi.NewWithOptions(ctx, projectID) }, }) } ``` 3) Add kubebuilder rbac annotations in `controllers/clusterctl/cluster_controller.go` to create role needed by your plugin. Once done, run `just update-manifest` to generate those roles. ```go // +kubebuilder:rbac:groups=edge.ncr.com,resources=clusters,verbs=get;list;watch // +kubebuilder:rbac:groups=edge.ncr.com,resources=clusters/status,verbs=get // +kubebuilder:rbac:groups=edge.ncr.com,resources=syncedobjects,verbs=create;get;list;update;patch;watch // +kubebuilder:rbac:groups=edge.ncr.com,resources=syncedobjects/status,verbs=get // +kubebuilder:rbac:groups="container.cnrm.cloud.google.com",resources=containerclusters,verbs=create;get;list;update;patch;watch // +kubebuilder:rbac:groups="container.cnrm.cloud.google.com",resources=containerclusters/status,verbs=get // +kubebuilder:rbac:groups="iam.cnrm.cloud.google.com",resources=iamserviceaccounts;iamserviceaccountkeys;iampolicymembers,verbs=get;list;create;update;patch;watch // +kubebuilder:rbac:groups="iam.cnrm.cloud.google.com",resources=iamserviceaccounts/status;iamservicecaccountkeys/status;iampolicymembers/status,verbs=get ```