From 8455474efd0ce0c2a4718d2b57ad19de96572347 Mon Sep 17 00:00:00 2001 From: Brendan Shephard Date: Mon, 26 Jun 2023 08:11:35 +1000 Subject: [PATCH] Add ability to set Horizon route annotation This change adds the ability to set annotations on the Horizon route. This can be leveraged as per the OpenShift documentation: https://docs.openshift.com/container-platform/4.13/networking/routes/route-configuration.html#nw-route-specific-annotations_route-configuration Depends-On: https://github.com/openstack-k8s-operators/lib-common/pull/288 Signed-off-by: Brendan Shephard --- api/v1beta1/horizon_types.go | 5 +++++ api/v1beta1/zz_generated.deepcopy.go | 9 ++++++++- config/crd/bases/horizon.openstack.org_horizons.yaml | 6 ++++++ controllers/horizon_controller.go | 6 ++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/api/v1beta1/horizon_types.go b/api/v1beta1/horizon_types.go index 14637975..4bc54b73 100644 --- a/api/v1beta1/horizon_types.go +++ b/api/v1beta1/horizon_types.go @@ -103,6 +103,11 @@ type HorizonDebug struct { // HorizonRoute is used to define all of the information for the OpenShift route // todo(bshephar) implement type HorizonRoute struct { + // +kubebuilder:validation:Optional + // RouteAnnotations takes a map of Annotations that will be applied to the + // Horizon OpenShift Route. + RouteAnnotations map[string]string `json:"routeAnnotations,omitempty"` + // +kubebuilder:validation:Optional // +kubebuilder:default=horizon RouteName string `json:"routeName,omitempty"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index ec8e88b7..07c9da10 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -118,6 +118,13 @@ func (in *HorizonList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HorizonRoute) DeepCopyInto(out *HorizonRoute) { *out = *in + if in.RouteAnnotations != nil { + in, out := &in.RouteAnnotations, &out.RouteAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HorizonRoute. @@ -149,7 +156,7 @@ func (in *HorizonSpec) DeepCopyInto(out *HorizonSpec) { } } in.Resources.DeepCopyInto(&out.Resources) - out.Route = in.Route + in.Route.DeepCopyInto(&out.Route) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HorizonSpec. diff --git a/config/crd/bases/horizon.openstack.org_horizons.yaml b/config/crd/bases/horizon.openstack.org_horizons.yaml index 474b34ae..ef0add67 100644 --- a/config/crd/bases/horizon.openstack.org_horizons.yaml +++ b/config/crd/bases/horizon.openstack.org_horizons.yaml @@ -145,6 +145,12 @@ spec: Implement everything about this. It's just a placeholder at the moment. properties: + routeAnnotations: + additionalProperties: + type: string + description: RouteAnnotations takes a map of Annotations that + will be applied to the Horizon OpenShift Route. + type: object routeLocation: description: TODO(bshephar) We need to implement TLS handling here to secure the route diff --git a/controllers/horizon_controller.go b/controllers/horizon_controller.go index 4cb8c93f..3fd8aba2 100644 --- a/controllers/horizon_controller.go +++ b/controllers/horizon_controller.go @@ -235,6 +235,11 @@ func (r *HorizonReconciler) reconcileInit( Port: horizon.HorizonPublicPort, }, } + + var routeAnnotations = map[string]string{} + if len(instance.Spec.Route.RouteAnnotations) != 0 { + routeAnnotations = instance.Spec.Route.RouteAnnotations + } apiEndpoints, ctrlResult, err := endpoint.ExposeEndpoints( ctx, @@ -242,6 +247,7 @@ func (r *HorizonReconciler) reconcileInit( horizon.ServiceName, serviceLabels, horizonPorts, + routeAnnotations, time.Duration(5)*time.Second, ) if err != nil {