Skip to content

Commit

Permalink
Add route lookup and update status.endpoint
Browse files Browse the repository at this point in the history
This commit adds a route lookup and then uses the returned value to
update the instance.Status.Endpoint value.

Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Sep 29, 2023
1 parent e0a30ad commit 230c46a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions controllers/horizon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
}

Expand Down

0 comments on commit 230c46a

Please sign in to comment.