Skip to content

Commit

Permalink
feat(cluster/kube/builder): "ram" storage class
Browse files Browse the repository at this point in the history
* Implement `"ram"` storage class with "empty dir" memory-backed
  volumes.
* No changes to resource accounting - service memory size
  must include size allocated to ram storage.

refs akash-network/support#179

Signed-off-by: Adam Bozanich <adam.boz@gmail.com>
  • Loading branch information
boz authored and troian committed Mar 20, 2024
1 parent 1eb358b commit 05777d7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions cluster/kube/builder/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
},
},
Expand Down
1 change: 1 addition & 0 deletions cluster/kube/builder/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
36 changes: 36 additions & 0 deletions cluster/kube/builder/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 // nolint:prealloc

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

Expand Down

0 comments on commit 05777d7

Please sign in to comment.