From 230c46a5438772508823eec9d4ca20691510b5b2 Mon Sep 17 00:00:00 2001 From: Brendan Shephard Date: Fri, 29 Sep 2023 11:10:20 +1000 Subject: [PATCH] Add route lookup and update status.endpoint This commit adds a route lookup and then uses the returned value to update the instance.Status.Endpoint value. Signed-off-by: Brendan Shephard --- controllers/horizon_controller.go | 11 +++++++++-- go.mod | 2 +- main.go | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/controllers/horizon_controller.go b/controllers/horizon_controller.go index 782e9fae..e821eae7 100644 --- a/controllers/horizon_controller.go +++ b/controllers/horizon_controller.go @@ -56,6 +56,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" + + routev1 "github.com/openshift/api/route/v1" ) // GetClient - @@ -342,7 +344,7 @@ func (r *HorizonReconciler) reconcileInit( // create service - end // TODO: TLS, pass in https as protocol - apiEndpoint, err := svc.GetAPIEndpoint( + _, err = svc.GetAPIEndpoint( svcOverride.EndpointURL, ptr.To(service.ProtocolHTTP), "") if err != nil { return ctrl.Result{}, err @@ -352,7 +354,12 @@ func (r *HorizonReconciler) reconcileInit( // // Update instance status with service endpoint url information // - instance.Status.Endpoint = apiEndpoint + horizonRoute := routev1.Route{} + err = r.Client.Get(ctx, types.NamespacedName{Namespace: instance.Namespace, Name: instance.Name}, &horizonRoute) + if err != nil { + return ctrl.Result{}, fmt.Errorf("Failed to get Horizon route info: %w", err) + } + instance.Status.Endpoint = horizonRoute.Spec.Host // expose service - end diff --git a/go.mod b/go.mod index e90a62af..097e930e 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/google/uuid v1.3.1 github.com/onsi/ginkgo/v2 v2.12.1 github.com/onsi/gomega v1.27.10 + github.com/openshift/api v3.9.0+incompatible github.com/openstack-k8s-operators/horizon-operator/api v0.1.1-0.20230828060631-f5678c16313e github.com/openstack-k8s-operators/infra-operator/apis v0.1.1-0.20230926144332-61ec188379c1 github.com/openstack-k8s-operators/keystone-operator/api v0.1.1-0.20230925133339-116a3a39cdfa @@ -51,7 +52,6 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/openshift/api v3.9.0+incompatible // indirect github.com/openstack-k8s-operators/lib-common/modules/openstack v0.1.1-0.20230927082538-4f614f333d17 // indirect github.com/openstack-k8s-operators/mariadb-operator/api v0.1.1-0.20230918111825-8999b3b2dc3c // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/main.go b/main.go index 4654c406..3aabfce3 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,8 @@ import ( horizonv1beta1 "github.com/openstack-k8s-operators/horizon-operator/api/v1beta1" "github.com/openstack-k8s-operators/horizon-operator/controllers" + + routev1 "github.com/openshift/api/route/v1" //+kubebuilder:scaffold:imports ) @@ -53,6 +55,7 @@ func init() { utilruntime.Must(horizonv1beta1.AddToScheme(scheme)) utilruntime.Must(keystonev1.AddToScheme(scheme)) utilruntime.Must(memcachedv1.AddToScheme(scheme)) + utilruntime.Must(routev1.AddToScheme(scheme)) //+kubebuilder:scaffold:scheme }