mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] ShortNames (#799)
This commit is contained in:
parent
53cd15d318
commit
a7f8b4744e
9 changed files with 151 additions and 51 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
|
||||
- Replace `beta.kubernetes.io/arch` Pod label with `kubernetes.io/arch` using Silent Rotation
|
||||
- Add "Short Names" feature
|
||||
|
||||
## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24)
|
||||
- Update UBI Image to 8.4
|
||||
|
|
39
pkg/deployment/features/names.go
Normal file
39
pkg/deployment/features/names.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// DISCLAIMER
|
||||
//
|
||||
// Copyright 2021 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
|
||||
//
|
||||
// Author Adam Janikowski
|
||||
//
|
||||
|
||||
package features
|
||||
|
||||
func init() {
|
||||
registerFeature(podNames)
|
||||
}
|
||||
|
||||
var podNames = &feature{
|
||||
name: "short-pod-names",
|
||||
description: "Enable Short Pod Names",
|
||||
version: "3.5.0",
|
||||
enterpriseRequired: false,
|
||||
enabledByDefault: false,
|
||||
}
|
||||
|
||||
func PodNames() Feature {
|
||||
return podNames
|
||||
}
|
|
@ -38,6 +38,12 @@ func NewTimeoutFetcher(t time.Duration) TimeoutFetcher {
|
|||
}
|
||||
}
|
||||
|
||||
type actionEmpty struct {
|
||||
actionImpl
|
||||
actionEmptyStart
|
||||
actionEmptyCheckProgress
|
||||
}
|
||||
|
||||
type actionEmptyCheckProgress struct {
|
||||
}
|
||||
|
||||
|
|
|
@ -66,19 +66,16 @@ func (a *memberPhaseUpdateAction) Start(ctx context.Context) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
phase, ok := api.GetPhase(phaseString)
|
||||
p, ok := api.GetPhase(phaseString)
|
||||
if !ok {
|
||||
log.Error().Msgf("Phase %s unknown", phase)
|
||||
log.Error().Msgf("Phase %s unknown", p)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if m.Phase == phase {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
m.Phase = phase
|
||||
if err := a.actionCtx.UpdateMember(ctx, m); err != nil {
|
||||
return false, errors.WithStack(err)
|
||||
if phase.Execute(&m, a.action, p) {
|
||||
if err := a.actionCtx.UpdateMember(ctx, m); err != nil {
|
||||
return false, errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
|
|
|
@ -23,12 +23,7 @@
|
|||
package reconcile
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
|
||||
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
|
||||
"github.com/arangodb/kube-arangodb/pkg/util/errors"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
|
@ -45,24 +40,5 @@ func newMemberRIDUpdate(log zerolog.Logger, action api.Action, actionCtx ActionC
|
|||
}
|
||||
|
||||
type memberRIDUpdateAction struct {
|
||||
actionImpl
|
||||
|
||||
actionEmptyCheckProgress
|
||||
}
|
||||
|
||||
func (a *memberRIDUpdateAction) Start(ctx context.Context) (bool, error) {
|
||||
log := a.log
|
||||
m, ok := a.actionCtx.GetMemberStatusByID(a.action.MemberID)
|
||||
if !ok {
|
||||
log.Error().Msg("No such member")
|
||||
return true, nil
|
||||
}
|
||||
|
||||
m.RID = uuid.NewUUID()
|
||||
|
||||
if err := a.actionCtx.UpdateMember(ctx, m); err != nil {
|
||||
return false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
actionEmpty
|
||||
}
|
||||
|
|
89
pkg/deployment/reconcile/member_phase_updates.go
Normal file
89
pkg/deployment/reconcile/member_phase_updates.go
Normal file
|
@ -0,0 +1,89 @@
|
|||
//
|
||||
// DISCLAIMER
|
||||
//
|
||||
// Copyright 2020-2021 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
|
||||
//
|
||||
// Author Adam Janikowski
|
||||
//
|
||||
|
||||
package reconcile
|
||||
|
||||
import (
|
||||
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
)
|
||||
|
||||
type phaseMapFunc func(action api.Action, m *api.MemberStatus)
|
||||
type phaseMapTo map[api.MemberPhase]phaseMapFunc
|
||||
type phaseMap map[api.MemberPhase]phaseMapTo
|
||||
|
||||
var phase = phaseMap{
|
||||
api.MemberPhaseNone: {
|
||||
api.MemberPhasePending: func(action api.Action, m *api.MemberStatus) {
|
||||
// Clean conditions
|
||||
m.Conditions.Remove(api.ConditionTypeReady)
|
||||
m.Conditions.Remove(api.ConditionTypeTerminated)
|
||||
m.Conditions.Remove(api.ConditionTypeTerminating)
|
||||
m.Conditions.Remove(api.ConditionTypeAgentRecoveryNeeded)
|
||||
m.Conditions.Remove(api.ConditionTypeAutoUpgrade)
|
||||
m.Conditions.Remove(api.ConditionTypeUpgradeFailed)
|
||||
m.Conditions.Remove(api.ConditionTypePendingTLSRotation)
|
||||
m.Conditions.Remove(api.ConditionTypePendingRestart)
|
||||
m.Conditions.Remove(api.ConditionTypeRestart)
|
||||
m.Conditions.Remove(api.ConditionTypePendingUpdate)
|
||||
m.Conditions.Remove(api.ConditionTypeUpdating)
|
||||
m.Conditions.Remove(api.ConditionTypeUpdateFailed)
|
||||
m.Conditions.Remove(api.ConditionTypeCleanedOut)
|
||||
|
||||
// Change member RID
|
||||
m.RID = uuid.NewUUID()
|
||||
|
||||
// Clean Pod details
|
||||
m.PodUID = ""
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func (p phaseMap) empty(action api.Action, m *api.MemberStatus) {
|
||||
|
||||
}
|
||||
|
||||
func (p phaseMap) getFunc(from, to api.MemberPhase) phaseMapFunc {
|
||||
if f, ok := p[from]; ok {
|
||||
if t, ok := f[to]; ok {
|
||||
return t
|
||||
}
|
||||
}
|
||||
|
||||
return p.empty
|
||||
}
|
||||
|
||||
func (p phaseMap) Execute(m *api.MemberStatus, action api.Action, to api.MemberPhase) bool {
|
||||
from := m.Phase
|
||||
|
||||
if from == to {
|
||||
return false
|
||||
}
|
||||
|
||||
f := p.getFunc(from, to)
|
||||
|
||||
m.Phase = to
|
||||
|
||||
f(action, m)
|
||||
|
||||
return true
|
||||
}
|
|
@ -125,9 +125,7 @@ func updateMemberPhasePlan(ctx context.Context,
|
|||
status.Members.ForeachServerGroup(func(group api.ServerGroup, list api.MemberStatusList) error {
|
||||
for _, m := range list {
|
||||
if m.Phase == api.MemberPhaseNone {
|
||||
p := api.Plan{
|
||||
api.NewAction(api.ActionTypeMemberRIDUpdate, group, m.ID, "Regenerate member RID"),
|
||||
}
|
||||
var p api.Plan
|
||||
|
||||
p = append(p,
|
||||
api.NewAction(api.ActionTypeArangoMemberUpdatePodSpec, group, m.ID, "Propagating spec of pod"),
|
||||
|
|
|
@ -622,19 +622,6 @@ func (r *Resources) createPodForMember(ctx context.Context, spec api.DeploymentS
|
|||
|
||||
// Record new member phase
|
||||
m.Phase = newPhase
|
||||
m.Conditions.Remove(api.ConditionTypeReady)
|
||||
m.Conditions.Remove(api.ConditionTypeTerminated)
|
||||
m.Conditions.Remove(api.ConditionTypeTerminating)
|
||||
m.Conditions.Remove(api.ConditionTypeAgentRecoveryNeeded)
|
||||
m.Conditions.Remove(api.ConditionTypeAutoUpgrade)
|
||||
m.Conditions.Remove(api.ConditionTypeUpgradeFailed)
|
||||
m.Conditions.Remove(api.ConditionTypePendingTLSRotation)
|
||||
m.Conditions.Remove(api.ConditionTypePendingRestart)
|
||||
m.Conditions.Remove(api.ConditionTypeRestart)
|
||||
m.Conditions.Remove(api.ConditionTypePendingUpdate)
|
||||
m.Conditions.Remove(api.ConditionTypeUpdating)
|
||||
m.Conditions.Remove(api.ConditionTypeUpdateFailed)
|
||||
m.Conditions.Remove(api.ConditionTypeCleanedOut)
|
||||
|
||||
m.Upgrade = false
|
||||
r.log.Info().Str("pod", m.PodName).Msgf("Updating member")
|
||||
|
@ -783,6 +770,10 @@ func (r *Resources) EnsurePods(ctx context.Context, cachedStatus inspectorInterf
|
|||
}
|
||||
|
||||
func CreatePodSuffix(spec api.DeploymentSpec) string {
|
||||
if features.PodNames().Enabled() {
|
||||
return ""
|
||||
}
|
||||
|
||||
raw, _ := json.Marshal(spec)
|
||||
hash := sha1.Sum(raw)
|
||||
return fmt.Sprintf("%0x", hash)[:6]
|
||||
|
|
|
@ -468,7 +468,10 @@ func GetPodSpecChecksum(podSpec core.PodSpec) (string, error) {
|
|||
func CreatePod(ctx context.Context, kubecli kubernetes.Interface, pod *core.Pod, ns string, owner metav1.OwnerReference) (types.UID, error) {
|
||||
AddOwnerRefToObject(pod.GetObjectMeta(), &owner)
|
||||
|
||||
if pod, err := kubecli.CoreV1().Pods(ns).Create(ctx, pod, metav1.CreateOptions{}); err != nil && !IsAlreadyExists(err) {
|
||||
if pod, err := kubecli.CoreV1().Pods(ns).Create(ctx, pod, metav1.CreateOptions{}); err != nil {
|
||||
if IsAlreadyExists(err) {
|
||||
return "", nil // If pod exists do not return any error but do not record UID (enforced rotation)
|
||||
}
|
||||
return "", errors.WithStack(err)
|
||||
} else {
|
||||
return pod.UID, nil
|
||||
|
|
Loading…
Reference in a new issue