Skip to content

Commit 5d6aed5

Browse files
committed
Improve logging and remove placeholder reconcile functions
Signed-off-by: Francesco Pantano <fpantano@redhat.com>
1 parent cc5c8f9 commit 5d6aed5

3 files changed

Lines changed: 25 additions & 86 deletions

File tree

controllers/glance_controller.go

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22-
"time"
2322

2423
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
2524
rbacv1 "k8s.io/api/rbac/v1"
@@ -109,6 +108,7 @@ func (r *GlanceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
109108
return ctrl.Result{}, nil
110109
}
111110
// Error reading the object - requeue the request.
111+
r.Log.Error(err, fmt.Sprintf("could not fetch Glance instance %s", instance.Name))
112112
return ctrl.Result{}, err
113113
}
114114

@@ -120,6 +120,7 @@ func (r *GlanceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
120120
r.Log,
121121
)
122122
if err != nil {
123+
r.Log.Error(err, fmt.Sprintf("could not instantiate helper for instance %s", instance.Name))
123124
return ctrl.Result{}, err
124125
}
125126

@@ -408,7 +409,7 @@ func (r *GlanceReconciler) reconcileInit(
408409
_, _, err := oko_secret.GetSecret(ctx, helper, instance.Spec.Secret, instance.Namespace)
409410
if err != nil {
410411
if k8s_errors.IsNotFound(err) {
411-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
412+
return glance.ResultRequeue, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
412413
}
413414
return ctrl.Result{}, err
414415
}
@@ -423,7 +424,7 @@ func (r *GlanceReconciler) reconcileInit(
423424
PasswordSelector: instance.Spec.PasswordSelectors.Service,
424425
}
425426

426-
ksSvc := keystonev1.NewKeystoneService(ksSvcSpec, instance.Namespace, serviceLabels, time.Duration(10)*time.Second)
427+
ksSvc := keystonev1.NewKeystoneService(ksSvcSpec, instance.Namespace, serviceLabels, glance.NormalDuration)
427428
ctrlResult, err := ksSvc.CreateOrPatch(ctx, helper)
428429
if err != nil {
429430
return ctrlResult, err
@@ -455,7 +456,7 @@ func (r *GlanceReconciler) reconcileInit(
455456
jobDef,
456457
glancev1.DbSyncHash,
457458
instance.Spec.PreserveJobs,
458-
time.Duration(5)*time.Second,
459+
glance.ShortDuration,
459460
dbSyncHash,
460461
)
461462
ctrlResult, err = dbSyncjob.DoJob(
@@ -489,26 +490,6 @@ func (r *GlanceReconciler) reconcileInit(
489490
return ctrl.Result{}, nil
490491
}
491492

492-
func (r *GlanceReconciler) reconcileUpdate(ctx context.Context, instance *glancev1.Glance, helper *helper.Helper) (ctrl.Result, error) {
493-
r.Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name))
494-
495-
// TODO: should have minor update tasks if required
496-
// - delete dbsync hash from status to rerun it?
497-
498-
r.Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name))
499-
return ctrl.Result{}, nil
500-
}
501-
502-
func (r *GlanceReconciler) reconcileUpgrade(ctx context.Context, instance *glancev1.Glance, helper *helper.Helper) (ctrl.Result, error) {
503-
r.Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name))
504-
505-
// TODO: should have major version upgrade tasks
506-
// -delete dbsync hash from status to rerun it?
507-
508-
r.Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name))
509-
return ctrl.Result{}, nil
510-
}
511-
512493
func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glancev1.Glance, helper *helper.Helper) (ctrl.Result, error) {
513494
r.Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name))
514495

@@ -552,7 +533,7 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
552533
condition.RequestedReason,
553534
condition.SeverityInfo,
554535
condition.MemcachedReadyWaitingMessage))
555-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("memcached %s not found", instance.Spec.MemcachedInstance)
536+
return glance.ResultRequeue, fmt.Errorf("memcached %s not found", instance.Spec.MemcachedInstance)
556537
}
557538
instance.Status.Conditions.Set(condition.FalseCondition(
558539
condition.MemcachedReadyCondition,
@@ -569,7 +550,7 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
569550
condition.RequestedReason,
570551
condition.SeverityInfo,
571552
condition.MemcachedReadyWaitingMessage))
572-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("memcached %s is not ready", memcached.Name)
553+
return glance.ResultRequeue, fmt.Errorf("memcached %s is not ready", memcached.Name)
573554
}
574555
// Mark the Memcached Service as Ready if we get to this point with no errors
575556
instance.Status.Conditions.MarkTrue(
@@ -587,7 +568,7 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
587568
condition.RequestedReason,
588569
condition.SeverityInfo,
589570
condition.InputReadyWaitingMessage))
590-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
571+
return glance.ResultRequeue, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
591572
}
592573
instance.Status.Conditions.Set(condition.FalseCondition(
593574
condition.InputReadyCondition,
@@ -646,22 +627,6 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
646627
return ctrlResult, nil
647628
}
648629

649-
// Handle service update
650-
ctrlResult, err = r.reconcileUpdate(ctx, instance, helper)
651-
if err != nil {
652-
return ctrlResult, err
653-
} else if (ctrlResult != ctrl.Result{}) {
654-
return ctrlResult, nil
655-
}
656-
657-
// Handle service upgrade
658-
ctrlResult, err = r.reconcileUpgrade(ctx, instance, helper)
659-
if err != nil {
660-
return ctrlResult, err
661-
} else if (ctrlResult != ctrl.Result{}) {
662-
return ctrlResult, nil
663-
}
664-
665630
//
666631
// Reconcile the GlanceAPI deployment
667632
//
@@ -1054,7 +1019,7 @@ func (r *GlanceReconciler) ensureDBPurgeJob(
10541019

10551020
dbPurgeCronJob := cronjob.NewCronJob(
10561021
cronjobDef,
1057-
5*time.Second,
1022+
glance.ShortDuration,
10581023
)
10591024
ctrlResult, err := dbPurgeCronJob.CreateOrPatch(ctx, h)
10601025
if err != nil {

controllers/glanceapi_controller.go

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"strings"
23-
"time"
2423

2524
batchv1 "k8s.io/api/batch/v1"
2625
"k8s.io/apimachinery/pkg/api/resource"
@@ -104,6 +103,7 @@ func (r *GlanceAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
104103
return ctrl.Result{}, nil
105104
}
106105
// Error reading the object - requeue the request.
106+
r.Log.Error(err, fmt.Sprintf("could not fetch GlanceAPI instance %s", instance.Name))
107107
return ctrl.Result{}, err
108108
}
109109

@@ -115,6 +115,7 @@ func (r *GlanceAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
115115
r.Log,
116116
)
117117
if err != nil {
118+
r.Log.Error(err, fmt.Sprintf("could not instantiate helper for instance %s", instance.Name))
118119
return ctrl.Result{}, err
119120
}
120121

@@ -525,26 +526,6 @@ func (r *GlanceAPIReconciler) reconcileInit(
525526
return ctrl.Result{}, nil
526527
}
527528

528-
func (r *GlanceAPIReconciler) reconcileUpdate(ctx context.Context, instance *glancev1.GlanceAPI, helper *helper.Helper) (ctrl.Result, error) {
529-
r.Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name))
530-
531-
// TODO: should have minor update tasks if required
532-
// - delete dbsync hash from status to rerun it?
533-
534-
r.Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name))
535-
return ctrl.Result{}, nil
536-
}
537-
538-
func (r *GlanceAPIReconciler) reconcileUpgrade(ctx context.Context, instance *glancev1.GlanceAPI, helper *helper.Helper) (ctrl.Result, error) {
539-
r.Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name))
540-
541-
// TODO: should have major version upgrade tasks
542-
// -delete dbsync hash from status to rerun it?
543-
544-
r.Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name))
545-
return ctrl.Result{}, nil
546-
}
547-
548529
func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *glancev1.GlanceAPI, helper *helper.Helper, req ctrl.Request) (ctrl.Result, error) {
549530
r.Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name))
550531

@@ -563,7 +544,7 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
563544
condition.RequestedReason,
564545
condition.SeverityInfo,
565546
condition.InputReadyWaitingMessage))
566-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
547+
return glance.ResultRequeue, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
567548
}
568549
instance.Status.Conditions.Set(condition.FalseCondition(
569550
condition.InputReadyCondition,
@@ -612,7 +593,7 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
612593
condition.SeverityInfo,
613594
glancev1.CinderInitMessage),
614595
)
615-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
596+
return glance.ResultRequeue, nil
616597
}
617598
// Cinder CR is found, we can unblock glance deployment because
618599
// it represents a valid backend.
@@ -743,22 +724,6 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
743724
return ctrlResult, nil
744725
}
745726

746-
// Handle service update
747-
ctrlResult, err = r.reconcileUpdate(ctx, instance, helper)
748-
if err != nil {
749-
return ctrlResult, err
750-
} else if (ctrlResult != ctrl.Result{}) {
751-
return ctrlResult, nil
752-
}
753-
754-
// Handle service upgrade
755-
ctrlResult, err = r.reconcileUpgrade(ctx, instance, helper)
756-
if err != nil {
757-
return ctrlResult, err
758-
} else if (ctrlResult != ctrl.Result{}) {
759-
return ctrlResult, nil
760-
}
761-
762727
//
763728
// normal reconcile tasks
764729
//
@@ -776,7 +741,7 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
776741
}
777742
depl := statefulset.NewStatefulSet(
778743
deplDef,
779-
time.Duration(5)*time.Second,
744+
glance.ShortDuration,
780745
)
781746

782747
ctrlResult, err = depl.CreateOrPatch(ctx, helper)
@@ -1109,7 +1074,7 @@ func (r *GlanceAPIReconciler) ensureKeystoneEndpoints(
11091074
instance.Namespace,
11101075
ksEndpointSpec,
11111076
serviceLabels,
1112-
time.Duration(10)*time.Second,
1077+
glance.NormalDuration,
11131078
)
11141079
ctrlResult, err = ksSvc.CreateOrPatch(ctx, helper)
11151080
if err != nil {
@@ -1194,7 +1159,7 @@ func (r *GlanceAPIReconciler) ensureImageCacheJob(
11941159
)
11951160
imageCacheCronJob := cronjob.NewCronJob(
11961161
cronjobDef,
1197-
5*time.Second,
1162+
glance.ShortDuration,
11981163
)
11991164
ctrlResult, err := imageCacheCronJob.CreateOrPatch(ctx, h)
12001165
if err != nil {

pkg/glance/const.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package glance
1717

1818
import (
1919
"github.com/openstack-k8s-operators/lib-common/modules/storage"
20+
ctrl "sigs.k8s.io/controller-runtime"
21+
"time"
2022
)
2123

2224
// CronJobType -
@@ -101,6 +103,10 @@ const (
101103
GlanceCacheCleaner = "/usr/bin/glance-cache-cleaner"
102104
// GlanceCachePruner -
103105
GlanceCachePruner = "/usr/bin/glance-cache-pruner"
106+
// ShortDuration -
107+
ShortDuration = time.Duration(5) * time.Second
108+
// NormalDuration -
109+
NormalDuration = time.Duration(10) * time.Second
104110
)
105111

106112
// DbsyncPropagation keeps track of the DBSync Service Propagation Type
@@ -110,3 +116,6 @@ var DbsyncPropagation = []storage.PropagationType{storage.DBSync}
110116
// It allows the GlanceAPI pod to mount volumes destined to Glance related
111117
// ServiceTypes
112118
var GlanceAPIPropagation = []storage.PropagationType{Glance, GlanceAPI}
119+
120+
// ResultRequeue - Used to requeue a request
121+
var ResultRequeue = ctrl.Result{RequeueAfter: NormalDuration}

0 commit comments

Comments
 (0)