chinmoysahu commented on code in PR #815:
URL: https://github.com/apache/solr-operator/pull/815#discussion_r2728892649
##########
controllers/solrcloud_controller.go:
##########
@@ -436,6 +441,223 @@ 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
+ }
+ }
+ }
+ }
+
+ // Reconcile BackendTLSPolicy resources if configured
+ if extAddressabilityOpts.HasBackendTLSPolicy() {
+ // Reconcile Common BackendTLSPolicy (if not hidden)
+ if !extAddressabilityOpts.HideCommon {
+ commonPolicy :=
util.GenerateCommonBackendTLSPolicy(instance)
+ if commonPolicy != nil {
+ commonPolicyLogger :=
logger.WithValues("backendtlspolicy", commonPolicy.Name)
+ foundCommonPolicy :=
&gatewayv1.BackendTLSPolicy{}
+ err = r.Get(ctx,
types.NamespacedName{Name: commonPolicy.Name, Namespace:
commonPolicy.Namespace}, foundCommonPolicy)
+
+ if err != nil && errors.IsNotFound(err)
{
+
commonPolicyLogger.Info("Creating BackendTLSPolicy")
+ if err =
controllerutil.SetControllerReference(instance, commonPolicy, r.Scheme); err ==
nil {
+ err = r.Create(ctx,
commonPolicy)
+ }
+ } else if err == nil {
+ var needsUpdate bool
+ needsUpdate, err =
util.OvertakeControllerRef(instance, foundCommonPolicy, r.Scheme)
+ if err == nil &&
util.CopyBackendTLSPolicyFields(commonPolicy, foundCommonPolicy,
commonPolicyLogger) {
+ needsUpdate = true
+ }
+ if needsUpdate {
+
commonPolicyLogger.Info("Updating BackendTLSPolicy")
+ err = r.Update(ctx,
foundCommonPolicy)
+ }
+ }
+ if err != nil {
+ return requeueOrNot, err
+ }
+ }
+ }
+
+ // Reconcile Node BackendTLSPolicies (if not hidden)
+ if !extAddressabilityOpts.HideNodes {
+ for _, nodeName := range solrNodeNames {
+ nodePolicy :=
util.GenerateNodeBackendTLSPolicy(instance, nodeName)
+ if nodePolicy != nil {
+ nodePolicyLogger :=
logger.WithValues("backendtlspolicy", nodePolicy.Name)
+ foundNodePolicy :=
&gatewayv1.BackendTLSPolicy{}
+ err = r.Get(ctx,
types.NamespacedName{Name: nodePolicy.Name, Namespace: nodePolicy.Namespace},
foundNodePolicy)
+
+ if err != nil &&
errors.IsNotFound(err) {
+
nodePolicyLogger.Info("Creating BackendTLSPolicy")
+ if err =
controllerutil.SetControllerReference(instance, nodePolicy, r.Scheme); err ==
nil {
+ err =
r.Create(ctx, nodePolicy)
+ }
+ } else if err == nil {
+ var needsUpdate bool
+ needsUpdate, err =
util.OvertakeControllerRef(instance, foundNodePolicy, r.Scheme)
+ if err == nil &&
util.CopyBackendTLSPolicyFields(nodePolicy, foundNodePolicy, nodePolicyLogger) {
+ needsUpdate =
true
+ }
+ if needsUpdate {
+
nodePolicyLogger.Info("Updating BackendTLSPolicy")
+ err =
r.Update(ctx, foundNodePolicy)
+ }
+ }
+
+ if err != nil {
+ return requeueOrNot, err
+ }
+ }
+ }
+ }
+
+ // Cleanup orphaned node BackendTLSPolicies (when
scaling down)
+ backendTLSPolicyList :=
&gatewayv1.BackendTLSPolicyList{}
+ err = r.List(ctx, backendTLSPolicyList, listOps)
+ if err == nil {
+ for _, policy := range
backendTLSPolicyList.Items {
+ // Skip the common BackendTLSPolicy
+ if policy.Name ==
instance.CommonBackendTLSPolicyName() {
+ continue
+ }
+ // Check if this node still exists
+ nodeExists := false
+ for _, nodeName := range solrNodeNames {
+ if policy.Name ==
instance.NodeBackendTLSPolicyName(nodeName) {
+ nodeExists = true
+ break
+ }
+ }
+ if !nodeExists {
+ logger.Info("Deleting orphaned
BackendTLSPolicy", "backendtlspolicy", policy.Name)
+ err = r.Delete(ctx, &policy)
+ if err != nil &&
!errors.IsNotFound(err) {
+ return requeueOrNot, err
+ }
+ }
+ }
+ }
+ }
Review Comment:
Good catch. Addressed.
##########
tests/e2e/solrcloud_gateway_test.go:
##########
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package e2e
+
+import (
+ "context"
+ solrv1beta1 "github.com/apache/solr-operator/api/v1beta1"
+ "github.com/apache/solr-operator/controllers/util"
+ . "github.com/onsi/ginkgo/v2"
+ . "github.com/onsi/gomega"
+)
+
+var _ = FDescribe("E2E - SolrCloud - Gateway API", func() {
Review Comment:
Addressed.
--
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]