Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPSTREAM: <carry>: XFS quota for emptyDir volumes #19533

Merged
merged 3 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -484,8 +484,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.