Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Add tmpfs option for etcd-data volume #2103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/apis/etcd/v1beta2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ type PodPolicy struct {
// '.cluster.local'.
// The default is to not set a cluster domain explicitly.
ClusterDomain string `json:"ClusterDomain"`

// Sets the 'emptyDir.medium' field for the etcd-data volume to "Memory".
// The default is to not use memory as the storage medium
// No effect if persistent volume is used
Tmpfs bool `json:"tmpfs,omitempty"`
}

// TODO: move this to initializer
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ func (c *Cluster) createPod(members etcdutil.MemberSet, m *etcdutil.Member, stat
if err != nil {
return fmt.Errorf("failed to create PVC for member (%s): %v", m.Name, err)
}
k8sutil.AddEtcdVolumeToPod(pod, pvc)
k8sutil.AddEtcdVolumeToPod(pod, pvc, false)
} else {
k8sutil.AddEtcdVolumeToPod(pod, nil)
k8sutil.AddEtcdVolumeToPod(pod, nil, c.cluster.Spec.Pod.Tmpfs)
Copy link

@Marlinc Marlinc Nov 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested this and it will cause the operator to crash with a nil error when c.cluster.Spec.Pod is nil.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a fix in cbws#22

}
_, err := c.config.KubeCli.CoreV1().Pods(c.cluster.Namespace).Create(pod)
return err
Expand Down
7 changes: 5 additions & 2 deletions pkg/util/k8sutil/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,17 @@ func newEtcdServiceManifest(svcName, clusterName, clusterIP string, ports []v1.S
}

// AddEtcdVolumeToPod abstract the process of appending volume spec to pod spec
func AddEtcdVolumeToPod(pod *v1.Pod, pvc *v1.PersistentVolumeClaim) {
func AddEtcdVolumeToPod(pod *v1.Pod, pvc *v1.PersistentVolumeClaim, tmpfs bool) {
vol := v1.Volume{Name: etcdVolumeName}
if pvc != nil {
vol.VolumeSource = v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: pvc.Name},
}
} else {
vol.VolumeSource = v1.VolumeSource{EmptyDir: &v1.EmptyDirVolumeSource{}}
if tmpfs {
vol.VolumeSource.EmptyDir.Medium = v1.StorageMediumMemory
}
}
pod.Spec.Volumes = append(pod.Spec.Volumes, vol)
}
Expand All @@ -274,7 +277,7 @@ func NewSeedMemberPod(clusterName string, ms etcdutil.MemberSet, m *etcdutil.Mem
token := uuid.New()
pod := newEtcdPod(m, ms.PeerURLPairs(), clusterName, "new", token, cs)
// TODO: PVC datadir support for restore process
AddEtcdVolumeToPod(pod, nil)
AddEtcdVolumeToPod(pod, nil, cs.Pod.Tmpfs)
if backupURL != nil {
addRecoveryToPod(pod, token, m, cs, backupURL)
}
Expand Down