Skip to content

Commit a7f8b47

Browse files
authored
[Feature] ShortNames (#799)
1 parent 53cd15d commit a7f8b47

File tree

9 files changed

+151
-51
lines changed

9 files changed

+151
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- Replace `beta.kubernetes.io/arch` Pod label with `kubernetes.io/arch` using Silent Rotation
5+
- Add "Short Names" feature
56

67
## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24)
78
- Update UBI Image to 8.4

pkg/deployment/features/names.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2021 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+
// Author Adam Janikowski
21+
//
22+
23+
package features
24+
25+
func init() {
26+
registerFeature(podNames)
27+
}
28+
29+
var podNames = &feature{
30+
name: "short-pod-names",
31+
description: "Enable Short Pod Names",
32+
version: "3.5.0",
33+
enterpriseRequired: false,
34+
enabledByDefault: false,
35+
}
36+
37+
func PodNames() Feature {
38+
return podNames
39+
}

pkg/deployment/reconcile/action_helper.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ func NewTimeoutFetcher(t time.Duration) TimeoutFetcher {
3838
}
3939
}
4040

41+
type actionEmpty struct {
42+
actionImpl
43+
actionEmptyStart
44+
actionEmptyCheckProgress
45+
}
46+
4147
type actionEmptyCheckProgress struct {
4248
}
4349

pkg/deployment/reconcile/action_member_phase_update.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,16 @@ func (a *memberPhaseUpdateAction) Start(ctx context.Context) (bool, error) {
6666
return true, nil
6767
}
6868

69-
phase, ok := api.GetPhase(phaseString)
69+
p, ok := api.GetPhase(phaseString)
7070
if !ok {
71-
log.Error().Msgf("Phase %s unknown", phase)
71+
log.Error().Msgf("Phase %s unknown", p)
7272
return true, nil
7373
}
7474

75-
if m.Phase == phase {
76-
return true, nil
77-
}
78-
79-
m.Phase = phase
80-
if err := a.actionCtx.UpdateMember(ctx, m); err != nil {
81-
return false, errors.WithStack(err)
75+
if phase.Execute(&m, a.action, p) {
76+
if err := a.actionCtx.UpdateMember(ctx, m); err != nil {
77+
return false, errors.WithStack(err)
78+
}
8279
}
8380

8481
return true, nil

pkg/deployment/reconcile/action_member_rid_update.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@
2323
package reconcile
2424

2525
import (
26-
"context"
27-
28-
"k8s.io/apimachinery/pkg/util/uuid"
29-
3026
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
31-
"github.com/arangodb/kube-arangodb/pkg/util/errors"
3227
"github.com/rs/zerolog"
3328
)
3429

@@ -45,24 +40,5 @@ func newMemberRIDUpdate(log zerolog.Logger, action api.Action, actionCtx ActionC
4540
}
4641

4742
type memberRIDUpdateAction struct {
48-
actionImpl
49-
50-
actionEmptyCheckProgress
51-
}
52-
53-
func (a *memberRIDUpdateAction) Start(ctx context.Context) (bool, error) {
54-
log := a.log
55-
m, ok := a.actionCtx.GetMemberStatusByID(a.action.MemberID)
56-
if !ok {
57-
log.Error().Msg("No such member")
58-
return true, nil
59-
}
60-
61-
m.RID = uuid.NewUUID()
62-
63-
if err := a.actionCtx.UpdateMember(ctx, m); err != nil {
64-
return false, errors.WithStack(err)
65-
}
66-
67-
return true, nil
43+
actionEmpty
6844
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020-2021 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+
// Author Adam Janikowski
21+
//
22+
23+
package reconcile
24+
25+
import (
26+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
27+
"k8s.io/apimachinery/pkg/util/uuid"
28+
)
29+
30+
type phaseMapFunc func(action api.Action, m *api.MemberStatus)
31+
type phaseMapTo map[api.MemberPhase]phaseMapFunc
32+
type phaseMap map[api.MemberPhase]phaseMapTo
33+
34+
var phase = phaseMap{
35+
api.MemberPhaseNone: {
36+
api.MemberPhasePending: func(action api.Action, m *api.MemberStatus) {
37+
// Clean conditions
38+
m.Conditions.Remove(api.ConditionTypeReady)
39+
m.Conditions.Remove(api.ConditionTypeTerminated)
40+
m.Conditions.Remove(api.ConditionTypeTerminating)
41+
m.Conditions.Remove(api.ConditionTypeAgentRecoveryNeeded)
42+
m.Conditions.Remove(api.ConditionTypeAutoUpgrade)
43+
m.Conditions.Remove(api.ConditionTypeUpgradeFailed)
44+
m.Conditions.Remove(api.ConditionTypePendingTLSRotation)
45+
m.Conditions.Remove(api.ConditionTypePendingRestart)
46+
m.Conditions.Remove(api.ConditionTypeRestart)
47+
m.Conditions.Remove(api.ConditionTypePendingUpdate)
48+
m.Conditions.Remove(api.ConditionTypeUpdating)
49+
m.Conditions.Remove(api.ConditionTypeUpdateFailed)
50+
m.Conditions.Remove(api.ConditionTypeCleanedOut)
51+
52+
// Change member RID
53+
m.RID = uuid.NewUUID()
54+
55+
// Clean Pod details
56+
m.PodUID = ""
57+
},
58+
},
59+
}
60+
61+
func (p phaseMap) empty(action api.Action, m *api.MemberStatus) {
62+
63+
}
64+
65+
func (p phaseMap) getFunc(from, to api.MemberPhase) phaseMapFunc {
66+
if f, ok := p[from]; ok {
67+
if t, ok := f[to]; ok {
68+
return t
69+
}
70+
}
71+
72+
return p.empty
73+
}
74+
75+
func (p phaseMap) Execute(m *api.MemberStatus, action api.Action, to api.MemberPhase) bool {
76+
from := m.Phase
77+
78+
if from == to {
79+
return false
80+
}
81+
82+
f := p.getFunc(from, to)
83+
84+
m.Phase = to
85+
86+
f(action, m)
87+
88+
return true
89+
}

pkg/deployment/reconcile/plan_builder_high.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ func updateMemberPhasePlan(ctx context.Context,
125125
status.Members.ForeachServerGroup(func(group api.ServerGroup, list api.MemberStatusList) error {
126126
for _, m := range list {
127127
if m.Phase == api.MemberPhaseNone {
128-
p := api.Plan{
129-
api.NewAction(api.ActionTypeMemberRIDUpdate, group, m.ID, "Regenerate member RID"),
130-
}
128+
var p api.Plan
131129

132130
p = append(p,
133131
api.NewAction(api.ActionTypeArangoMemberUpdatePodSpec, group, m.ID, "Propagating spec of pod"),

pkg/deployment/resources/pod_creator.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -622,19 +622,6 @@ func (r *Resources) createPodForMember(ctx context.Context, spec api.DeploymentS
622622

623623
// Record new member phase
624624
m.Phase = newPhase
625-
m.Conditions.Remove(api.ConditionTypeReady)
626-
m.Conditions.Remove(api.ConditionTypeTerminated)
627-
m.Conditions.Remove(api.ConditionTypeTerminating)
628-
m.Conditions.Remove(api.ConditionTypeAgentRecoveryNeeded)
629-
m.Conditions.Remove(api.ConditionTypeAutoUpgrade)
630-
m.Conditions.Remove(api.ConditionTypeUpgradeFailed)
631-
m.Conditions.Remove(api.ConditionTypePendingTLSRotation)
632-
m.Conditions.Remove(api.ConditionTypePendingRestart)
633-
m.Conditions.Remove(api.ConditionTypeRestart)
634-
m.Conditions.Remove(api.ConditionTypePendingUpdate)
635-
m.Conditions.Remove(api.ConditionTypeUpdating)
636-
m.Conditions.Remove(api.ConditionTypeUpdateFailed)
637-
m.Conditions.Remove(api.ConditionTypeCleanedOut)
638625

639626
m.Upgrade = false
640627
r.log.Info().Str("pod", m.PodName).Msgf("Updating member")
@@ -783,6 +770,10 @@ func (r *Resources) EnsurePods(ctx context.Context, cachedStatus inspectorInterf
783770
}
784771

785772
func CreatePodSuffix(spec api.DeploymentSpec) string {
773+
if features.PodNames().Enabled() {
774+
return ""
775+
}
776+
786777
raw, _ := json.Marshal(spec)
787778
hash := sha1.Sum(raw)
788779
return fmt.Sprintf("%0x", hash)[:6]

pkg/util/k8sutil/pods.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,10 @@ func GetPodSpecChecksum(podSpec core.PodSpec) (string, error) {
468468
func CreatePod(ctx context.Context, kubecli kubernetes.Interface, pod *core.Pod, ns string, owner metav1.OwnerReference) (types.UID, error) {
469469
AddOwnerRefToObject(pod.GetObjectMeta(), &owner)
470470

471-
if pod, err := kubecli.CoreV1().Pods(ns).Create(ctx, pod, metav1.CreateOptions{}); err != nil && !IsAlreadyExists(err) {
471+
if pod, err := kubecli.CoreV1().Pods(ns).Create(ctx, pod, metav1.CreateOptions{}); err != nil {
472+
if IsAlreadyExists(err) {
473+
return "", nil // If pod exists do not return any error but do not record UID (enforced rotation)
474+
}
472475
return "", errors.WithStack(err)
473476
} else {
474477
return pod.UID, nil

0 commit comments

Comments
 (0)