Rename fs package to filesys

This commit is contained in:
Jeffrey Regan
2019-10-14 10:41:49 -07:00
parent c4eca908ac
commit 9e3b837093
74 changed files with 309 additions and 333 deletions

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import (
"io/ioutil"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import (
"path/filepath"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import (
"os"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import (
"bytes"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import (
"os"

View File

@@ -1,8 +1,8 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package fs provides a file system abstraction layer.
package fs
// Package filesys provides a file system abstraction layer.
package filesys
import (
"io"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import (
"fmt"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import (
"bytes"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import (
"fmt"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import (
"io/ioutil"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fs
package filesys
import "path/filepath"

View File

@@ -1,18 +1,5 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package git
@@ -22,7 +9,7 @@ import (
"os/exec"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
)
// Cloner is a function that can clone a git repo.
@@ -36,7 +23,7 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
if err != nil {
return errors.Wrap(err, "no 'git' program on path")
}
repoSpec.Dir, err = fs.NewTmpConfirmedDir()
repoSpec.Dir, err = filesys.NewTmpConfirmedDir()
if err != nil {
return err
}
@@ -126,7 +113,7 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
// cloneDir field in the repoSpec. It's assumed that
// the cloneDir is associated with some fake filesystem
// used in a test.
func DoNothingCloner(dir fs.ConfirmedDir) Cloner {
func DoNothingCloner(dir filesys.ConfirmedDir) Cloner {
return func(rs *RepoSpec) error {
rs.Dir = dir
return nil

View File

@@ -1,18 +1,5 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package git
@@ -22,7 +9,7 @@ import (
"regexp"
"strings"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
)
// Used as a temporary non-empty occupant of the cloneDir
@@ -30,7 +17,7 @@ import (
// in various outputs (especially tests). Not using an
// actual directory name here, as that's a temporary directory
// with a unique name that isn't created until clone time.
const notCloned = fs.ConfirmedDir("/notCloned")
const notCloned = filesys.ConfirmedDir("/notCloned")
// RepoSpec specifies a git repository and a branch and path therein.
type RepoSpec struct {
@@ -46,7 +33,7 @@ type RepoSpec struct {
OrgRepo string
// Dir where the orgRepo is cloned to.
Dir fs.ConfirmedDir
Dir filesys.ConfirmedDir
// Relative path in the repository, and in the cloneDir,
// to a Kustomization.
@@ -67,7 +54,7 @@ func (x *RepoSpec) CloneSpec() string {
return x.Host + x.OrgRepo + x.GitSuffix
}
func (x *RepoSpec) CloneDir() fs.ConfirmedDir {
func (x *RepoSpec) CloneDir() filesys.ConfirmedDir {
return x.Dir
}
@@ -79,7 +66,7 @@ func (x *RepoSpec) AbsPath() string {
return x.Dir.Join(x.Path)
}
func (x *RepoSpec) Cleaner(fSys fs.FileSystem) func() error {
func (x *RepoSpec) Cleaner(fSys filesys.FileSystem) func() error {
return func() error { return fSys.RemoveAll(x.Dir.String()) }
}

View File

@@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
"sigs.k8s.io/kustomize/v3/pkg/git"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
)
@@ -74,7 +74,7 @@ type fileLoader struct {
// An absolute, cleaned path to a directory.
// The Load function will read non-absolute
// paths relative to this directory.
root fs.ConfirmedDir
root filesys.ConfirmedDir
// Restricts behavior of Load function.
loadRestrictor LoadRestrictorFunc
@@ -87,7 +87,7 @@ type fileLoader struct {
repoSpec *git.RepoSpec
// File system utilities.
fSys fs.FileSystem
fSys filesys.FileSystem
// Used to clone repositories.
cloner git.Cloner
@@ -100,14 +100,14 @@ const CWD = "."
// NewFileLoaderAtCwd returns a loader that loads from ".".
// A convenience for kustomize edit commands.
func NewFileLoaderAtCwd(v ifc.Validator, fSys fs.FileSystem) *fileLoader {
func NewFileLoaderAtCwd(v ifc.Validator, fSys filesys.FileSystem) *fileLoader {
return newLoaderOrDie(
RestrictionRootOnly, v, fSys, CWD)
}
// NewFileLoaderAtRoot returns a loader that loads from "/".
// A convenience for tests.
func NewFileLoaderAtRoot(v ifc.Validator, fSys fs.FileSystem) *fileLoader {
func NewFileLoaderAtRoot(v ifc.Validator, fSys filesys.FileSystem) *fileLoader {
return newLoaderOrDie(
RestrictionRootOnly, v, fSys, string(filepath.Separator))
}
@@ -120,7 +120,7 @@ func (fl *fileLoader) Root() string {
func newLoaderOrDie(
lr LoadRestrictorFunc, v ifc.Validator,
fSys fs.FileSystem, path string) *fileLoader {
fSys filesys.FileSystem, path string) *fileLoader {
root, err := demandDirectoryRoot(fSys, path)
if err != nil {
log.Fatalf("unable to make loader at '%s'; %v", path, err)
@@ -133,7 +133,7 @@ func newLoaderOrDie(
func newLoaderAtConfirmedDir(
lr LoadRestrictorFunc,
v ifc.Validator,
root fs.ConfirmedDir, fSys fs.FileSystem,
root filesys.ConfirmedDir, fSys filesys.FileSystem,
referrer *fileLoader, cloner git.Cloner) *fileLoader {
return &fileLoader{
loadRestrictor: lr,
@@ -148,7 +148,7 @@ func newLoaderAtConfirmedDir(
// Assure that the given path is in fact a directory.
func demandDirectoryRoot(
fSys fs.FileSystem, path string) (fs.ConfirmedDir, error) {
fSys filesys.FileSystem, path string) (filesys.ConfirmedDir, error) {
if path == "" {
return "", fmt.Errorf(
"loader root cannot be empty")
@@ -202,7 +202,7 @@ func (fl *fileLoader) New(path string) (ifc.Loader, error) {
// directory holding a cloned git repo.
func newLoaderAtGitClone(
repoSpec *git.RepoSpec,
v ifc.Validator, fSys fs.FileSystem,
v ifc.Validator, fSys filesys.FileSystem,
referrer *fileLoader, cloner git.Cloner) (ifc.Loader, error) {
cleaner := repoSpec.Cleaner(fSys)
err := cloner(repoSpec)
@@ -239,7 +239,7 @@ func newLoaderAtGitClone(
}
func (fl *fileLoader) errIfGitContainmentViolation(
base fs.ConfirmedDir) error {
base filesys.ConfirmedDir) error {
containingRepo := fl.containingRepo()
if containingRepo == nil {
return nil
@@ -269,7 +269,7 @@ func (fl *fileLoader) containingRepo() *git.RepoSpec {
// errIfArgEqualOrHigher tests whether the argument,
// is equal to or above the root of any ancestor.
func (fl *fileLoader) errIfArgEqualOrHigher(
candidateRoot fs.ConfirmedDir) error {
candidateRoot filesys.ConfirmedDir) error {
if fl.root.HasPrefix(candidateRoot) {
return fmt.Errorf(
"cycle detected: candidate root '%s' contains visited root '%s'",

View File

@@ -25,7 +25,7 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
"sigs.k8s.io/kustomize/v3/pkg/git"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
@@ -56,8 +56,8 @@ var testCases = []testData{
},
}
func MakeFakeFs(td []testData) fs.FileSystem {
fSys := fs.MakeFsInMemory()
func MakeFakeFs(td []testData) filesys.FileSystem {
fSys := filesys.MakeFsInMemory()
for _, x := range td {
fSys.WriteFile("/"+x.path, []byte(x.expectedContent))
}
@@ -225,12 +225,12 @@ const (
// │ └── symLinkToExteriorData -> ../exteriorData
// └── exteriorData
//
func commonSetupForLoaderRestrictionTest() (string, fs.FileSystem, error) {
func commonSetupForLoaderRestrictionTest() (string, filesys.FileSystem, error) {
dir, err := ioutil.TempDir("", "kustomize-test-")
if err != nil {
return "", nil, err
}
fSys := fs.MakeFsOnDisk()
fSys := filesys.MakeFsOnDisk()
fSys.Mkdir(filepath.Join(dir, "base"))
fSys.WriteFile(
@@ -385,7 +385,7 @@ func TestNewLoaderAtGitClone(t *testing.T) {
pathInRepo := "foo/base"
url := rootUrl + "/" + pathInRepo
coRoot := "/tmp"
fSys := fs.MakeFsInMemory()
fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(coRoot)
fSys.MkdirAll(coRoot + "/" + pathInRepo)
fSys.WriteFile(
@@ -401,7 +401,7 @@ whatever
}
l, err := newLoaderAtGitClone(
repoSpec, validators.MakeFakeValidator(), fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(coRoot)))
git.DoNothingCloner(filesys.ConfirmedDir(coRoot)))
if err != nil {
t.Fatalf("unexpected err: %v\n", err)
}
@@ -433,7 +433,7 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
// Define an overlay-base structure in the file system.
topDir := "/whatever"
cloneRoot := topDir + "/someClone"
fSys := fs.MakeFsInMemory()
fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(topDir + "/highBase")
fSys.MkdirAll(cloneRoot + "/foo/base")
fSys.MkdirAll(cloneRoot + "/foo/overlay")
@@ -480,7 +480,7 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
}
l1, err = newLoaderAtGitClone(
repoSpec, validators.MakeFakeValidator(), fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(cloneRoot)))
git.DoNothingCloner(filesys.ConfirmedDir(cloneRoot)))
if err != nil {
t.Fatalf("unexpected err: %v\n", err)
}
@@ -509,7 +509,7 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
func TestLocalLoaderReferencingGitBase(t *testing.T) {
topDir := "/whatever"
cloneRoot := topDir + "/someClone"
fSys := fs.MakeFsInMemory()
fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(topDir)
fSys.MkdirAll(cloneRoot + "/foo/base")
@@ -519,7 +519,7 @@ func TestLocalLoaderReferencingGitBase(t *testing.T) {
}
l1 := newLoaderAtConfirmedDir(
RestrictionRootOnly, validators.MakeFakeValidator(), root, fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(cloneRoot)))
git.DoNothingCloner(filesys.ConfirmedDir(cloneRoot)))
if l1.Root() != topDir {
t.Fatalf("unexpected root %s", l1.Root())
}
@@ -535,7 +535,7 @@ func TestLocalLoaderReferencingGitBase(t *testing.T) {
func TestRepoDirectCycleDetection(t *testing.T) {
topDir := "/cycles"
cloneRoot := topDir + "/someClone"
fSys := fs.MakeFsInMemory()
fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(topDir)
fSys.MkdirAll(cloneRoot)
@@ -545,7 +545,7 @@ func TestRepoDirectCycleDetection(t *testing.T) {
}
l1 := newLoaderAtConfirmedDir(
RestrictionRootOnly, validators.MakeFakeValidator(), root, fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(cloneRoot)))
git.DoNothingCloner(filesys.ConfirmedDir(cloneRoot)))
p1 := "github.com/someOrg/someRepo/foo"
rs1, err := git.NewRepoSpecFromUrl(p1)
if err != nil {
@@ -564,7 +564,7 @@ func TestRepoDirectCycleDetection(t *testing.T) {
func TestRepoIndirectCycleDetection(t *testing.T) {
topDir := "/cycles"
cloneRoot := topDir + "/someClone"
fSys := fs.MakeFsInMemory()
fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(topDir)
fSys.MkdirAll(cloneRoot)
@@ -574,7 +574,7 @@ func TestRepoIndirectCycleDetection(t *testing.T) {
}
l0 := newLoaderAtConfirmedDir(
RestrictionRootOnly, validators.MakeFakeValidator(), root, fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(cloneRoot)))
git.DoNothingCloner(filesys.ConfirmedDir(cloneRoot)))
p1 := "github.com/someOrg/someRepo1"
p2 := "github.com/someOrg/someRepo2"

View File

@@ -7,7 +7,7 @@ import (
"reflect"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
"sigs.k8s.io/kustomize/v3/pkg/types"
"sigs.k8s.io/kustomize/v3/pkg/validators"
)
@@ -46,7 +46,7 @@ func TestKeyValuesFromLines(t *testing.T) {
}
l := NewFileLoaderAtRoot(
validators.MakeFakeValidator(), fs.MakeFsInMemory())
validators.MakeFakeValidator(), filesys.MakeFsInMemory())
for _, test := range tests {
pairs, err := l.keyValuesFromLines([]byte(test.content))
if test.expectedErr && err == nil {
@@ -76,7 +76,7 @@ func TestKeyValuesFromFileSources(t *testing.T) {
},
}
fSys := fs.MakeFsInMemory()
fSys := filesys.MakeFsInMemory()
fSys.WriteFile("/files/app-init.ini", []byte("FOO=bar"))
l := NewFileLoaderAtRoot(validators.MakeFakeValidator(), fSys)
for _, tc := range tests {

View File

@@ -1,24 +1,11 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package loader has a data loading interface and various implementations.
package loader
import (
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
"sigs.k8s.io/kustomize/v3/pkg/git"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
)
@@ -32,7 +19,7 @@ import (
func NewLoader(
lr LoadRestrictorFunc,
v ifc.Validator,
target string, fSys fs.FileSystem) (ifc.Loader, error) {
target string, fSys filesys.FileSystem) (ifc.Loader, error) {
repoSpec, err := git.NewRepoSpecFromUrl(target)
if err == nil {
// The target qualifies as a remote git target.

View File

@@ -1,18 +1,5 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package loader
@@ -20,7 +7,7 @@ import (
"fmt"
"github.com/spf13/pflag"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
)
//go:generate stringer -type=loadRestrictions
@@ -64,10 +51,10 @@ func ValidateFlagLoadRestrictor() (LoadRestrictorFunc, error) {
}
type LoadRestrictorFunc func(
fs.FileSystem, fs.ConfirmedDir, string) (string, error)
filesys.FileSystem, filesys.ConfirmedDir, string) (string, error)
func RestrictionRootOnly(
fSys fs.FileSystem, root fs.ConfirmedDir, path string) (string, error) {
fSys filesys.FileSystem, root filesys.ConfirmedDir, path string) (string, error) {
d, f, err := fSys.CleanedAbs(path)
if err != nil {
return "", err
@@ -84,6 +71,6 @@ func RestrictionRootOnly(
}
func RestrictionNone(
_ fs.FileSystem, _ fs.ConfirmedDir, path string) (string, error) {
_ filesys.FileSystem, _ filesys.ConfirmedDir, path string) (string, error) {
return path, nil
}

View File

@@ -20,12 +20,12 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
)
func TestRestrictionNone(t *testing.T) {
fSys := fs.MakeFsInMemory()
root := fs.ConfirmedDir("irrelevant")
fSys := filesys.MakeFsInMemory()
root := filesys.ConfirmedDir("irrelevant")
path := "whatever"
p, err := RestrictionNone(fSys, root, path)
if err != nil {
@@ -37,8 +37,8 @@ func TestRestrictionNone(t *testing.T) {
}
func TestRestrictionRootOnly(t *testing.T) {
fSys := fs.MakeFsInMemory()
root := fs.ConfirmedDir("/tmp/foo")
fSys := filesys.MakeFsInMemory()
root := filesys.ConfirmedDir("/tmp/foo")
path := "/tmp/foo/whatever/beans"
p, err := RestrictionRootOnly(fSys, root, path)

View File

@@ -9,7 +9,7 @@ import (
"testing"
"sigs.k8s.io/kustomize/v3/internal/loadertest"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/loader"
@@ -234,7 +234,7 @@ func TestNewResMapFromSecretArgs(t *testing.T) {
Type: ifc.SecretTypeOpaque,
},
}
fSys := fs.MakeFsInMemory()
fSys := filesys.MakeFsInMemory()
fSys.Mkdir(".")
actual, err := rmF.NewResMapFromSecretArgs(
loader.NewFileLoaderAtRoot(validators.MakeFakeValidator(), fSys), nil, secrets)

View File

@@ -11,7 +11,7 @@ import (
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/k8sdeps/transformer"
"sigs.k8s.io/kustomize/v3/pkg/fs"
"sigs.k8s.io/kustomize/v3/pkg/filesys"
"sigs.k8s.io/kustomize/v3/pkg/kusttest"
"sigs.k8s.io/kustomize/v3/pkg/loader"
"sigs.k8s.io/kustomize/v3/pkg/plugins"
@@ -39,7 +39,7 @@ func TestPluginDir(t *testing.T) {
}
defer os.RemoveAll(dir)
fSys := fs.MakeFsOnDisk()
fSys := filesys.MakeFsOnDisk()
err = fSys.WriteFile(filepath.Join(dir, "kustomization.yaml"), []byte(`
generators:
- config.yaml