Skip to content

Commit 7d02c5f

Browse files
authored
[Feature] Topology env propagation (#806)
1 parent 4254057 commit 7d02c5f

File tree

8 files changed

+116
-7
lines changed

8 files changed

+116
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Switch ArangoDB Image Discovery process from Headless Service to Pod IP
77
- Fix PVC Resize for Single servers
88
- Add Topology support
9+
- Add ARANGODB_ZONE env to Topology Managed pods
910

1011
## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24)
1112
- Update UBI Image to 8.4
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 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+
// +build !enterprise
22+
23+
package pod
24+
25+
import (
26+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
27+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
28+
core "k8s.io/api/core/v1"
29+
)
30+
31+
func (t topology) Args(i Input) k8sutil.OptionPairs {
32+
return nil
33+
}
34+
35+
func (t topology) Volumes(i Input) ([]core.Volume, []core.VolumeMount) {
36+
return nil, nil
37+
}
38+
39+
func (t topology) Envs(i Input) []core.EnvVar {
40+
return nil
41+
}
42+
43+
func (t topology) Verify(i Input, cachedStatus interfaces.Inspector) error {
44+
return nil
45+
}

pkg/deployment/pod/topology.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 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 pod
22+
23+
func Topology() Builder {
24+
return topology{}
25+
}
26+
27+
type topology struct{}

pkg/deployment/reconcile/plan_builder_scale.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ func createScaleUPMemberPlan(ctx context.Context,
3535
log zerolog.Logger, apiObject k8sutil.APIObject,
3636
spec api.DeploymentSpec, status api.DeploymentStatus,
3737
cachedStatus inspectorInterface.Inspector, context PlanBuilderContext) api.Plan {
38-
return createScaleMemberPlan(ctx, log, apiObject, spec, status, cachedStatus, context).Filter(func(a api.Action) bool {
39-
return a.Type == api.ActionTypeAddMember
40-
})
38+
return createScaleMemberPlan(ctx, log, apiObject, spec, status, cachedStatus, context).Filter(filterScaleUP)
4139
}
4240

4341
func createScaleMemberPlan(ctx context.Context,
@@ -50,16 +48,17 @@ func createScaleMemberPlan(ctx context.Context,
5048
switch spec.GetMode() {
5149
case api.DeploymentModeSingle:
5250
// Never scale down
51+
plan = append(plan, createScalePlan(log, status, status.Members.Single, api.ServerGroupSingle, 1).Filter(filterScaleUP)...)
5352
case api.DeploymentModeActiveFailover:
5453
// Only scale agents & singles
5554
if a := status.Agency; a != nil && a.Size != nil {
56-
plan = append(plan, createScalePlan(log, status, status.Members.Agents, api.ServerGroupAgents, int(*a.Size))...)
55+
plan = append(plan, createScalePlan(log, status, status.Members.Agents, api.ServerGroupAgents, int(*a.Size)).Filter(filterScaleUP)...)
5756
}
5857
plan = append(plan, createScalePlan(log, status, status.Members.Single, api.ServerGroupSingle, spec.Single.GetCount())...)
5958
case api.DeploymentModeCluster:
6059
// Scale agents, dbservers, coordinators
6160
if a := status.Agency; a != nil && a.Size != nil {
62-
plan = append(plan, createScalePlan(log, status, status.Members.Agents, api.ServerGroupAgents, int(*a.Size))...)
61+
plan = append(plan, createScalePlan(log, status, status.Members.Agents, api.ServerGroupAgents, int(*a.Size)).Filter(filterScaleUP)...)
6362
}
6463
plan = append(plan, createScalePlan(log, status, status.Members.DBServers, api.ServerGroupDBServers, spec.DBServers.GetCount())...)
6564
plan = append(plan, createScalePlan(log, status, status.Members.Coordinators, api.ServerGroupCoordinators, spec.Coordinators.GetCount())...)
@@ -157,3 +156,7 @@ func createReplaceMemberPlan(ctx context.Context,
157156

158157
return plan
159158
}
159+
160+
func filterScaleUP(a api.Action) bool {
161+
return a.Type == api.ActionTypeAddMember
162+
}

pkg/deployment/reconcile/plan_builder_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func TestCreatePlanSingleScale(t *testing.T) {
362362

363363
newPlan, changed := createNormalPlan(ctx, log, depl, nil, spec, status, inspector.NewEmptyInspector(), c)
364364
assert.True(t, changed)
365-
assert.Len(t, newPlan, 0) // Single mode does not scale
365+
assert.Len(t, newPlan, 1)
366366

367367
// Test with 1 single member
368368
status.Members.Single = api.MemberStatusList{
@@ -375,6 +375,12 @@ func TestCreatePlanSingleScale(t *testing.T) {
375375
assert.True(t, changed)
376376
assert.Len(t, newPlan, 0) // Single mode does not scale
377377

378+
spec.Single.Count = util.NewInt(2)
379+
newPlan, changed = createNormalPlan(ctx, log, depl, nil, spec, status, inspector.NewEmptyInspector(), c)
380+
assert.True(t, changed)
381+
assert.Len(t, newPlan, 0) // Single mode does not scale
382+
383+
spec.Single.Count = util.NewInt(1)
378384
// Test with 2 single members (which should not happen) and try to scale down
379385
status.Members.Single = api.MemberStatusList{
380386
api.MemberStatus{
@@ -388,7 +394,7 @@ func TestCreatePlanSingleScale(t *testing.T) {
388394
}
389395
newPlan, changed = createNormalPlan(ctx, log, depl, nil, spec, status, inspector.NewEmptyInspector(), c)
390396
assert.True(t, changed)
391-
assert.Len(t, newPlan, 0) // Single mode does not scale
397+
assert.Len(t, newPlan, 0) // Single mode does not scale down
392398
}
393399

394400
// TestCreatePlanActiveFailoverScale creates a `ActiveFailover` deployment to test the creating of scaling plan.
@@ -664,6 +670,7 @@ func TestCreatePlan(t *testing.T) {
664670
},
665671
Helper: func(ad *api.ArangoDeployment) {
666672
ad.Spec.Mode = api.NewMode(api.DeploymentModeSingle)
673+
ad.Status.Members.Single = append(ad.Status.Members.Single, api.MemberStatus{})
667674
},
668675
ExpectedPlan: []api.Action{},
669676
},

pkg/deployment/resources/pod_creator_arangod.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ func (a *ArangoDContainer) GetEnvs() []core.EnvVar {
191191
}
192192
}
193193

194+
envs.Add(true, pod.Topology().Envs(a.member.AsInput())...)
195+
194196
return envs.GetEnvList()
195197
}
196198

pkg/deployment/rotation/arangod_containers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func containersCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *co
7171
return
7272
}
7373
}
74+
7475
func initContainersCompare(deploymentSpec api.DeploymentSpec, group api.ServerGroup, spec, status *core.PodSpec) compareFunc {
7576
return func(builder api.ActionBuilder) (mode Mode, plan api.Plan, err error) {
7677
gs := deploymentSpec.GetServerGroupSpec(group)

pkg/deployment/topology/const.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 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 topology
22+
23+
var ArangoDBZone = "ARANGODB_ZONE"

0 commit comments

Comments
 (0)