Skip to content

Commit

Permalink
Initialize route to prevent nil pointer deref
Browse files Browse the repository at this point in the history
Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed May 31, 2024
1 parent 1e23cab commit a368cc8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/openstack/horizon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/route"
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"

Expand Down Expand Up @@ -82,6 +83,20 @@ func ReconcileHorizon(ctx context.Context, instance *corev1beta1.OpenStackContro
//
apiOverrides := instance.Spec.Horizon.APIOverride

// Initialize Route if nil
if apiOverrides.Route == nil {
apiOverrides.Route = &route.OverrideSpec{}
}

if apiOverrides.Route.EmbeddedLabelsAnnotations == nil {
apiOverrides.Route.EmbeddedLabelsAnnotations = &route.EmbeddedLabelsAnnotations{}
}

// Initialize the annotations map if it is nil
if apiOverrides.Route.Annotations == nil {
apiOverrides.Route.Annotations = map[string]string{}
}

if _, ok := apiOverrides.Route.Annotations[HorizonHSTSHeaderAnnotation]; !ok {
apiOverrides.Route.Annotations[HorizonHSTSHeaderAnnotation] = HorizonHSTSHeaderAnnotationValue
}
Expand Down

0 comments on commit a368cc8

Please sign in to comment.