Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update controller recorder events #1212

Open
wants to merge 1 commit into
base: incubation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions controllers/datasciencecluster/datasciencecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
dsciInstances := &dsciv1.DSCInitializationList{}
err = r.Client.List(ctx, dsciInstances)
if err != nil {
r.Log.Error(err, "Failed to retrieve DSCInitialization resource.", "DSCInitialization Request.Name", req.Name)
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "DSCInitializationReconcileError", "Failed to retrieve DSCInitialization instance")
r.reportWarning(err, instance, "DSCInitializationReconcileError", "Failed to retrieve DSCInitialization resource")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's warning then I think, we should also change reason value DSCInitializationReconcileWarning instead DSCInitializationReconcileError
wdyt ?


return ctrl.Result{}, err
}
Expand All @@ -167,11 +166,11 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
saved.Status.Phase = status.PhaseError
})
if err != nil {
r.reportError(err, instance, "failed to update DataScienceCluster condition")

r.reportWarning(err, instance, "DataScienceClusterReconcileError", "Failed to update DataScienceCluster resource")
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
// do not rush to reconcile DSC, wait for DSCI
return ctrl.Result{RequeueAfter: time.Second * 30}, nil
case 1:
dscInitializationSpec := dsciInstances.Items[0].Spec
dscInitializationSpec.DeepCopyInto(r.DataScienceCluster.DSCISpec)
Expand Down Expand Up @@ -230,8 +229,7 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
saved.Status.Phase = status.PhaseProgressing
})
if err != nil {
_ = r.reportError(err, instance, fmt.Sprintf("failed to add conditions to status of DataScienceCluster resource name %s", req.Name))

_ = r.reportWarning(err, instance, "DataScienceClusterReconcileError", "Failed to add conditions to DataScienceCluster resource: "+req.Name)
return ctrl.Result{}, err
}
}
Expand Down Expand Up @@ -303,7 +301,7 @@ func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context
status.SetComponentCondition(&saved.Status.Conditions, componentName, status.ReconcileInit, message, corev1.ConditionUnknown)
})
if err != nil {
_ = r.reportError(err, instance, "failed to update DataScienceCluster conditions before first time reconciling "+componentName)
_ = r.reportWarning(err, instance, "DataScienceClusterReconcileError", "Failed to update DataScienceCluster conditions before first time reconciling "+componentName)
// try to continue with reconciliation, as further updates can fix the status
}
}
Expand All @@ -318,7 +316,7 @@ func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context

if err != nil {
// reconciliation failed: log errors, raise event and update status accordingly
instance = r.reportError(err, instance, "failed to reconcile "+componentName+" on DataScienceCluster")
instance = r.reportWarning(err, instance, "DataScienceClusterReconcileError", "Failed to reconcile "+componentName+" on DataScienceCluster")
instance, _ = status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dscv1.DataScienceCluster) {
if enabled {
if strings.Contains(err.Error(), datasciencepipelines.ArgoWorkflowCRD+" CRD already exists") {
Expand All @@ -345,18 +343,16 @@ func (r *DataScienceClusterReconciler) reconcileSubComponent(ctx context.Context
}
})
if err != nil {
instance = r.reportError(err, instance, "failed to update DataScienceCluster status after reconciling "+componentName)

instance = r.reportWarning(err, instance, "DataScienceClusterReconcileError", "Failed to update DataScienceCluster status after reconciling "+componentName)
return instance, err
}

return instance, nil
}

func (r *DataScienceClusterReconciler) reportError(err error, instance *dscv1.DataScienceCluster, message string) *dscv1.DataScienceCluster {
func (r *DataScienceClusterReconciler) reportWarning(err error, instance *dscv1.DataScienceCluster, reason string, message string) *dscv1.DataScienceCluster {
r.Log.Error(err, message, "instance.Name", instance.Name)
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "DataScienceClusterReconcileError",
"%s for instance %s", message, instance.Name)
r.Recorder.Eventf(instance, corev1.EventTypeWarning, reason, message)
return instance
}

Expand Down
12 changes: 4 additions & 8 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
if err := r.Client.List(ctx, instances); err != nil {
r.Log.Error(err, "Failed to retrieve DSCInitialization resource.", "DSCInitialization Request.Name", req.Name)
r.Recorder.Eventf(instances, corev1.EventTypeWarning, "DSCInitializationReconcileError", "Failed to retrieve DSCInitialization instance")

return ctrl.Result{}, err
}

Expand Down Expand Up @@ -144,10 +143,8 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
saved.Status.Phase = status.PhaseProgressing
})
if err != nil {
r.Log.Error(err, "Failed to add conditions to status of DSCInitialization resource.", "DSCInitialization", req.Namespace, "Request.Name", req.Name)
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "DSCInitializationReconcileError",
"%s for instance %s", message, instance.Name)

r.Log.Error(err, "Failed to add conditions to DSCInitialization resource.", "DSCInitialization", req.Namespace, "Request.Name", req.Name)
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "DSCInitializationReconcileError", "%s for instance %s", message, instance.Name)
return reconcile.Result{}, err
}
}
Expand Down Expand Up @@ -223,9 +220,8 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
osdConfigsPath := filepath.Join(deploy.DefaultManifestPath, "osd-configs")
err = deploy.DeployManifestsFromPath(ctx, r.Client, instance, osdConfigsPath, r.ApplicationsNamespace, "osd", true)
if err != nil {
r.Log.Error(err, "Failed to apply osd specific configs from manifests", "Manifests path", osdConfigsPath)
r.Log.Error(err, "Failed to apply ODS specific configs from manifests", "Manifests path", osdConfigsPath)
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "DSCInitializationReconcileError", "Failed to apply "+osdConfigsPath)

return reconcile.Result{}, err
}
if instance.Spec.Monitoring.ManagementState == operatorv1.Managed {
Expand Down Expand Up @@ -261,7 +257,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
saved.Status.Release = currentOperatorReleaseVersion
})
if err != nil {
r.Log.Error(err, "failed to update DSCInitialization status after successfully completed reconciliation")
r.Log.Error(err, "Failed to update DSCInitialization status after successfully completed reconciliation")
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "DSCInitializationReconcileError", "Failed to update DSCInitialization status")
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/status/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
// })
//
// serviceMeshErr := createServiceMesh(instance)
// _, reportError := reporter.ReportCondition(serviceMeshErr)
// _, reportWarning := reporter.ReportCondition(serviceMeshErr)
//
// return multierror.Append(serviceMeshErr, reportError) // return all errors
// return multierror.Append(serviceMeshErr, reportWarning) // return all errors
// }
package status
Loading