diff --git a/internal/controllers/ingresses.go b/internal/controllers/ingresses.go index 958bfe10c..fa8bc347b 100644 --- a/internal/controllers/ingresses.go +++ b/internal/controllers/ingresses.go @@ -117,6 +117,43 @@ func (r *Reconciler) createOrUpdateIngress(ctx context.Context, ingress *netv1.I return ingress, nil } +func configureCoreIngress(cr *model.CryostatInstance) *operatorv1beta1.NetworkConfiguration { + var config *operatorv1beta1.NetworkConfiguration + if cr.Spec.NetworkOptions == nil || cr.Spec.NetworkOptions.CoreConfig == nil { + config = &operatorv1beta1.NetworkConfiguration{} + } else { + config = cr.Spec.NetworkOptions.CoreConfig + } + + configureRoute(config, cr.Name, "cryostat") + return config +} + +func configureGrafanaIngress(cr *model.CryostatInstance) *operatorv1beta1.NetworkConfiguration { + var config *operatorv1beta1.NetworkConfiguration + if cr.Spec.NetworkOptions == nil || cr.Spec.NetworkOptions.GrafanaConfig == nil { + config = &operatorv1beta1.NetworkConfiguration{} + } else { + config = cr.Spec.NetworkOptions.GrafanaConfig + } + + configureRoute(config, cr.Name, "cryostat") + return config +} + +func configureIngress(config *operatorv1beta1.NetworkConfiguration, appLabel string, componentLabel string) { + if config.Labels == nil { + config.Labels = map[string]string{} + } + if config.Annotations == nil { + config.Annotations = map[string]string{} + } + + // Add required labels, overriding any user-specified labels with the same keys + config.Labels["app"] = appLabel + config.Labels["component"] = componentLabel +} + func (r *Reconciler) deleteIngress(ctx context.Context, ingress *netv1.Ingress) error { err := r.Client.Delete(ctx, ingress) if err != nil && !errors.IsNotFound(err) { diff --git a/internal/controllers/services.go b/internal/controllers/services.go index 3f79d0a1a..222788481 100644 --- a/internal/controllers/services.go +++ b/internal/controllers/services.go @@ -248,7 +248,6 @@ func (r *Reconciler) createOrUpdateService(ctx context.Context, svc *corev1.Serv // Update labels and annotations mergeLabelsAndAnnotations(&svc.ObjectMeta, config.Labels, config.Annotations) - svc.Annotations = config.Annotations // Set the Cryostat CR as controller if err := controllerutil.SetControllerReference(owner, svc, r.Scheme); err != nil { return err diff --git a/internal/test/resources.go b/internal/test/resources.go index 364d51c7f..84fbece8b 100644 --- a/internal/test/resources.go +++ b/internal/test/resources.go @@ -2095,8 +2095,7 @@ func (r *TestResources) newRoute(name string, port int) *routev1.Route { Name: name, Namespace: r.Namespace, Labels: map[string]string{ - "app": r.Name, - "component": "cryostat"}, + "app": r.Name}, }, Spec: routev1.RouteSpec{ To: routev1.RouteTargetReference{