From f1910062bb18877bf97898073acc3345815d56ad Mon Sep 17 00:00:00 2001 From: Emeline Gaulard Date: Wed, 4 Apr 2018 11:14:26 +0200 Subject: [PATCH 1/3] Allow flexvolume configuration via quota labels --- cmd/flex/main.go | 28 +++++++++++++++++++++++++++- svc/kube_list_quotas.go | 4 ++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/cmd/flex/main.go b/cmd/flex/main.go index b4ea9432c..846e55406 100755 --- a/cmd/flex/main.go +++ b/cmd/flex/main.go @@ -12,6 +12,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" crd "github.com/nerdalize/nerd/crd/pkg/client/clientset/versioned" @@ -387,6 +388,27 @@ 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.Background(), &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) + } + 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) @@ -448,8 +470,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 { diff --git a/svc/kube_list_quotas.go b/svc/kube_list_quotas.go index 1898382b9..f38c01c53 100644 --- a/svc/kube_list_quotas.go +++ b/svc/kube_list_quotas.go @@ -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 @@ -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, }) } From bd19706f03a5988537ab1e41f5444b64931309c4 Mon Sep 17 00:00:00 2001 From: Emeline Gaulard Date: Fri, 6 Apr 2018 09:13:17 +0200 Subject: [PATCH 2/3] add other check for flexvolume space --- cmd/flex/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/flex/main.go b/cmd/flex/main.go index 846e55406..17f40c2b0 100755 --- a/cmd/flex/main.go +++ b/cmd/flex/main.go @@ -405,6 +405,9 @@ func (volp *DatasetVolumes) fetchAllowedSpace(path, namespace string) (space int } 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 } From 5745d2480ad204bd30544474d37b4b455ad4d617 Mon Sep 17 00:00:00 2001 From: Emeline Gaulard Date: Mon, 9 Apr 2018 09:54:48 +0200 Subject: [PATCH 3/3] Add comments to update kube and context from flex script --- cmd/flex/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/flex/main.go b/cmd/flex/main.go index 17f40c2b0..79d08c232 100755 --- a/cmd/flex/main.go +++ b/cmd/flex/main.go @@ -399,7 +399,7 @@ func (volp *DatasetVolumes) fetchAllowedSpace(path, namespace string) (space int } kube := svc.NewKube(di) - quotas, err := kube.ListQuotas(context.Background(), &svc.ListQuotasInput{}) + quotas, err := kube.ListQuotas(context.TODO(), &svc.ListQuotasInput{}) if len(quotas.Items) == 0 { return space, err } @@ -460,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)