Skip to content

Commit

Permalink
configure Ingresses
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Aug 28, 2023
1 parent 5bfc747 commit a21700c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
37 changes: 37 additions & 0 deletions internal/controllers/ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion internal/controllers/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions internal/test/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit a21700c

Please sign in to comment.