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
  • Loading branch information
boz committed Feb 26, 2024
1 parent 1938a8b commit 8ae69ed
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

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 {

Check failure on line 167 in cluster/kube/builder/workload.go

View workflow job for this annotation

GitHub Actions / tests

undefined: sdl.StorageClassRAM

Check failure on line 167 in cluster/kube/builder/workload.go

View workflow job for this annotation

GitHub Actions / build-bins

undefined: sdl.StorageClassRAM

Check failure on line 167 in cluster/kube/builder/workload.go

View workflow job for this annotation

GitHub Actions / lint

undefined: sdl.StorageClassRAM) (typecheck)

Check failure on line 167 in cluster/kube/builder/workload.go

View workflow job for this annotation

GitHub Actions / lint

undefined: sdl.StorageClassRAM) (typecheck)

Check failure on line 167 in cluster/kube/builder/workload.go

View workflow job for this annotation

GitHub Actions / lint

undefined: sdl.StorageClassRAM) (typecheck)

Check failure on line 167 in cluster/kube/builder/workload.go

View workflow job for this annotation

GitHub Actions / lint

undefined: sdl.StorageClassRAM (typecheck)

Check failure on line 167 in cluster/kube/builder/workload.go

View workflow job for this annotation

GitHub Actions / release-dry-run

undefined: 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 8ae69ed

Please sign in to comment.