1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-15 17:51:03 +00:00

[Feature] Topology env propagation (#806)

This commit is contained in:
Adam Janikowski 2021-10-06 16:20:19 +02:00 committed by GitHub
parent 4254057822
commit 7d02c5f588
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 116 additions and 7 deletions

View file

@ -6,6 +6,7 @@
- Switch ArangoDB Image Discovery process from Headless Service to Pod IP - Switch ArangoDB Image Discovery process from Headless Service to Pod IP
- Fix PVC Resize for Single servers - Fix PVC Resize for Single servers
- Add Topology support - Add Topology support
- Add ARANGODB_ZONE env to Topology Managed pods
## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24) ## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24)
- Update UBI Image to 8.4 - Update UBI Image to 8.4

View file

@ -0,0 +1,45 @@
//
// DISCLAIMER
//
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
//
// Licensed 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// +build !enterprise
package pod
import (
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
core "k8s.io/api/core/v1"
)
func (t topology) Args(i Input) k8sutil.OptionPairs {
return nil
}
func (t topology) Volumes(i Input) ([]core.Volume, []core.VolumeMount) {
return nil, nil
}
func (t topology) Envs(i Input) []core.EnvVar {
return nil
}
func (t topology) Verify(i Input, cachedStatus interfaces.Inspector) error {
return nil
}

View file

@ -0,0 +1,27 @@
//
// DISCLAIMER
//
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
//
// Licensed 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package pod
func Topology() Builder {
return topology{}
}
type topology struct{}

View file

@ -35,9 +35,7 @@ func createScaleUPMemberPlan(ctx context.Context,
log zerolog.Logger, apiObject k8sutil.APIObject, log zerolog.Logger, apiObject k8sutil.APIObject,
spec api.DeploymentSpec, status api.DeploymentStatus, spec api.DeploymentSpec, status api.DeploymentStatus,
cachedStatus inspectorInterface.Inspector, context PlanBuilderContext) api.Plan { cachedStatus inspectorInterface.Inspector, context PlanBuilderContext) api.Plan {
return createScaleMemberPlan(ctx, log, apiObject, spec, status, cachedStatus, context).Filter(func(a api.Action) bool { return createScaleMemberPlan(ctx, log, apiObject, spec, status, cachedStatus, context).Filter(filterScaleUP)
return a.Type == api.ActionTypeAddMember
})
} }
func createScaleMemberPlan(ctx context.Context, func createScaleMemberPlan(ctx context.Context,
@ -50,16 +48,17 @@ func createScaleMemberPlan(ctx context.Context,
switch spec.GetMode() { switch spec.GetMode() {
case api.DeploymentModeSingle: case api.DeploymentModeSingle:
// Never scale down // Never scale down
plan = append(plan, createScalePlan(log, status, status.Members.Single, api.ServerGroupSingle, 1).Filter(filterScaleUP)...)
case api.DeploymentModeActiveFailover: case api.DeploymentModeActiveFailover:
// Only scale agents & singles // Only scale agents & singles
if a := status.Agency; a != nil && a.Size != nil { if a := status.Agency; a != nil && a.Size != nil {
plan = append(plan, createScalePlan(log, status, status.Members.Agents, api.ServerGroupAgents, int(*a.Size))...) plan = append(plan, createScalePlan(log, status, status.Members.Agents, api.ServerGroupAgents, int(*a.Size)).Filter(filterScaleUP)...)
} }
plan = append(plan, createScalePlan(log, status, status.Members.Single, api.ServerGroupSingle, spec.Single.GetCount())...) plan = append(plan, createScalePlan(log, status, status.Members.Single, api.ServerGroupSingle, spec.Single.GetCount())...)
case api.DeploymentModeCluster: case api.DeploymentModeCluster:
// Scale agents, dbservers, coordinators // Scale agents, dbservers, coordinators
if a := status.Agency; a != nil && a.Size != nil { if a := status.Agency; a != nil && a.Size != nil {
plan = append(plan, createScalePlan(log, status, status.Members.Agents, api.ServerGroupAgents, int(*a.Size))...) plan = append(plan, createScalePlan(log, status, status.Members.Agents, api.ServerGroupAgents, int(*a.Size)).Filter(filterScaleUP)...)
} }
plan = append(plan, createScalePlan(log, status, status.Members.DBServers, api.ServerGroupDBServers, spec.DBServers.GetCount())...) plan = append(plan, createScalePlan(log, status, status.Members.DBServers, api.ServerGroupDBServers, spec.DBServers.GetCount())...)
plan = append(plan, createScalePlan(log, status, status.Members.Coordinators, api.ServerGroupCoordinators, spec.Coordinators.GetCount())...) plan = append(plan, createScalePlan(log, status, status.Members.Coordinators, api.ServerGroupCoordinators, spec.Coordinators.GetCount())...)
@ -157,3 +156,7 @@ func createReplaceMemberPlan(ctx context.Context,
return plan return plan
} }
func filterScaleUP(a api.Action) bool {
return a.Type == api.ActionTypeAddMember
}

View file

@ -362,7 +362,7 @@ func TestCreatePlanSingleScale(t *testing.T) {
newPlan, changed := createNormalPlan(ctx, log, depl, nil, spec, status, inspector.NewEmptyInspector(), c) newPlan, changed := createNormalPlan(ctx, log, depl, nil, spec, status, inspector.NewEmptyInspector(), c)
assert.True(t, changed) assert.True(t, changed)
assert.Len(t, newPlan, 0) // Single mode does not scale assert.Len(t, newPlan, 1)
// Test with 1 single member // Test with 1 single member
status.Members.Single = api.MemberStatusList{ status.Members.Single = api.MemberStatusList{
@ -375,6 +375,12 @@ func TestCreatePlanSingleScale(t *testing.T) {
assert.True(t, changed) assert.True(t, changed)
assert.Len(t, newPlan, 0) // Single mode does not scale assert.Len(t, newPlan, 0) // Single mode does not scale
spec.Single.Count = util.NewInt(2)
newPlan, changed = createNormalPlan(ctx, log, depl, nil, spec, status, inspector.NewEmptyInspector(), c)
assert.True(t, changed)
assert.Len(t, newPlan, 0) // Single mode does not scale
spec.Single.Count = util.NewInt(1)
// Test with 2 single members (which should not happen) and try to scale down // Test with 2 single members (which should not happen) and try to scale down
status.Members.Single = api.MemberStatusList{ status.Members.Single = api.MemberStatusList{
api.MemberStatus{ api.MemberStatus{
@ -388,7 +394,7 @@ func TestCreatePlanSingleScale(t *testing.T) {
} }
newPlan, changed = createNormalPlan(ctx, log, depl, nil, spec, status, inspector.NewEmptyInspector(), c) newPlan, changed = createNormalPlan(ctx, log, depl, nil, spec, status, inspector.NewEmptyInspector(), c)
assert.True(t, changed) assert.True(t, changed)
assert.Len(t, newPlan, 0) // Single mode does not scale assert.Len(t, newPlan, 0) // Single mode does not scale down
} }
// TestCreatePlanActiveFailoverScale creates a `ActiveFailover` deployment to test the creating of scaling plan. // TestCreatePlanActiveFailoverScale creates a `ActiveFailover` deployment to test the creating of scaling plan.
@ -664,6 +670,7 @@ func TestCreatePlan(t *testing.T) {
}, },
Helper: func(ad *api.ArangoDeployment) { Helper: func(ad *api.ArangoDeployment) {
ad.Spec.Mode = api.NewMode(api.DeploymentModeSingle) ad.Spec.Mode = api.NewMode(api.DeploymentModeSingle)
ad.Status.Members.Single = append(ad.Status.Members.Single, api.MemberStatus{})
}, },
ExpectedPlan: []api.Action{}, ExpectedPlan: []api.Action{},
}, },

View file

@ -191,6 +191,8 @@ func (a *ArangoDContainer) GetEnvs() []core.EnvVar {
} }
} }
envs.Add(true, pod.Topology().Envs(a.member.AsInput())...)
return envs.GetEnvList() return envs.GetEnvList()
} }

View file

@ -71,6 +71,7 @@ func containersCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *co
return return
} }
} }
func initContainersCompare(deploymentSpec api.DeploymentSpec, group api.ServerGroup, spec, status *core.PodSpec) compareFunc { func initContainersCompare(deploymentSpec api.DeploymentSpec, group api.ServerGroup, spec, status *core.PodSpec) compareFunc {
return func(builder api.ActionBuilder) (mode Mode, plan api.Plan, err error) { return func(builder api.ActionBuilder) (mode Mode, plan api.Plan, err error) {
gs := deploymentSpec.GetServerGroupSpec(group) gs := deploymentSpec.GetServerGroupSpec(group)

View file

@ -0,0 +1,23 @@
//
// DISCLAIMER
//
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
//
// Licensed 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package topology
var ArangoDBZone = "ARANGODB_ZONE"