Skip to content

Commit a9ccccf

Browse files
authored
[Feature] Add Gateway Config condition (#1959)
1 parent 565e4e5 commit a9ccccf

File tree

13 files changed

+199
-38
lines changed

13 files changed

+199
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- (Bugfix) Helm Lint Indent fix
88
- (Feature) Add CA Certificates
99
- (Feature) Chart By Tag filter
10+
- (Feature) Add Gateway Config condition
1011

1112
## [1.3.0](https://github.com/arangodb/kube-arangodb/tree/1.3.0) (2025-08-01)
1213
- (Feature) (Platform) Storage Debug

pkg/apis/deployment/v1/conditions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ const (
135135
ConditionTypeDBServerWithData ConditionType = "DBServerWithData"
136136
// ConditionTypeSyncEnabled Define if DBServer contains any active data leaders
137137
ConditionTypeDBServerWithDataLeader ConditionType = "DBServerWithDataLeader"
138+
139+
// ConditionTypeGatewayConfig contains current config checksum of the Gateway
140+
ConditionTypeGatewayConfig ConditionType = "GatewayConfig"
138141
)
139142

140143
// Condition represents one current condition of a deployment or deployment member.

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ const (
135135
ConditionTypeDBServerWithData ConditionType = "DBServerWithData"
136136
// ConditionTypeSyncEnabled Define if DBServer contains any active data leaders
137137
ConditionTypeDBServerWithDataLeader ConditionType = "DBServerWithDataLeader"
138+
139+
// ConditionTypeGatewayConfig contains current config checksum of the Gateway
140+
ConditionTypeGatewayConfig ConditionType = "GatewayConfig"
138141
)
139142

140143
// Condition represents one current condition of a deployment or deployment member.

pkg/deployment/client/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type Client interface {
5757
DeleteExpiredJobs(ctx context.Context, timeout time.Duration) error
5858

5959
Compact(ctx context.Context, request *CompactRequest) error
60+
61+
Inventory(ctx context.Context) (*Inventory, error)
6062
}
6163

6264
type client struct {

pkg/deployment/client/inventory.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 client
22+
23+
import (
24+
"context"
25+
goHttp "net/http"
26+
27+
utilConstants "github.com/arangodb/kube-arangodb/pkg/util/constants"
28+
)
29+
30+
type Inventory struct {
31+
Configuration InventoryConfiguration `json:"configuration"`
32+
}
33+
34+
type InventoryConfiguration struct {
35+
Hash string `json:"hash"`
36+
}
37+
38+
func (c *client) Inventory(ctx context.Context) (*Inventory, error) {
39+
req, err := c.c.NewRequest(goHttp.MethodGet, utilConstants.EnvoyInventoryConfigDestination)
40+
if err != nil {
41+
return nil, err
42+
}
43+
44+
resp, err := c.c.Do(ctx, req)
45+
if err != nil {
46+
return nil, err
47+
}
48+
49+
if err := resp.CheckStatus(goHttp.StatusOK); err != nil {
50+
return nil, err
51+
}
52+
53+
var l Inventory
54+
55+
if err := resp.ParseBody("", &l); err != nil {
56+
return nil, err
57+
}
58+
59+
return &l, nil
60+
}

pkg/deployment/reconcile/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ type Context interface {
4242
reconciler.DeploymentImageManager
4343
reconciler.ArangoAgencyGet
4444
reconciler.ArangoApplier
45-
reconciler.DeploymentInfoGetter
45+
reconciler.DeploymentGetter
4646
reconciler.DeploymentDatabaseClient
4747
reconciler.KubernetesEventGenerator
4848

pkg/deployment/reconcile/plan_builder_context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ import (
3535
type PlanBuilderContext interface {
3636
reconciler.DeploymentStatusUpdate
3737

38-
reconciler.DeploymentInfoGetter
38+
reconciler.DeploymentGetter
3939
reconciler.DeploymentAgencyMaintenance
4040
reconciler.DeploymentPodRenderer
4141
reconciler.DeploymentImageManager
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

pkg/deployment/reconcile/plan_builder_high.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (r *Reconciler) createHighPlan(ctx context.Context, apiObject k8sutil.APIOb
5555
ApplyIfEmpty(r.updateMemberUpdateConditionsPlan).
5656
ApplyIfEmpty(r.updateMemberRotationConditionsPlan).
5757
ApplyIfEmpty(r.createMemberAllowUpgradeConditionPlan).
58+
ApplyIfEmpty(r.createMemberGatewayConfigConditionPlan).
5859
ApplyIfEmpty(r.createMemberRecreationConditionsPlan).
5960
ApplyIfEmpty(r.createMemberPodSchedulingFailurePlan).
6061
ApplyIfEmpty(r.createRotateServerStoragePVCPendingResizeConditionPlan).

pkg/deployment/reconcile/plan_builder_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ type testContext struct {
8282
state member.StateInspector
8383
}
8484

85+
func (c *testContext) GetServerClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error) {
86+
//TODO implement me
87+
panic("implement me")
88+
}
89+
90+
func (c *testContext) GetSyncServerClient(ctx context.Context, group api.ServerGroup, id string) (client.API, error) {
91+
//TODO implement me
92+
panic("implement me")
93+
}
94+
8595
func (c *testContext) IsSyncEnabled() bool {
8696
return false
8797
}

0 commit comments

Comments
 (0)