Skip to content

Commit

Permalink
Driver Controller: Enhance logging
Browse files Browse the repository at this point in the history
Signed-off-by: nb-ohad <[email protected]>
  • Loading branch information
nb-ohad committed Jul 15, 2024
1 parent 8733e16 commit f5a0b45
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions internal/controller/driver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (r *driverReconcile) reconcileK8sCsiDriver() error {
existingCsiDriver.Name = r.driver.Name

log := r.log.WithValues("driverName", existingCsiDriver.Name)
log.Info("Reconciling CSI Driver resource")
log.Info("Reconciling CSI Driver")

if err := r.Get(r.ctx, client.ObjectKeyFromObject(existingCsiDriver), existingCsiDriver); client.IgnoreNotFound(err) != nil {
log.Error(err, "Failed to load CSI Driver resource")
Expand Down Expand Up @@ -349,9 +349,10 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
deploy.Namespace = r.driver.Namespace

log := r.log.WithValues("deploymentName", deploy.Name)
log.Info("Reconciling controller plugin deployment resource")
log.Info("Reconciling controller plugin deployment")

_, err := ctrlutil.CreateOrUpdate(r.ctx, r.Client, deploy, func() error {
opResult, err := ctrlutil.CreateOrUpdate(r.ctx, r.Client, deploy, func() error {
r.log.Info("Controller plugin deployment reconciled successfully")
if err := ctrlutil.SetOwnerReference(&r.driver, deploy, r.Scheme); err != nil {
log.Error(err, "Failed setting an owner reference on deployment")
return err
Expand Down Expand Up @@ -673,9 +674,7 @@ func (r *driverReconcile) reconcileControllerPluginDeployment() error {
return nil
})

if err != nil {
r.log.Error(err, "")
}
r.logCreateOrUpdateResult(r.log, deploy, opResult, err)
return nil
}

Expand All @@ -685,9 +684,9 @@ func (r *driverReconcile) reconcileNodePluginDeamonSet() error {
daemonSet.Namespace = r.driver.Namespace

log := r.log.WithValues("daemonSetName", daemonSet.Name)
log.Info("Reconciling controller plugin deployment resource")
log.Info("Reconciling controller plugin deployment")

_, err := ctrlutil.CreateOrUpdate(r.ctx, r.Client, daemonSet, func() error {
opResult, err := ctrlutil.CreateOrUpdate(r.ctx, r.Client, daemonSet, func() error {
if err := ctrlutil.SetOwnerReference(&r.driver, daemonSet, r.Scheme); err != nil {
log.Error(err, "Failed setting an owner reference on deployment")
return err
Expand Down Expand Up @@ -902,9 +901,7 @@ func (r *driverReconcile) reconcileNodePluginDeamonSet() error {
return nil
})

if err != nil {
r.log.Error(err, "")
}
r.logCreateOrUpdateResult(r.log, daemonSet, opResult, err)
return nil
}

Expand All @@ -913,15 +910,15 @@ func (r *driverReconcile) reconcileLivnessService() error {
return nil
}

service := corev1.Service{}
service := &corev1.Service{}
service.Namespace = r.driver.Namespace
service.Name = r.generateName("livness")

log := r.log.WithValues("service", service.Name)
log.Info("Reconciling livness service resource")
log.Info("Reconciling livness service")

_, err := ctrlutil.CreateOrUpdate(r.ctx, r.Client, &service, func() error {
if err := ctrlutil.SetOwnerReference(&r.driver, &service, r.Scheme); err != nil {
opResult, err := ctrlutil.CreateOrUpdate(r.ctx, r.Client, service, func() error {
if err := ctrlutil.SetOwnerReference(&r.driver, service, r.Scheme); err != nil {
r.log.Error(err, "Faild setting an owner reference on service")

Check failure on line 922 in internal/controller/driver_controller.go

View workflow job for this annotation

GitHub Actions / codespell

Faild ==> Failed
return err
}
Expand All @@ -940,12 +937,32 @@ func (r *driverReconcile) reconcileLivnessService() error {
return nil
})

if err != nil {
r.log.Error(err, "")
}
r.logCreateOrUpdateResult(r.log, service, opResult, err)
return nil
}

func (r *driverReconcile) logCreateOrUpdateResult(
log logr.Logger,

Check failure on line 945 in internal/controller/driver_controller.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`(*driverReconcile).logCreateOrUpdateResult` - `log` is unused (unparam)
obj client.Object,
opRes ctrlutil.OperationResult,
err error,
) {
if err == nil {
verb := utils.If(obj.GetUID() == "", "create", "update")
r.log.Error(err, "Failed to %s resource", verb)
return
}

switch opRes {
case ctrlutil.OperationResultNone:
r.log.Info("Resource is already up to date")
case ctrlutil.OperationResultUpdated:
r.log.Info("Resource successfully updated")
case ctrlutil.OperationResultCreated:
r.log.Info("Resource successfully created")
}
}

func (r *driverReconcile) isRdbDriver() bool {
return r.driverType == RbdDriverType
}
Expand Down

0 comments on commit f5a0b45

Please sign in to comment.