diff --git a/cluster/kube/builder/deployment.go b/cluster/kube/builder/deployment.go index f337a36b..5769d76a 100644 --- a/cluster/kube/builder/deployment.go +++ b/cluster/kube/builder/deployment.go @@ -54,6 +54,7 @@ func (b *deployment) Create() (*appsv1.Deployment, error) { // nolint:golint,unp AutomountServiceAccountToken: &falseValue, Containers: []corev1.Container{b.container()}, ImagePullSecrets: b.imagePullSecrets(), + Volumes: b.volumes(), }, }, }, diff --git a/cluster/kube/builder/statefulset.go b/cluster/kube/builder/statefulset.go index c5fcda50..0b43be11 100644 --- a/cluster/kube/builder/statefulset.go +++ b/cluster/kube/builder/statefulset.go @@ -54,6 +54,7 @@ func (b *statefulSet) Create() (*appsv1.StatefulSet, error) { // nolint:golint,u AutomountServiceAccountToken: &falseValue, Containers: []corev1.Container{b.container()}, ImagePullSecrets: b.imagePullSecrets(), + Volumes: b.volumes(), }, }, VolumeClaimTemplates: b.persistentVolumeClaims(), diff --git a/cluster/kube/builder/workload.go b/cluster/kube/builder/workload.go index 48683f28..ee7e3fea 100644 --- a/cluster/kube/builder/workload.go +++ b/cluster/kube/builder/workload.go @@ -154,6 +154,42 @@ func (b *Workload) container() corev1.Container { return kcontainer } +// Return RAM volumes +func (b *Workload) volumes() []corev1.Volume { + var volumes []corev1.Volume + + service := &b.deployment.ManifestGroup().Services[b.serviceIdx] + + for _, storage := range service.Resources.Storage { + + // Only RAM volumes + sclass, ok := storage.Attributes.Find(sdl.StorageAttributeClass).AsString() + if !ok || sclass != sdl.StorageClassRAM { + continue + } + + // No persistent volumes + persistent, ok := storage.Attributes.Find(sdl.StorageAttributePersistent).AsBool() + if !ok || persistent { + continue + } + + size := resource.NewQuantity(storage.Quantity.Val.Int64(), resource.DecimalSI).DeepCopy() + + volumes = append(volumes, corev1.Volume{ + Name: fmt.Sprintf("%s-%s", service.Name, storage.Name), + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{ + Medium: corev1.StorageMediumMemory, + SizeLimit: &size, + }, + }, + }) + } + + return volumes +} + func (b *Workload) persistentVolumeClaims() []corev1.PersistentVolumeClaim { var pvcs []corev1.PersistentVolumeClaim // nolint:prealloc