diff --git a/controllers/backstage_controller.go b/controllers/backstage_controller.go index e3c2a65c..3cffea8c 100644 --- a/controllers/backstage_controller.go +++ b/controllers/backstage_controller.go @@ -183,13 +183,13 @@ func (r *BackstageReconciler) readConfigMapOrDefault(ctx context.Context, name s val, ok := cm.Data[key] if !ok { // key not found, default - lg.V(1).Info("custom configuration configMap and data exists, trying to apply it", "configMap", cm.Name, "key", key) + lg.V(1).Info("custom configuration configMap exists but no such key, applying default config", "configMap", cm.Name, "key", key) err := readYamlFile(defFile(key), object) if err != nil { return fmt.Errorf("failed to read YAML file: %w", err) } } else { - lg.V(1).Info("custom configuration configMap exists but no such key, applying default config", "configMap", cm.Name, "key", key) + lg.V(1).Info("custom configuration configMap and data exists, trying to apply it", "configMap", cm.Name, "key", key) err := readYaml([]byte(val), object) if err != nil { return fmt.Errorf("failed to read YAML: %w", err) diff --git a/controllers/backstage_service.go b/controllers/backstage_service.go index 1176f732..f479a2bb 100644 --- a/controllers/backstage_service.go +++ b/controllers/backstage_service.go @@ -33,14 +33,19 @@ func (r *BackstageReconciler) reconcileBackstageService(ctx context.Context, bac Namespace: ns, }, } + if _, err := controllerutil.CreateOrUpdate(ctx, r.Client, service, r.serviceObjectMutFun(ctx, service, *backstage, backstage.Spec.RawRuntimeConfig.BackstageConfigName, "service.yaml", service.Name, service.Name)); err != nil { + if errors.IsConflict(err) { return retryReconciliation(err) } msg := fmt.Sprintf("failed to deploy Backstage Service: %s", err) + setStatusCondition(backstage, bs.ConditionDeployed, metav1.ConditionFalse, bs.DeployFailed, msg) + return fmt.Errorf("%s %w", msg, err) } + return nil } @@ -49,6 +54,7 @@ func (r *BackstageReconciler) reconcileBackstageService(ctx context.Context, bac func (r *BackstageReconciler) serviceObjectMutFun(ctx context.Context, targetService *corev1.Service, backstage bs.Backstage, configName, configKey, serviceName, label string) controllerutil.MutateFn { return func() error { + service := &corev1.Service{} targetService.ObjectMeta.DeepCopyInto(&service.ObjectMeta) @@ -75,6 +81,7 @@ func (r *BackstageReconciler) serviceObjectMutFun(ctx context.Context, targetSer service.ObjectMeta.DeepCopyInto(&targetService.ObjectMeta) service.Spec.DeepCopyInto(&targetService.Spec) + return nil } } diff --git a/controllers/local_db_services.go b/controllers/local_db_services.go index a64441e5..51418bc8 100644 --- a/controllers/local_db_services.go +++ b/controllers/local_db_services.go @@ -85,6 +85,7 @@ func (r *BackstageReconciler) reconcilePsqlService(ctx context.Context, backstag } msg := fmt.Sprintf("failed to deploy database service: %s", err) setStatusCondition(backstage, bs.ConditionDeployed, metav1.ConditionFalse, bs.DeployFailed, msg) + return fmt.Errorf("%s %w", msg, err) } return nil }