Skip to content

Commit

Permalink
Merge pull request #492 from fmount/cleanup_updates_log
Browse files Browse the repository at this point in the history
Improve logging and remove placeholder reconcile functions
  • Loading branch information
openshift-merge-bot[bot] authored Mar 29, 2024
2 parents 47e8a3c + 5d6aed5 commit bd1b51e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 86 deletions.
53 changes: 9 additions & 44 deletions controllers/glance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"time"

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

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

Expand Down Expand Up @@ -401,7 +402,7 @@ func (r *GlanceReconciler) reconcileInit(
_, _, err := oko_secret.GetSecret(ctx, helper, instance.Spec.Secret, instance.Namespace)
if err != nil {
if k8s_errors.IsNotFound(err) {
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
return glance.ResultRequeue, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
}
return ctrl.Result{}, err
}
Expand All @@ -416,7 +417,7 @@ func (r *GlanceReconciler) reconcileInit(
PasswordSelector: instance.Spec.PasswordSelectors.Service,
}

ksSvc := keystonev1.NewKeystoneService(ksSvcSpec, instance.Namespace, serviceLabels, time.Duration(10)*time.Second)
ksSvc := keystonev1.NewKeystoneService(ksSvcSpec, instance.Namespace, serviceLabels, glance.NormalDuration)
ctrlResult, err := ksSvc.CreateOrPatch(ctx, helper)
if err != nil {
return ctrlResult, err
Expand Down Expand Up @@ -448,7 +449,7 @@ func (r *GlanceReconciler) reconcileInit(
jobDef,
glancev1.DbSyncHash,
instance.Spec.PreserveJobs,
time.Duration(5)*time.Second,
glance.ShortDuration,
dbSyncHash,
)
ctrlResult, err = dbSyncjob.DoJob(
Expand Down Expand Up @@ -486,26 +487,6 @@ func (r *GlanceReconciler) reconcileInit(
return ctrl.Result{}, nil
}

func (r *GlanceReconciler) reconcileUpdate(ctx context.Context, instance *glancev1.Glance, helper *helper.Helper) (ctrl.Result, error) {
r.Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name))

// TODO: should have minor update tasks if required
// - delete dbsync hash from status to rerun it?

r.Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name))
return ctrl.Result{}, nil
}

func (r *GlanceReconciler) reconcileUpgrade(ctx context.Context, instance *glancev1.Glance, helper *helper.Helper) (ctrl.Result, error) {
r.Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name))

// TODO: should have major version upgrade tasks
// -delete dbsync hash from status to rerun it?

r.Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name))
return ctrl.Result{}, nil
}

func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glancev1.Glance, helper *helper.Helper) (ctrl.Result, error) {
r.Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name))

Expand Down Expand Up @@ -549,7 +530,7 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
condition.RequestedReason,
condition.SeverityInfo,
condition.MemcachedReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("memcached %s not found", instance.Spec.MemcachedInstance)
return glance.ResultRequeue, fmt.Errorf("memcached %s not found", instance.Spec.MemcachedInstance)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.MemcachedReadyCondition,
Expand All @@ -566,7 +547,7 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
condition.RequestedReason,
condition.SeverityInfo,
condition.MemcachedReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("memcached %s is not ready", memcached.Name)
return glance.ResultRequeue, fmt.Errorf("memcached %s is not ready", memcached.Name)
}
// Mark the Memcached Service as Ready if we get to this point with no errors
instance.Status.Conditions.MarkTrue(
Expand All @@ -584,7 +565,7 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
return glance.ResultRequeue, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
Expand Down Expand Up @@ -643,22 +624,6 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance
return ctrlResult, nil
}

// Handle service update
ctrlResult, err = r.reconcileUpdate(ctx, instance, helper)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}

// Handle service upgrade
ctrlResult, err = r.reconcileUpgrade(ctx, instance, helper)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}

//
// Reconcile the GlanceAPI deployment
//
Expand Down Expand Up @@ -1052,7 +1017,7 @@ func (r *GlanceReconciler) ensureDBPurgeJob(

dbPurgeCronJob := cronjob.NewCronJob(
cronjobDef,
5*time.Second,
glance.ShortDuration,
)
ctrlResult, err := dbPurgeCronJob.CreateOrPatch(ctx, h)
if err != nil {
Expand Down
49 changes: 7 additions & 42 deletions controllers/glanceapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"strings"
"time"

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

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

Expand Down Expand Up @@ -525,26 +526,6 @@ func (r *GlanceAPIReconciler) reconcileInit(
return ctrl.Result{}, nil
}

func (r *GlanceAPIReconciler) reconcileUpdate(ctx context.Context, instance *glancev1.GlanceAPI, helper *helper.Helper) (ctrl.Result, error) {
r.Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name))

// TODO: should have minor update tasks if required
// - delete dbsync hash from status to rerun it?

r.Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name))
return ctrl.Result{}, nil
}

func (r *GlanceAPIReconciler) reconcileUpgrade(ctx context.Context, instance *glancev1.GlanceAPI, helper *helper.Helper) (ctrl.Result, error) {
r.Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name))

// TODO: should have major version upgrade tasks
// -delete dbsync hash from status to rerun it?

r.Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name))
return ctrl.Result{}, nil
}

func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *glancev1.GlanceAPI, helper *helper.Helper, req ctrl.Request) (ctrl.Result, error) {
r.Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name))

Expand All @@ -563,7 +544,7 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
return glance.ResultRequeue, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
Expand Down Expand Up @@ -619,7 +600,7 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
condition.SeverityInfo,
glancev1.CinderInitMessage),
)
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
return glance.ResultRequeue, nil
}
// Cinder CR is found, we can unblock glance deployment because
// it represents a valid backend.
Expand Down Expand Up @@ -750,22 +731,6 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
return ctrlResult, nil
}

// Handle service update
ctrlResult, err = r.reconcileUpdate(ctx, instance, helper)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}

// Handle service upgrade
ctrlResult, err = r.reconcileUpgrade(ctx, instance, helper)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}

//
// normal reconcile tasks
//
Expand All @@ -783,7 +748,7 @@ func (r *GlanceAPIReconciler) reconcileNormal(ctx context.Context, instance *gla
}
depl := statefulset.NewStatefulSet(
deplDef,
time.Duration(5)*time.Second,
glance.ShortDuration,
)

ctrlResult, err = depl.CreateOrPatch(ctx, helper)
Expand Down Expand Up @@ -1116,7 +1081,7 @@ func (r *GlanceAPIReconciler) ensureKeystoneEndpoints(
instance.Namespace,
ksEndpointSpec,
serviceLabels,
time.Duration(10)*time.Second,
glance.NormalDuration,
)
ctrlResult, err = ksSvc.CreateOrPatch(ctx, helper)
if err != nil {
Expand Down Expand Up @@ -1201,7 +1166,7 @@ func (r *GlanceAPIReconciler) ensureImageCacheJob(
)
imageCacheCronJob := cronjob.NewCronJob(
cronjobDef,
5*time.Second,
glance.ShortDuration,
)
ctrlResult, err := imageCacheCronJob.CreateOrPatch(ctx, h)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/glance/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package glance

import (
"github.com/openstack-k8s-operators/lib-common/modules/storage"
ctrl "sigs.k8s.io/controller-runtime"
"time"
)

// CronJobType -
Expand Down Expand Up @@ -101,6 +103,10 @@ const (
GlanceCacheCleaner = "/usr/bin/glance-cache-cleaner"
// GlanceCachePruner -
GlanceCachePruner = "/usr/bin/glance-cache-pruner"
// ShortDuration -
ShortDuration = time.Duration(5) * time.Second
// NormalDuration -
NormalDuration = time.Duration(10) * time.Second
)

// DbsyncPropagation keeps track of the DBSync Service Propagation Type
Expand All @@ -110,3 +116,6 @@ var DbsyncPropagation = []storage.PropagationType{storage.DBSync}
// It allows the GlanceAPI pod to mount volumes destined to Glance related
// ServiceTypes
var GlanceAPIPropagation = []storage.PropagationType{Glance, GlanceAPI}

// ResultRequeue - Used to requeue a request
var ResultRequeue = ctrl.Result{RequeueAfter: NormalDuration}

0 comments on commit bd1b51e

Please sign in to comment.