Skip to content

Commit a2f4728

Browse files
committed
Code cleanup and conventional fixes.
Signed-off-by: Humair Khan <[email protected]>
1 parent 74305c5 commit a2f4728

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

controllers/dspipeline_controller.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
253253
return ctrl.Result{}, err
254254
}
255255

256-
err, conditions := r.GenerateStatus(ctx, dspa)
256+
conditions, err := r.GenerateStatus(ctx, dspa)
257257
if err != nil {
258258
log.Info(err.Error())
259259
return ctrl.Result{}, err
@@ -278,15 +278,15 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
278278
return ctrl.Result{}, nil
279279
}
280280

281-
// isDeploymentInCondition evaluates if condition with "name" is in condition of type "conditionType".
281+
// handleReadyCondition evaluates if condition with "name" is in condition of type "conditionType".
282282
// this procedure is valid only for conditions with bool status type, for conditions of non bool type
283283
// results are undefined.
284284
func (r *DSPAReconciler) handleReadyCondition(
285285
ctx context.Context,
286286
dspa *dspav1alpha1.DataSciencePipelinesApplication,
287287
name string,
288288
condition string,
289-
) (error, metav1.Condition) {
289+
) (metav1.Condition, error) {
290290
readyCondition := r.buildCondition(condition, dspa, config.MinimumReplicasAvailable)
291291
deployment := &appsv1.Deployment{}
292292

@@ -295,15 +295,15 @@ func (r *DSPAReconciler) handleReadyCondition(
295295

296296
err := r.Get(ctx, types.NamespacedName{Name: component, Namespace: dspa.Namespace}, deployment)
297297
if err != nil {
298-
return err, metav1.Condition{}
298+
return metav1.Condition{}, err
299299
}
300300

301301
// First check if deployment is scaled down, if it is, component is deemed not ready
302302
if deployment.Spec.Replicas != nil && *deployment.Spec.Replicas == 0 {
303303
readyCondition.Reason = config.MinimumReplicasAvailable
304304
readyCondition.Status = metav1.ConditionFalse
305305
readyCondition.Message = fmt.Sprintf("Deployment for component \"%s\" is scaled down.", component)
306-
return nil, readyCondition
306+
return readyCondition, nil
307307
}
308308

309309
// At this point component is not minimally available, possible scenarios:
@@ -320,7 +320,7 @@ func (r *DSPAReconciler) handleReadyCondition(
320320
readyCondition.Reason = config.MinimumReplicasAvailable
321321
readyCondition.Status = metav1.ConditionTrue
322322
readyCondition.Message = fmt.Sprintf("Component [%s] is minimally available.", component)
323-
return nil, readyCondition
323+
return readyCondition, nil
324324
}
325325

326326
// There are two possible reasons for progress failing, deadline and replica create error:
@@ -332,15 +332,15 @@ func (r *DSPAReconciler) handleReadyCondition(
332332
readyCondition.Status = metav1.ConditionFalse
333333
readyCondition.Message = fmt.Sprintf("Component [%s] has failed to progress. Reason: [%s]. "+
334334
"Message: [%s]", component, progressingCond.Reason, progressingCond.Message)
335-
return nil, readyCondition
335+
return readyCondition, nil
336336
}
337337

338338
if replicaFailureCond != nil && replicaFailureCond.Status == corev1.ConditionTrue {
339339
readyCondition.Reason = config.FailingToDeploy
340340
readyCondition.Status = metav1.ConditionFalse
341341
readyCondition.Message = fmt.Sprintf("Component's replica [%s] has failed to create. Reason: [%s]. "+
342342
"Message: [%s]", component, replicaFailureCond.Reason, replicaFailureCond.Message)
343-
return nil, readyCondition
343+
return readyCondition, nil
344344
}
345345

346346
// Search through the pods associated with this deployment
@@ -352,7 +352,7 @@ func (r *DSPAReconciler) handleReadyCondition(
352352
}
353353
err = r.Client.List(ctx, podList, opts...)
354354
if err != nil {
355-
return err, metav1.Condition{}
355+
return metav1.Condition{}, err
356356
}
357357

358358
hasPodFailures := false
@@ -374,7 +374,7 @@ func (r *DSPAReconciler) handleReadyCondition(
374374
// We concatenate messages from all failing containers.
375375
readyCondition.Message = fmt.Sprintf("Component [%s] is in CrashLoopBackOff. "+
376376
"Message from pod: [%s]", component, c.State.Waiting.Message)
377-
return nil, readyCondition
377+
return readyCondition, nil
378378
}
379379
}
380380
}
@@ -383,31 +383,31 @@ func (r *DSPAReconciler) handleReadyCondition(
383383
readyCondition.Status = metav1.ConditionFalse
384384
readyCondition.Reason = config.FailingToDeploy
385385
readyCondition.Message = podFailureMessage
386-
return nil, readyCondition
386+
return readyCondition, nil
387387
}
388388

389389
// No errors encountered, assume deployment is progressing successfully
390390
// If this DSPA component is minimally available, we are done.
391391
readyCondition.Reason = config.Deploying
392392
readyCondition.Status = metav1.ConditionFalse
393393
readyCondition.Message = fmt.Sprintf("Component [%s] is deploying.", component)
394-
return nil, readyCondition
394+
return readyCondition, nil
395395

396396
}
397397

398-
func (r *DSPAReconciler) GenerateStatus(ctx context.Context, dspa *dspav1alpha1.DataSciencePipelinesApplication) (error, []metav1.Condition) {
398+
func (r *DSPAReconciler) GenerateStatus(ctx context.Context, dspa *dspav1alpha1.DataSciencePipelinesApplication) ([]metav1.Condition, error) {
399399

400-
err, apiServerReady := r.handleReadyCondition(ctx, dspa, "ds-pipeline", config.APIServerReady)
400+
apiServerReady, err := r.handleReadyCondition(ctx, dspa, "ds-pipeline", config.APIServerReady)
401401
if err != nil {
402-
return err, []metav1.Condition{}
402+
return []metav1.Condition{}, err
403403
}
404-
err, persistenceAgentReady := r.handleReadyCondition(ctx, dspa, "ds-pipeline-persistenceagent", config.PersistenceAgentReady)
404+
persistenceAgentReady, err := r.handleReadyCondition(ctx, dspa, "ds-pipeline-persistenceagent", config.PersistenceAgentReady)
405405
if err != nil {
406-
return err, []metav1.Condition{}
406+
return []metav1.Condition{}, err
407407
}
408-
err, scheduledWorkflowReady := r.handleReadyCondition(ctx, dspa, "ds-pipeline-scheduledworkflow", config.ScheduledWorkflowReady)
408+
scheduledWorkflowReady, err := r.handleReadyCondition(ctx, dspa, "ds-pipeline-scheduledworkflow", config.ScheduledWorkflowReady)
409409
if err != nil {
410-
return err, []metav1.Condition{}
410+
return []metav1.Condition{}, err
411411
}
412412
var conditions []metav1.Condition
413413
conditions = append(conditions, apiServerReady)
@@ -443,7 +443,7 @@ func (r *DSPAReconciler) GenerateStatus(ctx context.Context, dspa *dspav1alpha1.
443443
}
444444
}
445445

446-
return nil, conditions
446+
return conditions, nil
447447
}
448448

449449
func (r *DSPAReconciler) PublishMetrics(dspa *dspav1alpha1.DataSciencePipelinesApplication,

controllers/util/util.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,19 @@ import (
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
)
2323

24-
// GetConditionByType returns condition of type T if it exists in conditions, otherwise
24+
// GetConditionByType returns condition of type condType if it exists in conditions, otherwise
2525
// return empty condition struct.
26-
func GetConditionByType(t string, conditions []metav1.Condition) metav1.Condition {
26+
func GetConditionByType(condType string, conditions []metav1.Condition) metav1.Condition {
2727
for _, c := range conditions {
28-
if c.Type == t {
28+
if c.Type == condType {
2929
return c
3030
}
3131
}
3232
return metav1.Condition{}
3333
}
3434

3535
func GetDeploymentCondition(status appsv1.DeploymentStatus, condType appsv1.DeploymentConditionType) *appsv1.DeploymentCondition {
36-
for i := range status.Conditions {
37-
c := status.Conditions[i]
36+
for _, c := range status.Conditions {
3837
if c.Type == condType {
3938
return &c
4039
}

0 commit comments

Comments
 (0)