Skip to content

Commit 9abab5b

Browse files
authored
Merge pull request #95 from arangodb/set-uuid-once
Check contents of persisted volume when dbserver is restarting
2 parents eafc2ab + d7beb94 commit 9abab5b

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

pkg/apis/deployment/v1alpha/member_status.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ type MemberStatus struct {
4747
// RecentTerminatons holds the times when this member was recently terminated.
4848
// First entry is the oldest. (do not add omitempty, since we want to be able to switch from a list to an empty list)
4949
RecentTerminations []metav1.Time `json:"recent-terminations"`
50+
// IsInitialized is set after the very first time a pod was created for this member.
51+
// After that, DBServers must have a UUID field or fail.
52+
IsInitialized bool `json:"initialized"`
5053
}
5154

5255
// RemoveTerminationsBefore removes all recent terminations before the given timestamp.

pkg/deployment/images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, ima
166166
"--server.authentication=false",
167167
fmt.Sprintf("--server.endpoint=tcp://[::]:%d", k8sutil.ArangoPort),
168168
}
169-
if err := k8sutil.CreateArangodPod(ib.KubeCli, true, ib.APIObject, role, id, podName, "", image, ib.Spec.GetImagePullPolicy(), args, nil, nil, nil, "", ""); err != nil {
169+
if err := k8sutil.CreateArangodPod(ib.KubeCli, true, ib.APIObject, role, id, podName, "", image, ib.Spec.GetImagePullPolicy(), "", false, args, nil, nil, nil, "", ""); err != nil {
170170
log.Debug().Err(err).Msg("Failed to create image ID pod")
171171
return true, maskAny(err)
172172
}

pkg/deployment/resources/pod_creator.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,10 @@ func (r *Resources) createPodForMember(spec api.DeploymentSpec, group api.Server
366366
SecretKey: constants.SecretKeyJWT,
367367
}
368368
}
369-
if err := k8sutil.CreateArangodPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, m.PersistentVolumeClaimName, info.ImageID, spec.GetImagePullPolicy(), args, env, livenessProbe, readinessProbe, tlsKeyfileSecretName, rocksdbEncryptionSecretName); err != nil {
369+
engine := string(spec.GetStorageEngine())
370+
requireUUID := group == api.ServerGroupDBServers && m.IsInitialized
371+
if err := k8sutil.CreateArangodPod(kubecli, spec.IsDevelopment(), apiObject, role, m.ID, m.PodName, m.PersistentVolumeClaimName, info.ImageID, spec.GetImagePullPolicy(),
372+
engine, requireUUID, args, env, livenessProbe, readinessProbe, tlsKeyfileSecretName, rocksdbEncryptionSecretName); err != nil {
370373
return maskAny(err)
371374
}
372375
log.Debug().Str("pod-name", m.PodName).Msg("Created pod")

pkg/deployment/resources/pod_inspector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func (r *Resources) InspectPods() error {
106106
// Pod is now ready
107107
if memberStatus.Conditions.Update(api.ConditionTypeReady, true, "Pod Ready", "") {
108108
log.Debug().Str("pod-name", p.GetName()).Msg("Updating member condition Ready to true")
109+
memberStatus.IsInitialized = true // Require future pods for this member to have an existing UUID (in case of dbserver).
109110
updateMemberStatusNeeded = true
110111
}
111112
} else {

pkg/util/k8sutil/pods.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package k8sutil
2525
import (
2626
"fmt"
2727
"path/filepath"
28+
"strings"
2829
"time"
2930

3031
"k8s.io/api/core/v1"
@@ -170,13 +171,28 @@ func rocksdbEncryptionVolumeMounts() []v1.VolumeMount {
170171

171172
// arangodInitContainer creates a container configured to
172173
// initalize a UUID file.
173-
func arangodInitContainer(name, id string) v1.Container {
174+
func arangodInitContainer(name, id, engine string, requireUUID bool) v1.Container {
174175
uuidFile := filepath.Join(ArangodVolumeMountDir, "UUID")
176+
engineFile := filepath.Join(ArangodVolumeMountDir, "ENGINE")
177+
var command string
178+
if requireUUID {
179+
command = strings.Join([]string{
180+
// Files must exist
181+
fmt.Sprintf("test -f %s", uuidFile),
182+
fmt.Sprintf("test -f %s", engineFile),
183+
// Content must match
184+
fmt.Sprintf("grep -q %s %s", id, uuidFile),
185+
fmt.Sprintf("grep -q %s %s", engine, engineFile),
186+
}, " && ")
187+
188+
} else {
189+
command = fmt.Sprintf("test -f %s || echo '%s' > %s", uuidFile, id, uuidFile)
190+
}
175191
c := v1.Container{
176192
Command: []string{
177193
"/bin/sh",
178194
"-c",
179-
fmt.Sprintf("test -f %s || echo '%s' > %s", uuidFile, id, uuidFile),
195+
command,
180196
},
181197
Name: name,
182198
Image: alpineImage,
@@ -261,6 +277,7 @@ func newPod(deploymentName, ns, role, id, podName string) v1.Pod {
261277
// If another error occurs, that error is returned.
262278
func CreateArangodPod(kubecli kubernetes.Interface, developmentMode bool, deployment APIObject,
263279
role, id, podName, pvcName, image string, imagePullPolicy v1.PullPolicy,
280+
engine string, requireUUID bool,
264281
args []string, env map[string]EnvValue,
265282
livenessProbe *HTTPProbeConfig, readinessProbe *HTTPProbeConfig,
266283
tlsKeyfileSecretName, rocksdbEncryptionSecretName string) error {
@@ -278,7 +295,7 @@ func CreateArangodPod(kubecli kubernetes.Interface, developmentMode bool, deploy
278295
p.Spec.Containers = append(p.Spec.Containers, c)
279296

280297
// Add UUID init container
281-
p.Spec.InitContainers = append(p.Spec.InitContainers, arangodInitContainer("uuid", id))
298+
p.Spec.InitContainers = append(p.Spec.InitContainers, arangodInitContainer("uuid", id, engine, requireUUID))
282299

283300
// Add volume
284301
if pvcName != "" {

0 commit comments

Comments
 (0)