Skip to content

Commit

Permalink
Bump twpayne/vfs module to latest version
Browse files Browse the repository at this point in the history
Specifically bumping from v1.7.2 to v4.3.0. We were pretty outdated.

This commit could not get rid of the old version dependency completely
because yip requires a vfs v1 within the plugin API and we implement
a yip plugin for partitioning in elemental-toolkit. Because of that
both versions are coexisting.

Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany committed Jan 19, 2024
1 parent ec43513 commit 2e18efa
Show file tree
Hide file tree
Showing 48 changed files with 1,500 additions and 225 deletions.
4 changes: 2 additions & 2 deletions cmd/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/rancher/elemental-toolkit/pkg/constants"
v1mock "github.com/rancher/elemental-toolkit/pkg/mocks"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tredoe/osutil/v2 v2.0.0-rc.16 // indirect
github.com/twpayne/go-vfs/v4 v4.3.0
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vbatts/tar-split v0.11.3 // indirect
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c h1:kMFnB0vCcX
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/alecthomas/assert/v2 v2.3.0 h1:mAsH2wmvjsuvyBvAmCtm7zFsBlb8mIHx5ySLVdDZXL0=
github.com/alecthomas/assert/v2 v2.3.0/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk=
github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
Expand Down Expand Up @@ -279,6 +283,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
Expand Down Expand Up @@ -494,6 +500,8 @@ github.com/tredoe/osutil/v2 v2.0.0-rc.16 h1:5A2SKvyB2c3lhPYUIHyFtu6jbaXlaA3Hu5gW
github.com/tredoe/osutil/v2 v2.0.0-rc.16/go.mod h1:uLRVx/3pb7Y4RQhG8cQFbPE9ha5r81e6MXpBsxbTAYc=
github.com/twpayne/go-vfs v1.7.2 h1:ZNYMAXcu2Av8c109USrSGYm8dIIIV0xPlG19I2088Kw=
github.com/twpayne/go-vfs v1.7.2/go.mod h1:1eni2ntkiiAHZG27xfLOO4CYvMR4Kw8V7rYiLeeolsQ=
github.com/twpayne/go-vfs/v4 v4.3.0 h1:rTqFzzOQ/6ESKTSiwVubHlCBedJDOhQyVSnw8rQNZhU=
github.com/twpayne/go-vfs/v4 v4.3.0/go.mod h1:tq2UVhnUepesc0lSnPJH/jQ8HruGhzwZe2r5kDFpEIw=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/build-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func Raw2Gce(source string, fs v1.FS, logger v1.Logger, keepOldImage bool) error
// The disk image filename must be disk.raw.
// The compressed file must be a .tar.gz file that uses gzip compression and the --format=oldgnu option for the tar utility.
logger.Info("Transforming raw image into gce format")
actImg, err := fs.Open(source)
actImg, err := fs.OpenFile(source, os.O_CREATE|os.O_APPEND|os.O_WRONLY, constants.FilePerm)
if err != nil {
return elementalError.NewFromError(err, elementalError.OpenFile)
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/action/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import (
"encoding/binary"
"encoding/hex"
"errors"
"os"
"path/filepath"
"strconv"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/rancher/elemental-toolkit/pkg/action"
"github.com/rancher/elemental-toolkit/pkg/config"
Expand Down Expand Up @@ -375,7 +376,7 @@ var _ = Describe("Build Actions", func() {
Expect(info.Size()).To(BeNumerically("==", 23*1024*1024))

// Read the header
f, _ = fs.Open(filepath.Join(tmpDir, "disk.raw.vhd"))
f, _ = fs.OpenFile(filepath.Join(tmpDir, "disk.raw.vhd"), os.O_RDONLY, constants.FilePerm)
info, _ = f.Stat()
// Dump the header from the file into our VHDHeader
buff := make([]byte, 512)
Expand Down Expand Up @@ -415,7 +416,7 @@ var _ = Describe("Build Actions", func() {
Expect(info.Size()).To(BeNumerically("==", 1*1024*1024))

// Read the header
f, _ = fs.Open(filepath.Join(tmpDir, "disk.raw.vhd"))
f, _ = fs.OpenFile(filepath.Join(tmpDir, "disk.raw.vhd"), os.O_RDONLY, constants.FilePerm)
info, _ = f.Stat()
// Dump the header from the file into our VHDHeader
buff := make([]byte, 512)
Expand Down
4 changes: 2 additions & 2 deletions pkg/action/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/rancher/elemental-toolkit/pkg/action"
"github.com/rancher/elemental-toolkit/pkg/config"
Expand Down
4 changes: 2 additions & 2 deletions pkg/action/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/rancher/elemental-toolkit/pkg/action"
conf "github.com/rancher/elemental-toolkit/pkg/config"
Expand Down
4 changes: 2 additions & 2 deletions pkg/action/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"
"k8s.io/mount-utils"

"github.com/rancher/elemental-toolkit/pkg/action"
Expand Down
4 changes: 2 additions & 2 deletions pkg/action/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/jaypipes/ghw/pkg/block"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/rancher/elemental-toolkit/pkg/action"
conf "github.com/rancher/elemental-toolkit/pkg/config"
Expand Down
4 changes: 2 additions & 2 deletions pkg/action/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/rancher/elemental-toolkit/pkg/action"
conf "github.com/rancher/elemental-toolkit/pkg/config"
Expand Down
4 changes: 2 additions & 2 deletions pkg/bootloader/grub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
v1mock "github.com/rancher/elemental-toolkit/pkg/mocks"
v1 "github.com/rancher/elemental-toolkit/pkg/types/v1"
"github.com/rancher/elemental-toolkit/pkg/utils"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"
)

var _ = Describe("Booloader", Label("bootloader", "grub"), func() {
Expand Down
39 changes: 32 additions & 7 deletions pkg/cloudinit/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
"github.com/mudler/yip/pkg/schema"
"github.com/rancher/elemental-toolkit/pkg/constants"
"github.com/rancher/elemental-toolkit/pkg/utils"
"github.com/twpayne/go-vfs"
v1vfs "github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"
"gopkg.in/yaml.v3"

v1 "github.com/rancher/elemental-toolkit/pkg/types/v1"
Expand All @@ -33,12 +35,37 @@ import (
type YipCloudInitRunner struct {
exec executor.Executor
fs vfs.FS
v1fs v1vfs.FS
console plugins.Console
}

// NewYipCloudInitRunner returns a default yip cloud init executor with the Elemental plugin set.
// It accepts a logger which is used inside the runner.
func NewYipCloudInitRunner(l v1.Logger, r v1.Runner, fs vfs.FS) *YipCloudInitRunner {
var v1fs v1vfs.FS
var err error
var root string

// This is just to convert vfs instances of version v4 to equivalents of version 1
// required because yip is stuck on v1 and the plugin API requries a v1
v1fs = v1vfs.OSFS
if _, ok := fs.(*vfst.TestFS); ok {
root, err = fs.RawPath("/")
if err != nil {
l.Errorf("failed to set testfs to yip runner: %v. Fallback to v1vfs.OSFS filesystem.", err)
v1fs = v1vfs.OSFS
} else {
v1fs = v1vfs.NewPathFS(v1fs, root)
l.Debugf("Yip running on a TestFS based on %s", root)
}
} else if _, ok := fs.(*vfs.ReadOnlyFS); ok {
v1fs = v1vfs.NewReadOnlyFS(v1vfs.OSFS)
}

y := &YipCloudInitRunner{
fs: fs, console: newCloudInitConsole(l, r),
v1fs: v1fs,
}
exec := executor.NewExecutor(
executor.WithConditionals(
plugins.NodeConditional,
Expand All @@ -65,17 +92,15 @@ func NewYipCloudInitRunner(l v1.Logger, r v1.Runner, fs vfs.FS) *YipCloudInitRun
plugins.Environment,
plugins.SystemdFirstboot,
plugins.DataSources,
layoutPlugin,
y.layoutPlugin,
),
)
return &YipCloudInitRunner{
exec: exec, fs: fs,
console: newCloudInitConsole(l, r),
}
y.exec = exec
return y
}

func (ci YipCloudInitRunner) Run(stage string, args ...string) error {
return ci.exec.Run(stage, ci.fs, ci.console, args...)
return ci.exec.Run(stage, ci.v1fs, ci.console, args...)
}

func (ci *YipCloudInitRunner) SetModifier(m schema.Modifier) {
Expand Down
14 changes: 11 additions & 3 deletions pkg/cloudinit/cloudinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package cloudinit_test

import (
"bytes"
"errors"
"fmt"
"io"
Expand All @@ -26,8 +27,8 @@ import (
"github.com/jaypipes/ghw/pkg/block"
"github.com/mudler/yip/pkg/schema"

"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

. "github.com/rancher/elemental-toolkit/pkg/cloudinit"
"github.com/rancher/elemental-toolkit/pkg/constants"
Expand All @@ -49,7 +50,13 @@ const printOutput = `BYT;
var _ = Describe("CloudRunner", Label("CloudRunner", "types", "cloud-init"), func() {
// unit test stolen from yip
Describe("loading yaml files", func() {
logger := v1.NewNullLogger()
var logger v1.Logger
var buffer *bytes.Buffer
BeforeEach(func() {
buffer = bytes.NewBuffer([]byte{})
logger = v1.NewBufferLogger(buffer)
logger.SetLevel(v1.DebugLevel())
})

It("executes commands", func() {

Expand Down Expand Up @@ -85,6 +92,7 @@ stages:
Expect(err).Should(BeNil())

runner := NewYipCloudInitRunner(logger, &v1.RealRunner{}, fs)
Expect(buffer.String()).To(ContainSubstring("running on a TestFS"))

err = runner.Run("test", "/some/yip")
Expect(err).Should(BeNil())
Expand Down
9 changes: 5 additions & 4 deletions pkg/cloudinit/layout_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
"github.com/mudler/yip/pkg/logger"
"github.com/mudler/yip/pkg/plugins"
"github.com/mudler/yip/pkg/schema"
"github.com/twpayne/go-vfs"

v1vfs "github.com/twpayne/go-vfs"

"github.com/rancher/elemental-toolkit/pkg/constants"
"github.com/rancher/elemental-toolkit/pkg/partitioner"
Expand All @@ -34,7 +35,7 @@ import (

// layoutPlugin is the elemental's implementation of Layout yip's plugin based
// on partitioner package
func layoutPlugin(l logger.Interface, s schema.Stage, fs vfs.FS, console plugins.Console) (err error) {
func (y YipCloudInitRunner) layoutPlugin(l logger.Interface, s schema.Stage, _ v1vfs.FS, console plugins.Console) (err error) {
if s.Layout.Device == nil {
return nil
}
Expand All @@ -60,14 +61,14 @@ func layoutPlugin(l logger.Interface, s schema.Stage, fs vfs.FS, console plugins
partDevice.Disk,
partitioner.WithRunner(runner),
partitioner.WithLogger(log),
partitioner.WithFS(fs),
partitioner.WithFS(y.fs),
)
} else if len(strings.TrimSpace(s.Layout.Device.Path)) > 0 {
dev = partitioner.NewDisk(
s.Layout.Device.Path,
partitioner.WithRunner(runner),
partitioner.WithLogger(log),
partitioner.WithFS(fs),
partitioner.WithFS(y.fs),
)
} else {
l.Warnf("No target device defined, nothing to do")
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"runtime"
"strings"

"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/v4"

"github.com/rancher/elemental-toolkit/pkg/cloudinit"
"github.com/rancher/elemental-toolkit/pkg/constants"
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/jaypipes/ghw/pkg/block"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/rancher/elemental-toolkit/pkg/config"
"github.com/rancher/elemental-toolkit/pkg/constants"
Expand Down
4 changes: 2 additions & 2 deletions pkg/elemental/elemental_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

conf "github.com/rancher/elemental-toolkit/pkg/config"
"github.com/rancher/elemental-toolkit/pkg/constants"
Expand Down
2 changes: 1 addition & 1 deletion pkg/partitioner/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strings"
"time"

"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/v4"

v1 "github.com/rancher/elemental-toolkit/pkg/types/v1"
"github.com/rancher/elemental-toolkit/pkg/utils"
Expand Down
4 changes: 2 additions & 2 deletions pkg/partitioner/partitioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/rancher/elemental-toolkit/pkg/constants"
mocks "github.com/rancher/elemental-toolkit/pkg/mocks"
Expand Down
4 changes: 2 additions & 2 deletions pkg/snapshotter/loopdevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"github.com/rancher/elemental-toolkit/pkg/snapshotter"
v1 "github.com/rancher/elemental-toolkit/pkg/types/v1"
"github.com/rancher/elemental-toolkit/pkg/utils"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"
)

var _ = Describe("LoopDevice", Label("snapshotter", "loopdevice"), func() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/v1/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/twpayne/go-vfs"
"github.com/twpayne/go-vfs/vfst"
"github.com/twpayne/go-vfs/v4"
"github.com/twpayne/go-vfs/v4/vfst"

"github.com/rancher/elemental-toolkit/pkg/config"
conf "github.com/rancher/elemental-toolkit/pkg/config"
Expand Down

0 comments on commit 2e18efa

Please sign in to comment.