Skip to content

Commit

Permalink
use new workload controller with preconditions
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanBednar committed Oct 1, 2024
1 parent d44cdc0 commit 04ab0d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions pkg/operator/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ type OperatorControllerConfig struct {
GuestDaemonSetHooks []csidrivernodeservicecontroller.DaemonSetHookFunc
// List of informers that should be added to the guest DaemonSet controller.
GuestDaemonSetInformers []factory.Informer

// List of functions that should return true if we want the controller to sync normally.
// Returning false or error will degrade the cluster with OperatorCondition.Reason set to "PreconditionNotFulfilled"
// and any errors returned are shown as OperatorCondition.Message
Preconditions []deploymentcontroller.PreconditionFunc

// List of hooks should be run on the storage classes.
// No informers here, because StorageClassController does not accept any.
StorageClassHooks []csistorageclasscontroller.StorageClassHookFunc
Expand Down Expand Up @@ -116,6 +122,20 @@ func (o *OperatorControllerConfig) AddStorageClassHookBuilders(c *clients.Client
}
}

func (o *OperatorControllerConfig) AddPreconditions(preconditionFuncs ...deploymentcontroller.PreconditionFunc) {
for _, f := range preconditionFuncs {
o.Preconditions = append(o.Preconditions, f)
}
}

func (o *OperatorControllerConfig) GetPreconditions() []func(context.Context) (bool, error) {
var funcs []func(context.Context) (bool, error)
for _, precondition := range o.Preconditions {
funcs = append(funcs, precondition)
}
return funcs
}

type DeploymentHookBuilder func(c *clients.Clients) (deploymentcontroller.DeploymentHookFunc, []factory.Informer)
type DaemonSetHookBuilder func(c *clients.Clients) (csidrivernodeservicecontroller.DaemonSetHookFunc, []factory.Informer)
type StorageClassHookBuilder func(c *clients.Clients) csistorageclasscontroller.StorageClassHookFunc
Expand Down
6 changes: 4 additions & 2 deletions pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
).WithCSIConfigObserverController(
csiOperatorControllerConfig.GetControllerName("DriverCSIConfigObserverController"),
c.ConfigInformers,
).WithCSIDriverControllerService(
).WithCSIDriverControllerServiceWorkload(
csiOperatorControllerConfig.GetControllerName("DriverControllerServiceController"),
controlPlaneNamespace,
a.GetAsset,
generated_assets.ControllerDeploymentAssetName,
c.ControlPlaneKubeClient,
c.ControlPlaneKubeInformers.InformersFor(controlPlaneNamespace),
c.ControlPlaneKubeInformers,
c.ConfigInformers,
csiOperatorControllerConfig.GetPreconditions(),
controlPlaneControllerInformers,
controllerHooks...,
)
Expand Down

0 comments on commit 04ab0d7

Please sign in to comment.