Commit 91eacd33 authored by Dimitra Chatzichrysou's avatar Dimitra Chatzichrysou
Browse files

Improve reconcile loop and logs

parent fdfdd66b
Pipeline #3328270 passed with stages
in 5 minutes and 33 seconds
......@@ -13,16 +13,17 @@ var (
ErrInvalidSpec = errors.New("InvalidSpec")
// ErrFunctionDomain can be returned by a function that was passed invalid arguments, such as the default case of a switch.
// Consider constraining the arg type.
ErrFunctionDomain = errors.New("FunctionDomainError")
ErrClientK8s = errors.New("k8sAPIClientError")
ErrPodExec = errors.New("ExecInPodError")
ErrFilesystemIO = errors.New("FilesystemIOError")
ErrDBOD = errors.New("DBODError")
ErrBuildFailed = errors.New("BuildError")
ErrDeploymentUpdateFailed = errors.New("DeploymentUpdateError")
ErrDBUpdateFailed = errors.New("DBUpdateError")
ErrRollBack = errors.New("RollbackError")
ErrPodNotRunning = errors.New("PodNotRunning")
ErrFunctionDomain = errors.New("FunctionDomainError")
ErrClientK8s = errors.New("k8sAPIClientError")
ErrPodExec = errors.New("ExecInPodError")
ErrFilesystemIO = errors.New("FilesystemIOError")
ErrDBOD = errors.New("DBODError")
ErrBuildFailed = errors.New("BuildError")
ErrDeploymentUpdateFailed = errors.New("DeploymentUpdateError")
ErrDBUpdateFailed = errors.New("DBUpdateError")
ErrRollBack = errors.New("RollbackError")
ErrPodNotRunning = errors.New("PodNotRunning")
ErrSupportedDrupalVersionsNone = errors.New("SupportedDrupalVersionsNoneError")
)
type reconcileError interface {
......
......@@ -79,7 +79,7 @@ func (r *SupportedDrupalVersionsReconciler) SetupWithManager(mgr ctrl.Manager) e
// SetupWithManager sets up the controller with the Manager.
func (r *SupportedDrupalVersionsReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.Log.WithValues("Request.Namespace", req.NamespacedName, "Request.Name", req.Name)
log.V(1).Info("Updating version")
log.V(1).Info("Updating SupportedDrupalVersions resource")
drupalVersionsList := &drupalwebservicesv1alpha1.SupportedDrupalVersionsList{}
err := r.Client.List(ctx, drupalVersionsList)
......@@ -87,11 +87,22 @@ func (r *SupportedDrupalVersionsReconciler) Reconcile(ctx context.Context, req c
return ctrl.Result{}, err
}
// We only expect exactly one DrupalVersions in the cluster
if len(drupalVersionsList.Items) > 1 {
log.V(1).Info("Note: We currently support 1 DrupalVersions, but currently there is %d", len(drupalVersionsList.Items))
if len(drupalVersionsList.Items) == 0 {
err := newApplicationError(errors.New("fetching supported-drupal-versions failed"), ErrSupportedDrupalVersionsNone)
log.Error(err, "There isn't any SupportedDrupalVersions resource")
return ctrl.Result{}, err
}
// We only expect exactly one SupportedDrupalVersions resource in the cluster
drupalVersions := drupalVersionsList.Items[0]
if len(drupalVersionsList.Items) > 1 {
log.V(1).Info(fmt.Sprintf("Note: We support only 1 SupportedDrupalVersions resource, but currently there are %d", len(drupalVersionsList.Items)))
for _, item := range drupalVersionsList.Items {
if item.Name == "supported-drupal-versions" {
drupalVersions = item
}
}
}
registryAPISecret, err := r.getRegistryAPISecret(ctx)
if err != nil {
......@@ -222,7 +233,7 @@ func getRegistryTags(registryAPISecret string) ([]string, error) {
var tags Tags
err = json.Unmarshal(body, &tags)
if err != nil {
log.Error(err, "Unable to parse value: %q, error: %s", string(body), err.Error())
log.Error(err, fmt.Sprintf("Unable to parse value: %q", string(body)))
}
tagNames := []string{}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment