Skip to content

Commit

Permalink
move overlay-checks to an overlayutils package
Browse files Browse the repository at this point in the history
This allows using the utilities without importing the whole
snapshotter.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Mar 15, 2021
1 parent a113818 commit ba8f984
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions archive/tar_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/containerd/containerd/log/logtest"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/pkg/testutil"
"github.com/containerd/containerd/snapshots/overlay"
"github.com/containerd/containerd/snapshots/overlay/overlayutils"
"github.com/containerd/continuity/fs"
"github.com/containerd/continuity/fs/fstest"
"github.com/pkg/errors"
Expand All @@ -46,7 +46,7 @@ func TestOverlayApply(t *testing.T) {
}
defer os.RemoveAll(base)

if err := overlay.Supported(base); err != nil {
if err := overlayutils.Supported(base); err != nil {
t.Skipf("skipping because overlay is not supported %v", err)
}
fstest.FSSuite(t, overlayDiffApplier{
Expand All @@ -65,7 +65,7 @@ func TestOverlayApplyNoParents(t *testing.T) {
}
defer os.RemoveAll(base)

if err := overlay.Supported(base); err != nil {
if err := overlayutils.Supported(base); err != nil {
t.Skipf("skipping because overlay is not supported %v", err)
}
fstest.FSSuite(t, overlayDiffApplier{
Expand Down
3 changes: 2 additions & 1 deletion snapshots/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/snapshots/overlay/overlayutils"
"github.com/containerd/containerd/snapshots/storage"
"github.com/containerd/continuity/fs"
"github.com/pkg/errors"
Expand Down Expand Up @@ -98,7 +99,7 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
}

// figure out whether "userxattr" option is recognized by the kernel && needed
userxattr, err := NeedsUserXAttr(root)
userxattr, err := overlayutils.NeedsUserXAttr(root)
if err != nil {
logrus.WithError(err).Warnf("cannot detect whether \"userxattr\" option needs to be used, assuming to be %v", userxattr)
}
Expand Down
5 changes: 3 additions & 2 deletions snapshots/overlay/overlay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/pkg/testutil"
"github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/snapshots/overlay/overlayutils"
"github.com/containerd/containerd/snapshots/storage"
"github.com/containerd/containerd/snapshots/testsuite"
)
Expand Down Expand Up @@ -177,7 +178,7 @@ func testOverlayOverlayMount(t *testing.T, newSnapshotter testsuite.SnapshotterF
expected := []string{
"index=off",
}
if userxattr, err := NeedsUserXAttr(root); err != nil {
if userxattr, err := overlayutils.NeedsUserXAttr(root); err != nil {
t.Fatal(err)
} else if userxattr {
expected = append(expected, "userxattr")
Expand Down Expand Up @@ -346,7 +347,7 @@ func testOverlayView(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) {
}

expectedOptions := 2
userxattr, err := NeedsUserXAttr(root)
userxattr, err := overlayutils.NeedsUserXAttr(root)
if err != nil {
t.Fatal(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
limitations under the License.
*/

package overlay
package overlayutils

import (
"fmt"
Expand All @@ -31,14 +31,14 @@ import (
"github.com/pkg/errors"
)

// supportsMultipleLowerDir checks if the system supports multiple lowerdirs,
// SupportsMultipleLowerDir checks if the system supports multiple lowerdirs,
// which is required for the overlay snapshotter. On 4.x kernels, multiple lowerdirs
// are always available (so this check isn't needed), and backported to RHEL and
// CentOS 3.x kernels (3.10.0-693.el7.x86_64 and up). This function is to detect
// support on those kernels, without doing a kernel version compare.
//
// Ported from moby overlay2.
func supportsMultipleLowerDir(d string) error {
func SupportsMultipleLowerDir(d string) error {
td, err := ioutil.TempDir(d, "multiple-lowerdir-check")
if err != nil {
return err
Expand Down Expand Up @@ -85,7 +85,7 @@ func Supported(root string) error {
if !supportsDType {
return fmt.Errorf("%s does not support d_type. If the backing filesystem is xfs, please reformat with ftype=1 to enable d_type support", root)
}
return supportsMultipleLowerDir(root)
return SupportsMultipleLowerDir(root)
}

// NeedsUserXAttr returns whether overlayfs should be mounted with the "userxattr" mount option.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
limitations under the License.
*/

package overlay
package overlayutils

import (
"io/ioutil"
Expand Down

0 comments on commit ba8f984

Please sign in to comment.