Skip to content

Commit

Permalink
Merge pull request #19533 from sjenning/carry-xfs-quota
Browse files Browse the repository at this point in the history
UPSTREAM: <carry>: XFS quota for emptyDir volumes
  • Loading branch information
openshift-merge-robot authored May 15, 2018
2 parents 62b9d59 + 7637781 commit ad9b0c1
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 78 deletions.
64 changes: 0 additions & 64 deletions pkg/cmd/server/kubernetes/node/node.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package node

import (
"errors"
"fmt"
"os"
"path/filepath"

"github.com/golang/glog"

kapiv1 "k8s.io/api/core/v1"
"k8s.io/kubernetes/cmd/kubelet/app"
"k8s.io/kubernetes/pkg/volume"

configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/volume/emptydir"
)

// TODO this is a best effort check at the moment that should either move to kubelet or be removed entirely
Expand Down Expand Up @@ -83,60 +76,3 @@ func initializeVolumeDir(rootDirectory string) error {
}
return nil
}

// TODO this needs to move into the forked kubelet with a `--openshift-config` flag
// PatchUpstreamVolumePluginsForLocalQuota checks if the node config specifies a local storage
// perFSGroup quota, and if so will test that the volumeDirectory is on a
// filesystem suitable for quota enforcement. If checks pass the k8s emptyDir
// volume plugin will be replaced with a wrapper version which adds quota
// functionality.
func PatchUpstreamVolumePluginsForLocalQuota(nodeConfig configapi.NodeConfig) func() []volume.VolumePlugin {
// This looks a little weird written this way but it allows straight lifting from here to kube at a future time
// and will allow us to wrap the exec.

existingProbeVolumePlugins := app.ProbeVolumePlugins
return func() []volume.VolumePlugin {
if nodeConfig.VolumeConfig.LocalQuota.PerFSGroup == nil {
return existingProbeVolumePlugins()
}

glog.V(4).Info("Replacing empty-dir volume plugin with quota wrapper")
wrappedEmptyDirPlugin := false

quotaApplicator, err := emptydir.NewQuotaApplicator(nodeConfig.VolumeDirectory)
if err != nil {
glog.Fatalf("Could not set up local quota, %s", err)
}

// Create a volume spec with emptyDir we can use to search for the
// emptyDir plugin with CanSupport:
emptyDirSpec := &volume.Spec{
Volume: &kapiv1.Volume{
VolumeSource: kapiv1.VolumeSource{
EmptyDir: &kapiv1.EmptyDirVolumeSource{},
},
},
}

ret := existingProbeVolumePlugins()
for idx, plugin := range ret {
// Can't really do type checking or use a constant here as they are not exported:
if plugin.CanSupport(emptyDirSpec) {
wrapper := emptydir.EmptyDirQuotaPlugin{
VolumePlugin: plugin,
Quota: *nodeConfig.VolumeConfig.LocalQuota.PerFSGroup,
QuotaApplicator: quotaApplicator,
}
ret[idx] = &wrapper
wrappedEmptyDirPlugin = true
}
}
// Because we can't look for the k8s emptyDir plugin by any means that would
// survive a refactor, error out if we couldn't find it:
if !wrappedEmptyDirPlugin {
glog.Fatal(errors.New("No plugin handling EmptyDir was found, unable to apply local quotas"))
}

return ret
}
}
2 changes: 0 additions & 2 deletions pkg/cmd/server/start/start_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,6 @@ func StartNode(nodeConfig configapi.NodeConfig, components *utilflags.ComponentF
node.EnsureKubeletAccess()
// TODO perform this "ensure" in ansible and skip it entirely.
node.EnsureVolumeDir(nodeConfig.VolumeDirectory)
// TODO accept an --openshift-config in our fork. This overwrites the volume creation patch for the node.
kubeletapp.ProbeVolumePlugins = node.PatchUpstreamVolumePluginsForLocalQuota(nodeConfig)

go func() {
glog.Fatal(runKubeletInProcess(kubeletArgs))
Expand Down
4 changes: 2 additions & 2 deletions test/extended/localquota/local_fsgroup_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/volume/emptydirquota"

"github.com/openshift/origin/pkg/volume/emptydir"
exutil "github.com/openshift/origin/test/extended/util"
)

Expand Down Expand Up @@ -58,7 +58,7 @@ func lookupFSGroup(oc *exutil.CLI, project string) (int, error) {
func lookupXFSQuota(oc *exutil.CLI, fsGroup int, volDir string) (int, error) {

// First lookup the filesystem device the volumeDir resides on:
fsDevice, err := emptydir.GetFSDevice(volDir)
fsDevice, err := emptydirquota.GetFSDevice(volDir)
if err != nil {
return 0, err
}
Expand Down
113 changes: 113 additions & 0 deletions vendor/k8s.io/kubernetes/cmd/kubelet/app/patch_volumequota.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions vendor/k8s.io/kubernetes/cmd/kubelet/app/patch_volumes.go

This file was deleted.

3 changes: 1 addition & 2 deletions vendor/k8s.io/kubernetes/cmd/kubelet/app/plugins.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions vendor/k8s.io/kubernetes/cmd/kubelet/app/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ad9b0c1

Please sign in to comment.