Skip to content

Commit

Permalink
Merge pull request #260 from fmount/cleanup_updates
Browse files Browse the repository at this point in the history
Improve logging and remove placeholder functions
  • Loading branch information
openshift-merge-bot[bot] authored Mar 29, 2024
2 parents 1b212e9 + 229937d commit db99e21
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 167 deletions.
53 changes: 9 additions & 44 deletions controllers/manila_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/go-logr/logr"
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
Expand Down Expand Up @@ -128,6 +127,7 @@ func (r *ManilaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
if k8s_errors.IsNotFound(err) {
return ctrl.Result{}, nil
}
r.Log.Error(err, fmt.Sprintf("could not fetch Manila instance %s", instance.Name))
return ctrl.Result{}, err
}

Expand All @@ -139,6 +139,7 @@ func (r *ManilaReconciler) 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 @@ -364,7 +365,7 @@ func (r *ManilaReconciler) reconcileInit(
jobDef,
manilav1beta1.DbSyncHash,
instance.Spec.PreserveJobs,
time.Duration(5)*time.Second,
manila.ShortDuration,
dbSyncHash,
)
ctrlResult, err := dbSyncjob.DoJob(
Expand Down Expand Up @@ -455,7 +456,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
condition.RequestedReason,
condition.SeverityInfo,
condition.RabbitMqTransportURLReadyRunningMessage))
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
return manila.ResultRequeue, nil
}

instance.Status.Conditions.MarkTrue(condition.RabbitMqTransportURLReadyCondition, condition.RabbitMqTransportURLReadyMessage)
Expand All @@ -473,7 +474,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
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 manila.ResultRequeue, fmt.Errorf("memcached %s not found", instance.Spec.MemcachedInstance)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.MemcachedReadyCondition,
Expand All @@ -490,7 +491,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
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 manila.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 @@ -508,7 +509,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
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 manila.ResultRequeue, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
Expand Down Expand Up @@ -601,7 +602,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
condition.SeverityInfo,
condition.NetworkAttachmentsReadyWaitingMessage,
netAtt))
return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt)
return manila.ResultRequeue, fmt.Errorf("network-attachment-definition %s not found", netAtt)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
Expand Down Expand Up @@ -635,22 +636,6 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
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 Down Expand Up @@ -761,7 +746,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
cronjobDef := manila.CronJob(instance, serviceLabels, serviceAnnotations)
cronjob := cronjob.NewCronJob(
cronjobDef,
5*time.Second,
manila.ShortDuration,
)

ctrlResult, err = cronjob.CreateOrPatch(ctx, helper)
Expand All @@ -787,26 +772,6 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
return ctrl.Result{}, nil
}

func (r *ManilaReconciler) reconcileUpdate(ctx context.Context, instance *manilav1beta1.Manila, 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 *ManilaReconciler) reconcileUpgrade(ctx context.Context, instance *manilav1beta1.Manila, 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
}

// generateServiceConfigMaps - create create configmaps which hold scripts and service configuration
func (r *ManilaReconciler) generateServiceConfig(
ctx context.Context,
Expand Down
49 changes: 7 additions & 42 deletions controllers/manilaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"time"

"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -127,6 +126,7 @@ func (r *ManilaAPIReconciler) 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 ManilaAPI instance %s", instance.Name))
return ctrl.Result{}, err
}

Expand All @@ -138,6 +138,7 @@ func (r *ManilaAPIReconciler) 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 @@ -562,7 +563,7 @@ func (r *ManilaAPIReconciler) reconcileInit(
PasswordSelector: instance.Spec.PasswordSelectors.Service,
}

ksSvcObj := keystonev1.NewKeystoneService(ksSvcSpec, instance.Namespace, serviceLabels, time.Duration(10)*time.Second)
ksSvcObj := keystonev1.NewKeystoneService(ksSvcSpec, instance.Namespace, serviceLabels, manila.NormalDuration)
ctrlResult, err := ksSvcObj.CreateOrPatch(ctx, helper)
if err != nil {
instance.Status.Conditions.MarkFalse(
Expand Down Expand Up @@ -595,7 +596,7 @@ func (r *ManilaAPIReconciler) reconcileInit(
instance.Namespace,
ksEndptSpec,
serviceLabels,
time.Duration(10)*time.Second)
manila.NormalDuration)
ctrlResult, err = ksEndptObj.CreateOrPatch(ctx, helper)
if err != nil {
instance.Status.Conditions.MarkFalse(
Expand Down Expand Up @@ -781,7 +782,7 @@ func (r *ManilaAPIReconciler) reconcileNormal(ctx context.Context, instance *man
condition.SeverityInfo,
condition.NetworkAttachmentsReadyWaitingMessage,
netAtt))
return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt)
return manila.ResultRequeue, fmt.Errorf("network-attachment-definition %s not found", netAtt)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
Expand Down Expand Up @@ -813,22 +814,6 @@ func (r *ManilaAPIReconciler) reconcileNormal(ctx context.Context, instance *man
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 @@ -845,7 +830,7 @@ func (r *ManilaAPIReconciler) reconcileNormal(ctx context.Context, instance *man
return ctrl.Result{}, err
}

ss := statefulset.NewStatefulSet(ssDef, time.Duration(5)*time.Second)
ss := statefulset.NewStatefulSet(ssDef, manila.ShortDuration)

ctrlResult, err = ss.CreateOrPatch(ctx, helper)
if err != nil {
Expand Down Expand Up @@ -933,26 +918,6 @@ func (r *ManilaAPIReconciler) reconcileNormal(ctx context.Context, instance *man
return ctrl.Result{}, nil
}

func (r *ManilaAPIReconciler) reconcileUpdate(ctx context.Context, instance *manilav1beta1.ManilaAPI, 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 *ManilaAPIReconciler) reconcileUpgrade(ctx context.Context, instance *manilav1beta1.ManilaAPI, 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
}

// getSecret - get the specified secret, and add its hash to envVars
func (r *ManilaAPIReconciler) getSecret(
ctx context.Context,
Expand All @@ -969,7 +934,7 @@ func (r *ManilaAPIReconciler) getSecret(
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("Secret %s not found", secretName)
return manila.ResultRequeue, fmt.Errorf("Secret %s not found", secretName)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
Expand Down
46 changes: 5 additions & 41 deletions controllers/manilascheduler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"context"
"fmt"
"time"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -105,6 +104,7 @@ func (r *ManilaSchedulerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, nil
}
// Error reading the object - requeue the request.
r.Log.Error(err, fmt.Sprintf("could not fetch ManilaScheduler instance %s", instance.Name))
return ctrl.Result{}, err
}

Expand All @@ -116,6 +116,7 @@ func (r *ManilaSchedulerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
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 @@ -465,7 +466,7 @@ func (r *ManilaSchedulerReconciler) reconcileNormal(ctx context.Context, instanc
condition.SeverityInfo,
condition.NetworkAttachmentsReadyWaitingMessage,
netAtt))
return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt)
return manila.ResultRequeue, fmt.Errorf("network-attachment-definition %s not found", netAtt)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
Expand Down Expand Up @@ -497,30 +498,14 @@ func (r *ManilaSchedulerReconciler) reconcileNormal(ctx context.Context, instanc
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
//

// Deploy a statefulset
ss := statefulset.NewStatefulSet(
manilascheduler.StatefulSet(instance, inputHash, serviceLabels, serviceAnnotations),
time.Duration(5)*time.Second,
manila.ShortDuration,
)

ctrlResult, err = ss.CreateOrPatch(ctx, helper)
Expand Down Expand Up @@ -608,27 +593,6 @@ func (r *ManilaSchedulerReconciler) reconcileNormal(ctx context.Context, instanc
return ctrl.Result{}, nil
}

func (r *ManilaSchedulerReconciler) reconcileUpdate(ctx context.Context, instance *manilav1beta1.ManilaScheduler, 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))
// update the overall status condition if service is ready
return ctrl.Result{}, nil
}

func (r *ManilaSchedulerReconciler) reconcileUpgrade(ctx context.Context, instance *manilav1beta1.ManilaScheduler, 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
}

// getSecret - get the specified secret, and add its hash to envVars
func (r *ManilaSchedulerReconciler) getSecret(
ctx context.Context,
Expand All @@ -645,7 +609,7 @@ func (r *ManilaSchedulerReconciler) getSecret(
condition.RequestedReason,
condition.SeverityInfo,
condition.InputReadyWaitingMessage))
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("Secret %s not found", secretName)
return manila.ResultRequeue, fmt.Errorf("Secret %s not found", secretName)
}
instance.Status.Conditions.Set(condition.FalseCondition(
condition.InputReadyCondition,
Expand Down
Loading

0 comments on commit db99e21

Please sign in to comment.