chinmoysahu commented on code in PR #815:
URL: https://github.com/apache/solr-operator/pull/815#discussion_r3355856211
##########
controllers/solrcloud_controller.go:
##########
@@ -436,6 +441,273 @@ func (r *SolrCloudReconciler) Reconcile(ctx
context.Context, req ctrl.Request) (
}
}
+ // Reconcile Gateway API HTTPRoutes
+ if extAddressabilityOpts != nil && extAddressabilityOpts.Method ==
solrv1beta1.Gateway {
+ // Validate that gateway config is provided
+ if extAddressabilityOpts.Gateway == nil ||
len(extAddressabilityOpts.Gateway.ParentRefs) == 0 {
+ return requeueOrNot, fmt.Errorf("gateway.parentRefs is
required when using method=Gateway")
+ }
+
+ // Reconcile Common HTTPRoute (if not hidden)
+ if !extAddressabilityOpts.HideCommon {
+ commonHTTPRoute :=
util.GenerateCommonHTTPRoute(instance, solrNodeNames)
+ commonHTTPRouteLogger := logger.WithValues("httproute",
commonHTTPRoute.Name)
+ foundCommonHTTPRoute := &gatewayv1.HTTPRoute{}
+ err = r.Get(ctx, types.NamespacedName{Name:
commonHTTPRoute.Name, Namespace: commonHTTPRoute.Namespace},
foundCommonHTTPRoute)
+ if err != nil && errors.IsNotFound(err) {
+ commonHTTPRouteLogger.Info("Creating common
HTTPRoute")
+ if err =
controllerutil.SetControllerReference(instance, commonHTTPRoute, r.Scheme); err
== nil {
+ err = r.Create(ctx, commonHTTPRoute)
+ }
+ } else if err == nil {
+ var needsUpdate bool
+ needsUpdate, err =
util.OvertakeControllerRef(instance, foundCommonHTTPRoute, r.Scheme)
+ needsUpdate =
util.CopyHTTPRouteFields(commonHTTPRoute, foundCommonHTTPRoute,
commonHTTPRouteLogger) || needsUpdate
+
+ if needsUpdate && err == nil {
+ commonHTTPRouteLogger.Info("Updating
common HTTPRoute")
+ err = r.Update(ctx,
foundCommonHTTPRoute)
+ }
+ }
+ if err != nil {
+ return requeueOrNot, err
+ }
+ } else {
+ // Delete common HTTPRoute if it exists but should be
hidden
+ foundCommonHTTPRoute := &gatewayv1.HTTPRoute{}
+ err := r.Get(ctx, types.NamespacedName{Name:
instance.CommonHTTPRouteName(), Namespace: instance.GetNamespace()},
foundCommonHTTPRoute)
+ if err == nil {
+ logger.Info("Deleting common HTTPRoute
(hideCommon=true)")
+ err = r.Delete(ctx, foundCommonHTTPRoute)
+ if err != nil && !errors.IsNotFound(err) {
+ return requeueOrNot, err
+ }
+ }
+ }
+
+ // Reconcile Node HTTPRoutes (if not hidden)
+ if !extAddressabilityOpts.HideNodes {
+ for _, nodeName := range solrNodeNames {
+ nodeHTTPRoute :=
util.GenerateNodeHTTPRoute(instance, nodeName)
+ nodeHTTPRouteLogger :=
logger.WithValues("httproute", nodeHTTPRoute.Name)
+ foundNodeHTTPRoute := &gatewayv1.HTTPRoute{}
+ err = r.Get(ctx, types.NamespacedName{Name:
nodeHTTPRoute.Name, Namespace: nodeHTTPRoute.Namespace}, foundNodeHTTPRoute)
+ if err != nil && errors.IsNotFound(err) {
+ nodeHTTPRouteLogger.Info("Creating node
HTTPRoute")
+ if err =
controllerutil.SetControllerReference(instance, nodeHTTPRoute, r.Scheme); err
== nil {
+ err = r.Create(ctx,
nodeHTTPRoute)
+ }
+ } else if err == nil {
+ var needsUpdate bool
+ needsUpdate, err =
util.OvertakeControllerRef(instance, foundNodeHTTPRoute, r.Scheme)
+ needsUpdate =
util.CopyHTTPRouteFields(nodeHTTPRoute, foundNodeHTTPRoute,
nodeHTTPRouteLogger) || needsUpdate
+
+ if needsUpdate && err == nil {
+
nodeHTTPRouteLogger.Info("Updating node HTTPRoute")
+ err = r.Update(ctx,
foundNodeHTTPRoute)
+ }
+ }
+ if err != nil {
+ return requeueOrNot, err
+ }
+ }
+ }
+
+ // Cleanup orphaned node HTTPRoutes (when scaling down)
+ httpRouteList := &gatewayv1.HTTPRouteList{}
+ labelSelector := labels.SelectorFromSet(instance.SharedLabels())
+ listOps := &client.ListOptions{
+ Namespace: instance.Namespace,
+ LabelSelector: labelSelector,
+ }
+ err = r.List(ctx, httpRouteList, listOps)
+ if err == nil {
+ for _, httpRoute := range httpRouteList.Items {
+ // Skip the common HTTPRoute
+ if httpRoute.Name ==
instance.CommonHTTPRouteName() {
+ continue
+ }
+ // Check if this node still exists
+ nodeExists := false
+ for _, nodeName := range solrNodeNames {
+ if httpRoute.Name ==
instance.NodeHTTPRouteName(nodeName) {
+ nodeExists = true
+ break
+ }
+ }
+ // Delete orphaned HTTPRoute
+ if !nodeExists {
+ logger.Info("Deleting orphaned node
HTTPRoute", "httproute", httpRoute.Name)
+ err = r.Delete(ctx, &httpRoute)
+ if err != nil &&
!errors.IsNotFound(err) {
+ return requeueOrNot, err
+ }
+ }
Review Comment:
Fixed in the latest commit - The cleanup now deletes all non-common
HTTPRoutes when hideNodes=true, matching the BackendTLSPolicy cleanup pattern.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]