|  | 
|  | 1 | +// | 
|  | 2 | +// DISCLAIMER | 
|  | 3 | +// | 
|  | 4 | +// Copyright 2025 ArangoDB GmbH, Cologne, Germany | 
|  | 5 | +// | 
|  | 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 7 | +// you may not use this file except in compliance with the License. | 
|  | 8 | +// You may obtain a copy of the License at | 
|  | 9 | +// | 
|  | 10 | +// http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 11 | +// | 
|  | 12 | +// Unless required by applicable law or agreed to in writing, software | 
|  | 13 | +// distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 15 | +// See the License for the specific language governing permissions and | 
|  | 16 | +// limitations under the License. | 
|  | 17 | +// | 
|  | 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany | 
|  | 19 | +// | 
|  | 20 | + | 
|  | 21 | +package reconcile | 
|  | 22 | + | 
|  | 23 | +import ( | 
|  | 24 | +	"context" | 
|  | 25 | +	"time" | 
|  | 26 | + | 
|  | 27 | +	core "k8s.io/api/core/v1" | 
|  | 28 | + | 
|  | 29 | +	api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" | 
|  | 30 | +	client "github.com/arangodb/kube-arangodb/pkg/deployment/client" | 
|  | 31 | +	sharedReconcile "github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared" | 
|  | 32 | +	"github.com/arangodb/kube-arangodb/pkg/util/k8sutil" | 
|  | 33 | +) | 
|  | 34 | + | 
|  | 35 | +func (r *Reconciler) createMemberGatewayConfigConditionPlan(ctx context.Context, _ k8sutil.APIObject, _ api.DeploymentSpec, | 
|  | 36 | +	status api.DeploymentStatus, planCtx PlanBuilderContext) api.Plan { | 
|  | 37 | +	var plan api.Plan | 
|  | 38 | + | 
|  | 39 | +	// Check for members in failed state. | 
|  | 40 | +	for _, m := range status.Members.AsListInGroup(api.ServerGroupGateways) { | 
|  | 41 | +		inv, err := r.getGatewayInventoryConfig(ctx, planCtx, m.Group, m.Member) | 
|  | 42 | +		if err != nil { | 
|  | 43 | +			if c, ok := m.Member.Conditions.Get(api.ConditionTypeGatewayConfig); !ok || c.Status == core.ConditionTrue { | 
|  | 44 | +				plan = append(plan, sharedReconcile.UpdateMemberConditionActionV2("Config is not present", api.ConditionTypeGatewayConfig, m.Group, m.Member.ID, false, "Config is not present", "Config is not present", "")) | 
|  | 45 | +			} | 
|  | 46 | + | 
|  | 47 | +			continue | 
|  | 48 | +		} | 
|  | 49 | + | 
|  | 50 | +		logger.JSON("inv", inv).Info("Inventory Fetched") | 
|  | 51 | + | 
|  | 52 | +		if c, ok := m.Member.Conditions.Get(api.ConditionTypeGatewayConfig); !ok || c.Status == core.ConditionFalse || c.Hash != inv.Configuration.Hash { | 
|  | 53 | +			plan = append(plan, sharedReconcile.UpdateMemberConditionActionV2("Config Present", api.ConditionTypeGatewayConfig, m.Group, m.Member.ID, true, "Config Present", "Config Present", inv.Configuration.Hash)) | 
|  | 54 | +		} | 
|  | 55 | +	} | 
|  | 56 | + | 
|  | 57 | +	return plan | 
|  | 58 | +} | 
|  | 59 | + | 
|  | 60 | +func (r *Reconciler) getGatewayInventoryConfig(ctx context.Context, planCtx PlanBuilderContext, group api.ServerGroup, member api.MemberStatus) (*client.Inventory, error) { | 
|  | 61 | +	serverClient, err := planCtx.GetServerClient(ctx, group, member.ID) | 
|  | 62 | +	if err != nil { | 
|  | 63 | +		return nil, err | 
|  | 64 | +	} | 
|  | 65 | + | 
|  | 66 | +	internalClient := client.NewClient(serverClient.Connection(), logger) | 
|  | 67 | + | 
|  | 68 | +	lCtx, c := context.WithTimeout(ctx, 500*time.Millisecond) | 
|  | 69 | +	defer c() | 
|  | 70 | + | 
|  | 71 | +	return internalClient.Inventory(lCtx) | 
|  | 72 | +} | 
0 commit comments