Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Fix service raw configuration #203

Merged
merged 17 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controllers/backstage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions controllers/backstage_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a test case for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, please add note to the issue, will do in a separate PR later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I added a task to issue: #202

}

return nil
}

Expand All @@ -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)

Expand All @@ -75,6 +81,7 @@ func (r *BackstageReconciler) serviceObjectMutFun(ctx context.Context, targetSer

service.ObjectMeta.DeepCopyInto(&targetService.ObjectMeta)
service.Spec.DeepCopyInto(&targetService.Spec)

return nil
}
}
Expand Down
1 change: 1 addition & 0 deletions controllers/local_db_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading