Skip to content

Commit

Permalink
Merge pull request #394 from nerdalize/feature/flex-volume-custom-size
Browse files Browse the repository at this point in the history
Allow flexvolume configuration via quota labels
  • Loading branch information
advanderveer committed Apr 9, 2018
2 parents 2dbec35 + 5745d24 commit 792316d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
33 changes: 32 additions & 1 deletion cmd/flex/main.go
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

crd "github.com/nerdalize/nerd/crd/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -387,6 +388,30 @@ func (volp *DatasetVolumes) handleOutput(path, namespace, dataset string) error
return nil
}

// fetchAllowedSpace is a temporary solution so we can give more space to specific users on the public cluster
func (volp *DatasetVolumes) fetchAllowedSpace(path, namespace string) (space int64, err error) {
// TODO WriteSpace should be used only if there is no label "flex-volume-size" in the namespace quota labels.
space = WriteSpace

di, err := NewDeps(namespace)
if err != nil {
return space, errors.Wrap(err, "failed to setup dependencies")
}

kube := svc.NewKube(di)
quotas, err := kube.ListQuotas(context.TODO(), &svc.ListQuotasInput{})
if len(quotas.Items) == 0 {
return space, err
}
if quotas.Items[0].Labels["flex-volume-size"] != "" {
space, err = strconv.ParseInt(quotas.Items[0].Labels["flex-volume-size"], 10, 64)
if err != nil {
space = WriteSpace
}
}
return space, err
}

//getPath returns a path above the mountPath and unique to the dataset name.
func (volp *DatasetVolumes) getPath(mountPath string, name string) string {
return filepath.Join(mountPath, "..", filepath.Base(mountPath)+"."+name)
Expand Down Expand Up @@ -435,6 +460,8 @@ func (volp *DatasetVolumes) Mount(kubeMountPath string, opts MountOptions) (err
return errors.Wrap(err, "failed to write volume database")
}

//+TODO create kube here and inject it in provisionInput and fetchAllowedSpace
//TODO create a context with a deadline
//Set up input
err = volp.provisionInput(volp.getPath(kubeMountPath, RelPathInput), dsopts.Namespace, dsopts.InputDataset)

Expand All @@ -448,8 +475,12 @@ func (volp *DatasetVolumes) Mount(kubeMountPath string, opts MountOptions) (err
return errors.Wrap(err, "failed to provision input")
}

writeSpace, err := volp.fetchAllowedSpace(kubeMountPath, dsopts.Namespace)
if err != nil {
return errors.Wrap(err, "failed to fetch allowed space")
}
//Create volume to contain pod writes
err = volp.createFSInFile(volp.getPath(kubeMountPath, RelPathFSInFile), FileSystemExt4, WriteSpace)
err = volp.createFSInFile(volp.getPath(kubeMountPath, RelPathFSInFile), FileSystemExt4, writeSpace)

defer func() {
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions svc/kube_list_quotas.go
Expand Up @@ -19,6 +19,8 @@ type ListQuotaItem struct {
UseLimitCPU int64
UseLimitMemory int64
UseRequestMemory int64

Labels map[string]string
}

//NodeLimitedQuota is used when no quota is configured
Expand Down Expand Up @@ -65,6 +67,8 @@ func (k *Kube) ListQuotas(ctx context.Context, in *ListQuotasInput) (out *ListQu
UseRequestCPU: useReqCPU.MilliValue(),
UseLimitMemory: useLimMem.MilliValue(),
UseRequestMemory: useReqMem.MilliValue(),

Labels: q.Labels,
})
}

Expand Down

0 comments on commit 792316d

Please sign in to comment.