@@ -26,6 +26,7 @@ import (
2626 k8s_errors "k8s.io/apimachinery/pkg/api/errors"
2727 "k8s.io/apimachinery/pkg/fields"
2828 "k8s.io/apimachinery/pkg/types"
29+ "k8s.io/utils/ptr"
2930 ctrl "sigs.k8s.io/controller-runtime"
3031 "sigs.k8s.io/controller-runtime/pkg/builder"
3132 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -38,9 +39,11 @@ import (
3839 "github.com/go-logr/logr"
3940 memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
4041 topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
42+ keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
4143 common "github.com/openstack-k8s-operators/lib-common/modules/common"
4244 "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
4345 "github.com/openstack-k8s-operators/lib-common/modules/common/cronjob"
46+ "github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
4447 "github.com/openstack-k8s-operators/lib-common/modules/common/env"
4548 helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
4649 job "github.com/openstack-k8s-operators/lib-common/modules/common/job"
@@ -179,6 +182,22 @@ func (r *NovaConductorReconciler) Reconcile(ctx context.Context, req ctrl.Reques
179182 // detect if something is changed.
180183 hashes := make (map [string ]env.Setter )
181184
185+ // hash the endpoint URLs of the services this depends on
186+ // By adding the hash to the hash of hashes being added to the deployment
187+ // allows it to get restarted, in case the endpoint changes and it requires
188+ // the current cached ones to be updated.
189+ endpointUrlsHash , err := keystonev1 .GetHashforKeystoneEndpointUrlsForServices (
190+ ctx ,
191+ h ,
192+ instance .Namespace ,
193+ ptr .To (string (endpoint .EndpointInternal )),
194+ endpointList ,
195+ )
196+ if err != nil {
197+ return ctrl.Result {}, err
198+ }
199+ hashes ["endpointUrlsHash" ] = env .SetValue (endpointUrlsHash )
200+
182201 requiredSecretFields := []string {
183202 ServicePasswordSelector ,
184203 TransportURLSelector ,
@@ -698,6 +717,40 @@ func (r *NovaConductorReconciler) findObjectsForSrc(ctx context.Context, src cli
698717 return requests
699718}
700719
720+ func (r * NovaConductorReconciler ) findObjectsWithAppSelectorLabelInNamespace (ctx context.Context , src client.Object ) []reconcile.Request {
721+ requests := []reconcile.Request {}
722+
723+ l := log .FromContext (ctx ).WithName ("Controllers" ).WithName ("NovaConductor" )
724+
725+ // if the endpoint has the service label and its in our endpointList, reconcile the CR in the namespace
726+ if svc , ok := src .GetLabels ()[common .AppSelector ]; ok && util .StringInSlice (svc , endpointList ) {
727+ crList := & novav1.NovaConductorList {}
728+ listOps := & client.ListOptions {
729+ Namespace : src .GetNamespace (),
730+ }
731+ err := r .Client .List (ctx , crList , listOps )
732+ if err != nil {
733+ l .Error (err , fmt .Sprintf ("listing %s for namespace: %s" , crList .GroupVersionKind ().Kind , src .GetNamespace ()))
734+ return requests
735+ }
736+
737+ for _ , item := range crList .Items {
738+ l .Info (fmt .Sprintf ("input source %s changed, reconcile: %s - %s" , src .GetName (), item .GetName (), item .GetNamespace ()))
739+
740+ requests = append (requests ,
741+ reconcile.Request {
742+ NamespacedName : types.NamespacedName {
743+ Name : item .GetName (),
744+ Namespace : item .GetNamespace (),
745+ },
746+ },
747+ )
748+ }
749+ }
750+
751+ return requests
752+ }
753+
701754// fields to index to reconcile when change
702755var (
703756 cdWatchFields = []string {
@@ -834,5 +887,8 @@ func (r *NovaConductorReconciler) SetupWithManager(mgr ctrl.Manager) error {
834887 Watches (& topologyv1.Topology {},
835888 handler .EnqueueRequestsFromMapFunc (r .findObjectsForSrc ),
836889 builder .WithPredicates (predicate.GenerationChangedPredicate {})).
890+ Watches (& keystonev1.KeystoneEndpoint {},
891+ handler .EnqueueRequestsFromMapFunc (r .findObjectsWithAppSelectorLabelInNamespace ),
892+ builder .WithPredicates (keystonev1 .KeystoneEndpointStatusChangedPredicate )).
837893 Complete (r )
838894}
0 commit comments