Compare commits

...

107 Commits

Author SHA1 Message Date
Jeff Regan
0a8faced8f Merge pull request #1679 from monopole/updateCloudbuildAgain
Improve the release process instructions
2019-10-22 16:16:36 -07:00
Jeff Regan
3c06debf98 Merge pull request #1678 from monopole/fixCliInternalDeps
Fix internal kustomize CLI deps
2019-10-22 16:14:39 -07:00
Jeff Regan
fcee91eafd Merge pull request #1678 from monopole/fixCliInternalDeps
Fix internal kustomize CLI deps
2019-10-22 15:37:37 -07:00
Jeffrey Regan
b0b3a705f4 Fix internal kustomize CLI deps 2019-10-22 15:27:57 -07:00
Jeff Regan
67c8fbcc3c Merge pull request #1676 from monopole/useLatestCloudbuilderSigh
Use latest cloudbuilder image.
2019-10-22 12:50:33 -07:00
Jeffrey Regan
9b50b78ec8 Use latest cloudbuilder image. 2019-10-22 12:49:38 -07:00
Jeff Regan
943a1b0195 Merge pull request #1675 from monopole/pinKustomizeToApiV011
Pin kustomize CLI to API v0.1.1
2019-10-22 12:40:12 -07:00
Jeffrey Regan
f77143cd34 Pin kustomize CLI to API v0.1.1 2019-10-22 12:32:05 -07:00
Jeff Regan
b7d2ba2376 Merge pull request #1674 from monopole/dealWithDeprecationsInGoReleaser
Deal with goreleaser field deprecations.
2019-10-22 12:12:34 -07:00
Jeffrey Regan
c28a0eb83d Deal with goreleaser field deprecations. 2019-10-22 12:11:13 -07:00
Jeff Regan
f7e5b5138b Merge pull request #1673 from monopole/moreTweaks
Add tag check to release script
2019-10-22 11:52:55 -07:00
Jeffrey Regan
61149cbf21 Add tag check to release script 2019-10-22 11:51:26 -07:00
Jeff Regan
310d516030 Update README.md 2019-10-22 10:16:51 -07:00
Jeff Regan
a9e3fe155b Merge pull request #1672 from monopole/moreReleasingTweaks
Pin the cloudbuild step container tags.
2019-10-22 10:13:32 -07:00
Jeffrey Regan
24837bad40 More releasing tweaks. 2019-10-22 10:10:47 -07:00
Jeff Regan
3063560e77 Merge pull request #1670 from monopole/installKubevalNotes
Add kubeval install notes.
2019-10-21 19:34:41 -07:00
jregan
bff0604bee Add kubeval install notes. 2019-10-21 19:33:45 -07:00
Jeff Regan
9f8faa7d7e Merge pull request #1669 from monopole/cloudBuildTake9834
Cloud build adjustments.
2019-10-21 19:03:03 -07:00
jregan
335077eade Cloud build adjustments. 2019-10-21 19:00:52 -07:00
Jeff Regan
491baa74cb Merge pull request #1668 from monopole/tweakReleaseProcess
Experimenting with cloud build and goreleaser
2019-10-21 17:33:52 -07:00
Jeff Regan
2f2d078669 Update README.md 2019-10-21 17:31:40 -07:00
Jeff Regan
b7bcb90057 Update README.md 2019-10-21 16:43:35 -07:00
Jeff Regan
35dc15b16b Merge pull request #1667 from monopole/setupApiRelease
Define the API release process.
2019-10-21 16:37:41 -07:00
Jeffrey Regan
83f70877c8 Define the API release process. 2019-10-21 16:24:16 -07:00
Jeff Regan
98cd31b820 Merge pull request #1666 from monopole/modulesForAll
Each plugin gets its own module.
2019-10-21 16:16:25 -07:00
Jeffrey Regan
5416ae7365 Introduce API module. 2019-10-21 15:21:04 -07:00
Kubernetes Prow Robot
644f2ddcdc Merge pull request #1665 from monopole/introduceApiModule
Introduce API module.
2019-10-21 15:13:22 -07:00
Jeffrey Regan
46524d3b6a Introduce API module. 2019-10-21 13:30:31 -07:00
Jeff Regan
4f014d0262 Merge pull request #1664 from monopole/moveGeneratedCode
Move generated code
2019-10-21 13:21:19 -07:00
Jeffrey Regan
0cf2057fc5 Install generated plugin code into the API module. 2019-10-21 11:15:51 -07:00
Jeffrey Regan
3f08e1546c Move generated plugin code. 2019-10-21 09:48:11 -07:00
Jeff Regan
10619fb0f7 Merge pull request #1662 from monopole/builtinNestingPlace
Make new nesting place for generated builtin code.
2019-10-20 17:53:02 -07:00
jregan
c88e8cc057 Make new nesting place for generated builtin code. 2019-10-20 17:41:09 -07:00
Jeff Regan
327a3f5300 Merge pull request #1661 from monopole/moveK8sdeps
Move ks8deps to api for now.
2019-10-20 16:51:47 -07:00
jregan
fddde81f9c Move ks8deps to api for now. 2019-10-20 16:49:53 -07:00
Jeff Regan
22d07ed37d Merge pull request #1660 from monopole/drainTopInternal
Drain top internal folder
2019-10-20 16:14:08 -07:00
jregan
dee1c425da Drain the top level internal. 2019-10-20 15:51:04 -07:00
jregan
951d15bf17 Make api/plugins 2019-10-20 15:12:13 -07:00
Jeff Regan
0f82d2932c Merge pull request #1658 from monopole/makeInventoryPublic
Make inventory public.
2019-10-20 11:46:09 -07:00
jregan
e2d7a06e9f Make inventory public. 2019-10-20 11:43:36 -07:00
Jeff Regan
286b9c1aed Merge pull request #1657 from monopole/makeGitPrivate
Make git package private
2019-10-20 11:43:25 -07:00
jregan
f54d4a5837 Make git package private 2019-10-20 11:36:10 -07:00
Jeff Regan
d9031fb2c9 Merge pull request #1656 from monopole/makeResourcePublic
Make resource, resmap and ifc public.
2019-10-20 11:14:22 -07:00
jregan
3af5a8afea Make resource, resmap public. 2019-10-20 10:51:20 -07:00
Jeff Regan
e2fd33c54a Merge pull request #1655 from monopole/drainPkgTransformers
Drain pkg transformers
2019-10-20 09:50:59 -07:00
jregan
c90e0a4080 Drain pkg/transformers. 2019-10-20 09:19:07 -07:00
jregan
5de000ee3d Move FieldSpec to API. 2019-10-20 06:52:13 -07:00
Jeff Regan
c28b82510c Merge pull request #1654 from monopole/makeSmpPrivate
Make SMP code private to CLI.
2019-10-18 17:16:10 -07:00
jregan
fda3ba8af9 Make SMP code private to CLI. 2019-10-18 17:14:43 -07:00
Kubernetes Prow Robot
fd1356e5d8 Merge pull request #1653 from monopole/docsUpdate
Update docs
2019-10-18 13:13:37 -07:00
jregan
a62f1364fe Update docs 2019-10-18 12:46:36 -07:00
Jeff Regan
d1240bcc63 Update INSTALL.md 2019-10-18 10:48:54 -07:00
Jeff Regan
1c24fe7d16 Merge pull request #1651 from monopole/startApi
Start api directory, which will become the api module.
2019-10-17 15:03:57 -07:00
Jeffrey Regan
e5c8b5ec8f Start api directory, which will become a module. 2019-10-17 14:01:20 -07:00
Jeff Regan
180429774a Merge pull request #1649 from monopole/fixNits
fixNits
2019-10-17 11:16:46 -07:00
Jeffrey Regan
586bba0b31 fixNits 2019-10-17 11:15:10 -07:00
Jeff Regan
2ce138ab3a Update awker.sh 2019-10-16 20:40:21 -07:00
Jeff Regan
5e99ad000e Merge pull request #1645 from monopole/docTypes
Document the types package.
2019-10-16 17:25:05 -07:00
jregan
0f0e740c21 Document the types package. 2019-10-16 17:24:21 -07:00
Kubernetes Prow Robot
33600189bc Merge pull request #1644 from monopole/makeTypesPublic
Make types package public.
2019-10-16 16:58:38 -07:00
jregan
07d2500ee3 Make types package public. 2019-10-16 16:41:43 -07:00
Jeff Regan
de6eb14867 Merge pull request #1643 from monopole/cleanupTypes
Cleanup types package before going public.
2019-10-16 16:24:40 -07:00
jregan
85b71a31e3 Cleanup types package before going public. 2019-10-16 16:02:01 -07:00
Jeff Regan
16e7638220 Merge pull request #1642 from monopole/makeHasherPublic
Maker hasher public for now.
2019-10-16 14:21:44 -07:00
jregan
04c23b2085 Maker hasher public for now. 2019-10-16 12:25:09 -07:00
Kubernetes Prow Robot
24db94dd0d Merge pull request #1638 from dbachrach/f-edit-set-replicas
Add support for kustomize edit set replicas
2019-10-15 19:44:07 -07:00
Kubernetes Prow Robot
5f862ba17c Merge pull request #1639 from dbachrach/b-zero-replica-formatting
Fix yaml formatting of replicas count when count is 0
2019-10-15 17:00:13 -07:00
Jeff Regan
18ba3ee91b Merge pull request #1640 from monopole/moveKvStuff
Extract kv loader from file loader, and place in public package.
2019-10-15 16:59:21 -07:00
Jeffrey Regan
4e9d42fae7 Move kv loader code to public package. 2019-10-15 16:52:03 -07:00
Dustin Bachrach
52e57dab7f FIx yaml formatting of replicas count when count is 0
Previously, a count of 0 would cause the count field to be omitted from the yaml
2019-10-15 15:47:53 -07:00
Dustin Bachrach
ba464a5e11 Add support for kustomize edit set replicas
New command line tool for editing replica counts for resources.
Example:
  kustomize edit set replicas app=3 other-app=1
2019-10-15 15:43:10 -07:00
Jeff Regan
2734085fb0 Merge pull request #1634 from tkellen/gh-1600-failing
make failing test showing spurious variable conflicts
2019-10-15 14:24:28 -07:00
Tyler
d21ff7cfe6 make test pass with reference to bug 2019-10-15 16:59:32 -04:00
Jeff Regan
3a15f450a9 Merge pull request #1637 from monopole/renameDataSources
Rename DataSources to KvPairSources and remove deprecated env field.
2019-10-15 13:47:44 -07:00
Jeffrey Regan
bb77e7491a Rename DataSources to KvPairSources and remove deprecated env field. 2019-10-15 13:39:42 -07:00
Tyler
aa82240b4c use namespace value when making Var 2019-10-15 14:47:05 -04:00
Kubernetes Prow Robot
cac7b46ebd Merge pull request #1635 from beautytiger/dev-191015-trimfix
fix string trim in normalizeGitHostSpec func
2019-10-15 09:27:53 -07:00
Guangming Wang
367d0e042c fix string trim in normalizeGitHostSpec func
Signed-off-by: Guangming Wang <guangming.wang@daocloud.io>
2019-10-16 00:06:02 +08:00
Tyler
d851305c33 make failing test showing spurious variable conflicts 2019-10-15 00:33:33 -04:00
Jeff Regan
0c52bd71ba Merge pull request #1633 from monopole/startPlugLib
Start pluglib, a set of public, plugin specific functions.
2019-10-14 20:25:15 -07:00
Jeffrey Regan
41a008e9a3 Start pluglib, a set of public, plugin specific functions. 2019-10-14 19:43:55 -07:00
Jeff Regan
2fadb4dd59 Merge pull request #1630 from monopole/moveFilesysUp
Move filesys package up to make public.
2019-10-14 12:50:15 -07:00
Jeffrey Regan
a88ee3f93c Move filesys package up to make public. 2019-10-14 12:40:09 -07:00
Jeff Regan
237848a80b Merge pull request #1629 from monopole/renamePackageFsToFileSys
Rename fs package to filesys
2019-10-14 11:01:43 -07:00
Jeffrey Regan
9e3b837093 Rename fs package to filesys 2019-10-14 10:50:27 -07:00
Jeff Regan
c4eca908ac Merge pull request #1623 from monopole/removeVersionCheckFromMinecraft
Remove minecraft version check from chart plugin tests.
2019-10-12 13:03:22 -07:00
jregan
72d9b4cbca Remove minecraft version check from chart plugin tests. 2019-10-12 12:52:36 -07:00
Jeff Regan
19d94110b1 Merge pull request #1621 from scottnuma/patch-1
Update broken URL in Exec Plugin Tutorial
2019-10-12 10:10:41 -07:00
Jeff Regan
1756765dbc Merge pull request #1622 from monopole/fixNits
Fix some nits
2019-10-12 07:43:03 -07:00
jregan
b306f8511c Fix some nits 2019-10-12 07:42:04 -07:00
Scott Numamoto
9778f867b5 Update broken URL in Exec Plugin Tutorial
- link created in the scripts of Exec plugin on linux in 60 seconds to download the kustomize executable does not work
- used the [releases page](https://github.com/kubernetes-sigs/kustomize/releases/tag/v3.0.0) to fix
2019-10-12 01:02:16 -07:00
Jeff Regan
a69ebf2b11 Merge pull request #1576 from chenrui333/go-1.13
Upgrade golang to v1.13
2019-10-11 11:04:23 -07:00
Jeff Regan
cf9c81f908 Merge pull request #1615 from monopole/moreCodeToDiscussIn1297
More composition testing
2019-10-11 11:01:02 -07:00
Jeffrey Regan
b95164b9a8 More code to discuss in 1297 2019-10-11 10:37:29 -07:00
Rui Chen
0551338958 Merge branch 'master' of github.com:kubernetes-sigs/kustomize into go-1.13
* 'master' of github.com:kubernetes-sigs/kustomize: (27 commits)
  Update complexcomposition_test.go
  doc: add configmap generator key example
  tweakNamesInTest
  cleanup on errors in git loader
  refactor complexcomposition_test in prep for addition
  Update INSTALL.md
  Update INSTALL.md
  Introduce dummy program to help with API releases.
  fix zh-doc
  v3.3.0 release notes
  Move pluginator to kustomize Go API v3.3.0
  Three builders.
  Update README.md
  update release process doc
  improve tests for alternative kustomization file names
  Reduce size of pgmconfig package
  Break the dep between fs and pgmconfig.
  Improve fs package and doc in prep to officially go public
  Update versioning notes.
  Fix: documentation link for plugins
  ...
2019-10-11 11:18:20 -04:00
Kubernetes Prow Robot
40b7ad23ea Merge pull request #1618 from seriousben/add-configmap-key-example
doc: add configmap generator key example
2019-10-10 15:19:21 -07:00
Kubernetes Prow Robot
ce66ceeed6 Merge pull request #1616 from jeffmhastings/cleanup-git-clone-errors
cleanup on errors in git loader
2019-10-10 15:17:21 -07:00
Jeff Regan
4e45af6265 Update complexcomposition_test.go 2019-10-10 13:16:45 -07:00
Benjamin Boudreau
07a9454215 doc: add configmap generator key example 2019-10-10 16:11:37 -04:00
Jeff Regan
9f5a936236 Merge pull request #1617 from monopole/tweakNamesInTest
tweakNamesInTest
2019-10-10 13:04:25 -07:00
Jeffrey Regan
e6770e5f1e tweakNamesInTest 2019-10-10 13:03:55 -07:00
Jeff Hastings
705b4ab212 cleanup on errors in git loader 2019-10-10 15:54:56 -04:00
Jeff Regan
2cb964ab8e Merge pull request #1614 from monopole/refactorComplexTest
refactor complexcomposition_test in prep for addition
2019-10-10 11:28:27 -07:00
Jeffrey Regan
949b10bf93 refactor complexcomposition_test in prep for addition 2019-10-10 11:25:38 -07:00
Jeff Regan
cc4341c546 Update INSTALL.md 2019-10-09 11:16:19 -07:00
Jeff Regan
d0caea0ce1 Update INSTALL.md
fix #1604
2019-10-09 11:15:48 -07:00
Rui Chen
5caba59073 Upgrade golang to v1.13 2019-09-29 16:34:18 -04:00
464 changed files with 7040 additions and 5106 deletions

View File

@@ -1,7 +1,11 @@
os: os:
- linux - linux
- osx # TODO: Uncomment this when someone figures out how
# TODO: Uncomment when tests running on Windows. # to speed up the slowness of homebrew installation on
# oxs; presumably cache images?
# - osx
#
# TODO: Uncomment when some gets the tests running on Windows.
# - windows # - windows
addons: addons:
@@ -20,7 +24,7 @@ git:
language: go language: go
go: go:
- "1.12" - "1.13"
go_import_path: sigs.k8s.io/kustomize go_import_path: sigs.k8s.io/kustomize

View File

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

View File

@@ -1,11 +1,13 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package fs package filesys_test
import ( import (
"path/filepath" "path/filepath"
"testing" "testing"
. "sigs.k8s.io/kustomize/api/filesys"
) )
func TestJoin(t *testing.T) { func TestJoin(t *testing.T) {
@@ -27,7 +29,8 @@ func TestJoin(t *testing.T) {
} }
func TestHasPrefix_Slash(t *testing.T) { func TestHasPrefix_Slash(t *testing.T) {
d, f, err := MakeFsInMemory().CleanedAbs("/") fSys := MakeFsInMemory()
d, f, err := fSys.CleanedAbs("/")
if err != nil { if err != nil {
t.Fatalf("unexpected err: %v", err) t.Fatalf("unexpected err: %v", err)
} }

View File

@@ -1,9 +1,10 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package fs package filesys
import ( import (
"io"
"os" "os"
"time" "time"
) )
@@ -32,3 +33,9 @@ func (fi *fileInfo) IsDir() bool { return fi.dir }
// Sys should return underlying data source, but it now returns nil // Sys should return underlying data source, but it now returns nil
func (fi *fileInfo) Sys() interface{} { return nil } func (fi *fileInfo) Sys() interface{} { return nil }
// File groups the basic os.File methods.
type File interface {
io.ReadWriteCloser
Stat() (os.FileInfo, error)
}

View File

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

View File

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

View File

@@ -1,12 +1,10 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// Package fs provides a file system abstraction layer. // Package filesys provides a file system abstraction layer.
package fs package filesys
import ( import (
"io"
"os"
"path/filepath" "path/filepath"
) )
@@ -41,9 +39,3 @@ type FileSystem interface {
// Walk walks the file system with the given WalkFunc. // Walk walks the file system with the given WalkFunc.
Walk(path string, walkFn filepath.WalkFunc) error Walk(path string, walkFn filepath.WalkFunc) error
} }
// File groups the basic os.File methods.
type File interface {
io.ReadWriteCloser
Stat() (os.FileInfo, error)
}

View File

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

View File

@@ -1,110 +1,112 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package fs package filesys_test
import ( import (
"bytes" "bytes"
"reflect" "reflect"
"testing" "testing"
. "sigs.k8s.io/kustomize/api/filesys"
) )
func TestExists(t *testing.T) { func TestExists(t *testing.T) {
x := MakeFsInMemory() fSys := MakeFsInMemory()
if x.Exists("foo") { if fSys.Exists("foo") {
t.Fatalf("expected no foo") t.Fatalf("expected no foo")
} }
x.Mkdir("/") fSys.Mkdir("/")
if !x.IsDir("/") { if !fSys.IsDir("/") {
t.Fatalf("expected dir at /") t.Fatalf("expected dir at /")
} }
} }
func TestIsDir(t *testing.T) { func TestIsDir(t *testing.T) {
x := MakeFsInMemory() fSys := MakeFsInMemory()
expectedName := "my-dir" expectedName := "my-dir"
err := x.Mkdir(expectedName) err := fSys.Mkdir(expectedName)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
shouldExist(t, x, expectedName) shouldExist(t, fSys, expectedName)
if !x.IsDir(expectedName) { if !fSys.IsDir(expectedName) {
t.Fatalf(expectedName + " should be a dir") t.Fatalf(expectedName + " should be a dir")
} }
} }
func shouldExist(t *testing.T, fs FileSystem, name string) { func shouldExist(t *testing.T, fSys FileSystem, name string) {
if !fs.Exists(name) { if !fSys.Exists(name) {
t.Fatalf(name + " should exist") t.Fatalf(name + " should exist")
} }
} }
func shouldNotExist(t *testing.T, fs FileSystem, name string) { func shouldNotExist(t *testing.T, fSys FileSystem, name string) {
if fs.Exists(name) { if fSys.Exists(name) {
t.Fatalf(name + " should not exist") t.Fatalf(name + " should not exist")
} }
} }
func TestRemoveAll(t *testing.T) { func TestRemoveAll(t *testing.T) {
x := MakeFsInMemory() fSys := MakeFsInMemory()
x.WriteFile("/foo/project/file.yaml", []byte("Unused")) fSys.WriteFile("/foo/project/file.yaml", []byte("Unused"))
x.WriteFile("/foo/project/subdir/file.yaml", []byte("Unused")) fSys.WriteFile("/foo/project/subdir/file.yaml", []byte("Unused"))
x.WriteFile("/foo/apple/subdir/file.yaml", []byte("Unused")) fSys.WriteFile("/foo/apple/subdir/file.yaml", []byte("Unused"))
shouldExist(t, x, "/foo/project/file.yaml") shouldExist(t, fSys, "/foo/project/file.yaml")
shouldExist(t, x, "/foo/project/subdir/file.yaml") shouldExist(t, fSys, "/foo/project/subdir/file.yaml")
shouldExist(t, x, "/foo/apple/subdir/file.yaml") shouldExist(t, fSys, "/foo/apple/subdir/file.yaml")
err := x.RemoveAll("/foo/project") err := fSys.RemoveAll("/foo/project")
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
shouldNotExist(t, x, "/foo/project/file.yaml") shouldNotExist(t, fSys, "/foo/project/file.yaml")
shouldNotExist(t, x, "/foo/project/subdir/file.yaml") shouldNotExist(t, fSys, "/foo/project/subdir/file.yaml")
shouldExist(t, x, "/foo/apple/subdir/file.yaml") shouldExist(t, fSys, "/foo/apple/subdir/file.yaml")
} }
func TestIsDirDeeper(t *testing.T) { func TestIsDirDeeper(t *testing.T) {
x := MakeFsInMemory() fSys := MakeFsInMemory()
x.WriteFile("/foo/project/file.yaml", []byte("Unused")) fSys.WriteFile("/foo/project/file.yaml", []byte("Unused"))
x.WriteFile("/foo/project/subdir/file.yaml", []byte("Unused")) fSys.WriteFile("/foo/project/subdir/file.yaml", []byte("Unused"))
if !x.IsDir("/") { if !fSys.IsDir("/") {
t.Fatalf("/ should be a dir") t.Fatalf("/ should be a dir")
} }
if !x.IsDir("/foo") { if !fSys.IsDir("/foo") {
t.Fatalf("/foo should be a dir") t.Fatalf("/foo should be a dir")
} }
if !x.IsDir("/foo/project") { if !fSys.IsDir("/foo/project") {
t.Fatalf("/foo/project should be a dir") t.Fatalf("/foo/project should be a dir")
} }
if x.IsDir("/fo") { if fSys.IsDir("/fo") {
t.Fatalf("/fo should not be a dir") t.Fatalf("/fo should not be a dir")
} }
if x.IsDir("/x") { if fSys.IsDir("/x") {
t.Fatalf("/x should not be a dir") t.Fatalf("/x should not be a dir")
} }
} }
func TestCreate(t *testing.T) { func TestCreate(t *testing.T) {
x := MakeFsInMemory() fSys := MakeFsInMemory()
f, err := x.Create("foo") f, err := fSys.Create("foo")
if f == nil { if f == nil {
t.Fatalf("expected file") t.Fatalf("expected file")
} }
if err != nil { if err != nil {
t.Fatalf("unexpected error") t.Fatalf("unexpected error")
} }
shouldExist(t, x, "foo") shouldExist(t, fSys, "foo")
} }
func TestReadFile(t *testing.T) { func TestReadFile(t *testing.T) {
x := MakeFsInMemory() fSys := MakeFsInMemory()
f, err := x.Create("foo") f, err := fSys.Create("foo")
if f == nil { if f == nil {
t.Fatalf("expected file") t.Fatalf("expected file")
} }
if err != nil { if err != nil {
t.Fatalf("unexpected error") t.Fatalf("unexpected error")
} }
content, err := x.ReadFile("foo") content, err := fSys.ReadFile("foo")
if len(content) != 0 { if len(content) != 0 {
t.Fatalf("expected no content") t.Fatalf("expected no content")
} }
@@ -114,13 +116,13 @@ func TestReadFile(t *testing.T) {
} }
func TestWriteFile(t *testing.T) { func TestWriteFile(t *testing.T) {
x := MakeFsInMemory() fSys := MakeFsInMemory()
c := []byte("heybuddy") c := []byte("heybuddy")
err := x.WriteFile("foo", c) err := fSys.WriteFile("foo", c)
if err != nil { if err != nil {
t.Fatalf("expected no error") t.Fatalf("expected no error")
} }
content, err := x.ReadFile("foo") content, err := fSys.ReadFile("foo")
if err != nil { if err != nil {
t.Fatalf("expected read to work: %v", err) t.Fatalf("expected read to work: %v", err)
} }
@@ -130,10 +132,10 @@ func TestWriteFile(t *testing.T) {
} }
func TestGlob(t *testing.T) { func TestGlob(t *testing.T) {
x := MakeFsInMemory() fSys := MakeFsInMemory()
x.Create("dir/foo") fSys.Create("dir/foo")
x.Create("dir/bar") fSys.Create("dir/bar")
files, err := x.Glob("dir/*") files, err := fSys.Glob("dir/*")
if err != nil { if err != nil {
t.Fatalf("expected no error") t.Fatalf("expected no error")
} }

View File

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

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package fs package filesys_test
import ( import (
"io/ioutil" "io/ioutil"
@@ -10,10 +10,12 @@ import (
"path/filepath" "path/filepath"
"reflect" "reflect"
"testing" "testing"
. "sigs.k8s.io/kustomize/api/filesys"
) )
func makeTestDir(t *testing.T) (FileSystem, string) { func makeTestDir(t *testing.T) (FileSystem, string) {
x := MakeFsOnDisk() fSys := MakeFsOnDisk()
td, err := ioutil.TempDir("", "kustomize_testing_dir") td, err := ioutil.TempDir("", "kustomize_testing_dir")
if err != nil { if err != nil {
t.Fatalf("unexpected error %s", err) t.Fatalf("unexpected error %s", err)
@@ -22,20 +24,20 @@ func makeTestDir(t *testing.T) (FileSystem, string) {
if err != nil { if err != nil {
t.Fatalf("unexpected error %s", err) t.Fatalf("unexpected error %s", err)
} }
if !x.Exists(testDir) { if !fSys.Exists(testDir) {
t.Fatalf("expected existence") t.Fatalf("expected existence")
} }
if !x.IsDir(testDir) { if !fSys.IsDir(testDir) {
t.Fatalf("expected directory") t.Fatalf("expected directory")
} }
return x, testDir return fSys, testDir
} }
func TestCleanedAbs_1(t *testing.T) { func TestCleanedAbs_1(t *testing.T) {
x, testDir := makeTestDir(t) fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir) defer os.RemoveAll(testDir)
d, f, err := x.CleanedAbs("") d, f, err := fSys.CleanedAbs("")
if err != nil { if err != nil {
t.Fatalf("unexpected err=%v", err) t.Fatalf("unexpected err=%v", err)
} }
@@ -52,10 +54,10 @@ func TestCleanedAbs_1(t *testing.T) {
} }
func TestCleanedAbs_2(t *testing.T) { func TestCleanedAbs_2(t *testing.T) {
x, testDir := makeTestDir(t) fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir) defer os.RemoveAll(testDir)
d, f, err := x.CleanedAbs("/") d, f, err := fSys.CleanedAbs("/")
if err != nil { if err != nil {
t.Fatalf("unexpected err=%v", err) t.Fatalf("unexpected err=%v", err)
} }
@@ -68,16 +70,16 @@ func TestCleanedAbs_2(t *testing.T) {
} }
func TestCleanedAbs_3(t *testing.T) { func TestCleanedAbs_3(t *testing.T) {
x, testDir := makeTestDir(t) fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir) defer os.RemoveAll(testDir)
err := x.WriteFile( err := fSys.WriteFile(
filepath.Join(testDir, "foo"), []byte(`foo`)) filepath.Join(testDir, "foo"), []byte(`foo`))
if err != nil { if err != nil {
t.Fatalf("unexpected err=%v", err) t.Fatalf("unexpected err=%v", err)
} }
d, f, err := x.CleanedAbs(filepath.Join(testDir, "foo")) d, f, err := fSys.CleanedAbs(filepath.Join(testDir, "foo"))
if err != nil { if err != nil {
t.Fatalf("unexpected err=%v", err) t.Fatalf("unexpected err=%v", err)
} }
@@ -90,21 +92,21 @@ func TestCleanedAbs_3(t *testing.T) {
} }
func TestCleanedAbs_4(t *testing.T) { func TestCleanedAbs_4(t *testing.T) {
x, testDir := makeTestDir(t) fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir) defer os.RemoveAll(testDir)
err := x.MkdirAll(filepath.Join(testDir, "d1", "d2")) err := fSys.MkdirAll(filepath.Join(testDir, "d1", "d2"))
if err != nil { if err != nil {
t.Fatalf("unexpected err=%v", err) t.Fatalf("unexpected err=%v", err)
} }
err = x.WriteFile( err = fSys.WriteFile(
filepath.Join(testDir, "d1", "d2", "bar"), filepath.Join(testDir, "d1", "d2", "bar"),
[]byte(`bar`)) []byte(`bar`))
if err != nil { if err != nil {
t.Fatalf("unexpected err=%v", err) t.Fatalf("unexpected err=%v", err)
} }
d, f, err := x.CleanedAbs( d, f, err := fSys.CleanedAbs(
filepath.Join(testDir, "d1", "d2")) filepath.Join(testDir, "d1", "d2"))
if err != nil { if err != nil {
t.Fatalf("unexpected err=%v", err) t.Fatalf("unexpected err=%v", err)
@@ -116,7 +118,7 @@ func TestCleanedAbs_4(t *testing.T) {
t.Fatalf("unexpected f=%s", f) t.Fatalf("unexpected f=%s", f)
} }
d, f, err = x.CleanedAbs( d, f, err = fSys.CleanedAbs(
filepath.Join(testDir, "d1", "d2", "bar")) filepath.Join(testDir, "d1", "d2", "bar"))
if err != nil { if err != nil {
t.Fatalf("unexpected err=%v", err) t.Fatalf("unexpected err=%v", err)
@@ -130,26 +132,26 @@ func TestCleanedAbs_4(t *testing.T) {
} }
func TestReadFilesRealFS(t *testing.T) { func TestReadFilesRealFS(t *testing.T) {
x, testDir := makeTestDir(t) fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir) defer os.RemoveAll(testDir)
err := x.WriteFile(path.Join(testDir, "foo"), []byte(`foo`)) err := fSys.WriteFile(path.Join(testDir, "foo"), []byte(`foo`))
if err != nil { if err != nil {
t.Fatalf("unexpected error %s", err) t.Fatalf("unexpected error %s", err)
} }
if !x.Exists(path.Join(testDir, "foo")) { if !fSys.Exists(path.Join(testDir, "foo")) {
t.Fatalf("expected foo") t.Fatalf("expected foo")
} }
if x.IsDir(path.Join(testDir, "foo")) { if fSys.IsDir(path.Join(testDir, "foo")) {
t.Fatalf("expected foo not to be a directory") t.Fatalf("expected foo not to be a directory")
} }
err = x.WriteFile(path.Join(testDir, "bar"), []byte(`bar`)) err = fSys.WriteFile(path.Join(testDir, "bar"), []byte(`bar`))
if err != nil { if err != nil {
t.Fatalf("unexpected error %s", err) t.Fatalf("unexpected error %s", err)
} }
files, err := x.Glob(path.Join("testDir", "*")) files, err := fSys.Glob(path.Join("testDir", "*"))
expected := []string{ expected := []string{
path.Join(testDir, "bar"), path.Join(testDir, "bar"),
path.Join(testDir, "foo"), path.Join(testDir, "foo"),

View File

@@ -1,12 +1,12 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package fs package filesys
import "path/filepath" import "path/filepath"
// RPath returns a rooted path, e.g. "/hey/foo" as // RootedPath returns a rooted path, e.g. "/foo/bar" as
// opposed to "hey/foo". // opposed to "foo/bar".
func RPath(elem ...string) string { func RootedPath(elem ...string) string {
return separator + filepath.Join(elem...) return separator + filepath.Join(elem...)
} }

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
package git package git
@@ -22,7 +9,7 @@ import (
"os/exec" "os/exec"
"github.com/pkg/errors" "github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/fs" "sigs.k8s.io/kustomize/api/filesys"
) )
// Cloner is a function that can clone a git repo. // Cloner is a function that can clone a git repo.
@@ -36,7 +23,7 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
if err != nil { if err != nil {
return errors.Wrap(err, "no 'git' program on path") return errors.Wrap(err, "no 'git' program on path")
} }
repoSpec.Dir, err = fs.NewTmpConfirmedDir() repoSpec.Dir, err = filesys.NewTmpConfirmedDir()
if err != nil { if err != nil {
return err return err
} }
@@ -126,7 +113,7 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
// cloneDir field in the repoSpec. It's assumed that // cloneDir field in the repoSpec. It's assumed that
// the cloneDir is associated with some fake filesystem // the cloneDir is associated with some fake filesystem
// used in a test. // used in a test.
func DoNothingCloner(dir fs.ConfirmedDir) Cloner { func DoNothingCloner(dir filesys.ConfirmedDir) Cloner {
return func(rs *RepoSpec) error { return func(rs *RepoSpec) error {
rs.Dir = dir rs.Dir = dir
return nil return nil

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
package git package git
@@ -22,7 +9,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"sigs.k8s.io/kustomize/v3/pkg/fs" "sigs.k8s.io/kustomize/api/filesys"
) )
// Used as a temporary non-empty occupant of the cloneDir // Used as a temporary non-empty occupant of the cloneDir
@@ -30,7 +17,7 @@ import (
// in various outputs (especially tests). Not using an // in various outputs (especially tests). Not using an
// actual directory name here, as that's a temporary directory // actual directory name here, as that's a temporary directory
// with a unique name that isn't created until clone time. // 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. // RepoSpec specifies a git repository and a branch and path therein.
type RepoSpec struct { type RepoSpec struct {
@@ -46,7 +33,7 @@ type RepoSpec struct {
OrgRepo string OrgRepo string
// Dir where the orgRepo is cloned to. // Dir where the orgRepo is cloned to.
Dir fs.ConfirmedDir Dir filesys.ConfirmedDir
// Relative path in the repository, and in the cloneDir, // Relative path in the repository, and in the cloneDir,
// to a Kustomization. // to a Kustomization.
@@ -67,7 +54,7 @@ func (x *RepoSpec) CloneSpec() string {
return x.Host + x.OrgRepo + x.GitSuffix return x.Host + x.OrgRepo + x.GitSuffix
} }
func (x *RepoSpec) CloneDir() fs.ConfirmedDir { func (x *RepoSpec) CloneDir() filesys.ConfirmedDir {
return x.Dir return x.Dir
} }
@@ -79,7 +66,7 @@ func (x *RepoSpec) AbsPath() string {
return x.Dir.Join(x.Path) 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()) } return func() error { return fSys.RemoveAll(x.Dir.String()) }
} }
@@ -213,7 +200,7 @@ func normalizeGitHostSpec(host string) string {
} }
} }
if strings.HasPrefix(s, "git::") { if strings.HasPrefix(s, "git::") {
host = strings.TrimLeft(s, "git::") host = strings.TrimPrefix(s, "git::")
} }
return host return host
} }

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
package git package git

21
api/go.mod Normal file
View File

@@ -0,0 +1,21 @@
module sigs.k8s.io/kustomize/api
go 1.13
require (
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/go-openapi/spec v0.19.4
github.com/golang/protobuf v1.3.2 // indirect
github.com/pkg/errors v0.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.4
k8s.io/api v0.0.0-20191016225839-816a9b7df678
k8s.io/apimachinery v0.0.0-20191020214737-6c8691705fc5
k8s.io/client-go v11.0.0+incompatible
k8s.io/kube-openapi v0.0.0-20190918143330-0270cf2f1c1d
sigs.k8s.io/yaml v1.1.0
)

162
api/go.sum Normal file
View File

@@ -0,0 +1,162 @@
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633 h1:H2pdYOb3KQ1/YsqVWoWNLQO+fusocsw354rqGTZtAgw=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
github.com/go-openapi/jsonreference v0.19.2 h1:o20suLFB4Ri0tuzpWtyHlh7E7HnkqTNLq6aR6WVNS1w=
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc=
github.com/go-openapi/spec v0.19.4 h1:ixzUSnHTd6hCemgtAJgluaTSGYpLNpJY4mA2DIkdOAo=
github.com/go-openapi/spec v0.19.4/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I=
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I=
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d h1:7XGaL1e6bYS1yIonGp9761ExpPPV1ui0SAC59Yube9k=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190812203447-cdfb69ac37fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 h1:rOhMmluY6kLMhdnrivzec6lLgaVbMHMn2ISQXJeJ5EM=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inf.v0 v0.9.0 h1:3zYtXIO92bvsdS3ggAdA8Gb4Azj0YU+TVY1uGYNFA8o=
gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
k8s.io/api v0.0.0-20191016225839-816a9b7df678 h1:z/0BV/tMBIvdwZvqBH/f7TWjQX9y3dj1nMNhrSK0h/8=
k8s.io/api v0.0.0-20191016225839-816a9b7df678/go.mod h1:LZQaT8MvVpl7Bg2lYFcQm7+Mpdxq8p1NFl3yh+5DCwY=
k8s.io/apimachinery v0.0.0-20191016225534-b1267f8c42b4/go.mod h1:92mWDd8Ji2sw2157KIgino5wCxffA8KSvhW2oY4ypdw=
k8s.io/apimachinery v0.0.0-20191020214737-6c8691705fc5 h1:r3/YL3+t1U46lJF5zUSArskUpnLyWuM28rQDpM1qQPI=
k8s.io/apimachinery v0.0.0-20191020214737-6c8691705fc5/go.mod h1:92mWDd8Ji2sw2157KIgino5wCxffA8KSvhW2oY4ypdw=
k8s.io/client-go v11.0.0+incompatible h1:LBbX2+lOwY9flffWlJM7f1Ct8V2SRNiMRDFeiwnJo9o=
k8s.io/client-go v11.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
k8s.io/kube-openapi v0.0.0-20190918143330-0270cf2f1c1d h1:Xpe6sK+RY4ZgCTyZ3y273UmFmURhjtoJiwOMbQsXitY=
k8s.io/kube-openapi v0.0.0-20190918143330-0270cf2f1c1d/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=

View File

@@ -6,7 +6,7 @@ package hasher_test
import ( import (
"testing" "testing"
. "sigs.k8s.io/kustomize/v3/pkg/hasher" . "sigs.k8s.io/kustomize/api/hasher"
) )
func TestSortArrayAndComputeHash(t *testing.T) { func TestSortArrayAndComputeHash(t *testing.T) {

View File

@@ -5,8 +5,8 @@
package ifc package ifc
import ( import (
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/types"
) )
// Validator provides functions to validate annotations and labels // Validator provides functions to validate annotations and labels
@@ -20,6 +20,12 @@ type Validator interface {
IsEnvVarName(k string) error IsEnvVarName(k string) error
} }
// KvLoader reads and validates KV pairs.
type KvLoader interface {
Validator() Validator
Load(args types.KvPairSources) (all []types.Pair, err error)
}
// Loader interface exposes methods to read bytes. // Loader interface exposes methods to read bytes.
type Loader interface { type Loader interface {
// Root returns the root location for this Loader. // Root returns the root location for this Loader.
@@ -30,10 +36,6 @@ type Loader interface {
Load(location string) ([]byte, error) Load(location string) ([]byte, error)
// Cleanup cleans the loader // Cleanup cleans the loader
Cleanup() error Cleanup() error
// Validator validates data for use in various k8s fields.
Validator() Validator
// Loads pairs.
LoadKvPairs(args types.GeneratorArgs) ([]types.Pair, error)
} }
// Kunstructured allows manipulation of k8s objects // Kunstructured allows manipulation of k8s objects
@@ -53,8 +55,8 @@ type Kunstructured interface {
GetMap(path string) (map[string]interface{}, error) GetMap(path string) (map[string]interface{}, error)
MarshalJSON() ([]byte, error) MarshalJSON() ([]byte, error)
UnmarshalJSON([]byte) error UnmarshalJSON([]byte) error
GetGvk() gvk.Gvk GetGvk() resid.Gvk
SetGvk(gvk.Gvk) SetGvk(resid.Gvk)
GetKind() string GetKind() string
GetName() string GetName() string
SetName(string) SetName(string)
@@ -74,11 +76,11 @@ type KunstructuredFactory interface {
FromMap(m map[string]interface{}) Kunstructured FromMap(m map[string]interface{}) Kunstructured
Hasher() KunstructuredHasher Hasher() KunstructuredHasher
MakeConfigMap( MakeConfigMap(
ldr Loader, kvLdr KvLoader,
options *types.GeneratorOptions, options *types.GeneratorOptions,
args *types.ConfigMapArgs) (Kunstructured, error) args *types.ConfigMapArgs) (Kunstructured, error)
MakeSecret( MakeSecret(
ldr Loader, kvLdr KvLoader,
options *types.GeneratorOptions, options *types.GeneratorOptions,
args *types.SecretArgs) (Kunstructured, error) args *types.SecretArgs) (Kunstructured, error)
} }

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
// Package expansion provides functions find and replace $(FOO) style variables in strings. // Package expansion provides functions find and replace $(FOO) style variables in strings.
package expansion package expansion

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
package expansion_test package expansion_test
@@ -20,7 +7,7 @@ import (
"fmt" "fmt"
"testing" "testing"
. "sigs.k8s.io/kustomize/v3/pkg/expansion" . "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
) )
type expected struct { type expected struct {

View File

@@ -1,20 +1,7 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package accumulator
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.
*/
package config
import ( import (
"encoding/json" "encoding/json"
@@ -23,8 +10,10 @@ import (
"github.com/go-openapi/spec" "github.com/go-openapi/spec"
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/kube-openapi/pkg/common" "k8s.io/kube-openapi/pkg/common"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
@@ -33,8 +22,8 @@ type nameToApiMap map[string]common.OpenAPIDefinition
// LoadConfigFromCRDs parse CRD schemas from paths into a TransformerConfig // LoadConfigFromCRDs parse CRD schemas from paths into a TransformerConfig
func LoadConfigFromCRDs( func LoadConfigFromCRDs(
ldr ifc.Loader, paths []string) (*TransformerConfig, error) { ldr ifc.Loader, paths []string) (*builtinconfig.TransformerConfig, error) {
tc := MakeEmptyConfig() tc := builtinconfig.MakeEmptyConfig()
for _, path := range paths { for _, path := range paths {
content, err := ldr.Load(path) content, err := ldr.Load(path)
if err != nil { if err != nil {
@@ -65,13 +54,13 @@ func makeNameToApiMap(content []byte) (result nameToApiMap, err error) {
return return
} }
func makeConfigFromApiMap(m nameToApiMap) (*TransformerConfig, error) { func makeConfigFromApiMap(m nameToApiMap) (*builtinconfig.TransformerConfig, error) {
result := MakeEmptyConfig() result := builtinconfig.MakeEmptyConfig()
for name, api := range m { for name, api := range m {
if !looksLikeAk8sType(api.Schema.SchemaProps.Properties) { if !looksLikeAk8sType(api.Schema.SchemaProps.Properties) {
continue continue
} }
tc := MakeEmptyConfig() tc := builtinconfig.MakeEmptyConfig()
err := loadCrdIntoConfig( err := loadCrdIntoConfig(
tc, makeGvkFromTypeName(name), m, name, []string{}) tc, makeGvkFromTypeName(name), m, name, []string{})
if err != nil { if err != nil {
@@ -88,10 +77,10 @@ func makeConfigFromApiMap(m nameToApiMap) (*TransformerConfig, error) {
// TODO: Get Group and Version for CRD from the // TODO: Get Group and Version for CRD from the
// openAPI definition once // openAPI definition once
// "x-kubernetes-group-version-kind" is available in CRD // "x-kubernetes-group-version-kind" is available in CRD
func makeGvkFromTypeName(n string) gvk.Gvk { func makeGvkFromTypeName(n string) resid.Gvk {
names := strings.Split(n, ".") names := strings.Split(n, ".")
kind := names[len(names)-1] kind := names[len(names)-1]
return gvk.Gvk{Kind: kind} return resid.Gvk{Kind: kind}
} }
func looksLikeAk8sType(properties myProperties) bool { func looksLikeAk8sType(properties myProperties) bool {
@@ -133,7 +122,7 @@ const (
// loadCrdIntoConfig loads a CRD spec into a TransformerConfig // loadCrdIntoConfig loads a CRD spec into a TransformerConfig
func loadCrdIntoConfig( func loadCrdIntoConfig(
theConfig *TransformerConfig, theGvk gvk.Gvk, theMap nameToApiMap, theConfig *builtinconfig.TransformerConfig, theGvk resid.Gvk, theMap nameToApiMap,
typeName string, path []string) (err error) { typeName string, path []string) (err error) {
api, ok := theMap[typeName] api, ok := theMap[typeName]
if !ok { if !ok {
@@ -173,9 +162,9 @@ func loadCrdIntoConfig(
nameKey = "name" nameKey = "name"
} }
err = theConfig.AddNamereferenceFieldSpec( err = theConfig.AddNamereferenceFieldSpec(
NameBackReferences{ builtinconfig.NameBackReferences{
Gvk: gvk.Gvk{Kind: kind, Version: version}, Gvk: resid.Gvk{Kind: kind, Version: version},
FieldSpecs: []FieldSpec{ FieldSpecs: []types.FieldSpec{
makeFs(theGvk, append(path, propName, nameKey))}, makeFs(theGvk, append(path, propName, nameKey))},
}) })
if err != nil { if err != nil {
@@ -192,8 +181,8 @@ func loadCrdIntoConfig(
return nil return nil
} }
func makeFs(in gvk.Gvk, path []string) FieldSpec { func makeFs(in resid.Gvk, path []string) types.FieldSpec {
return FieldSpec{ return types.FieldSpec{
CreateIfNotPresent: false, CreateIfNotPresent: false,
Gvk: in, Gvk: in,
Path: strings.Join(path, "/"), Path: strings.Join(path, "/"),

View File

@@ -1,28 +1,18 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package accumulator_test
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.
*/
package config
import ( import (
"reflect" "reflect"
"testing" "testing"
"sigs.k8s.io/kustomize/v3/internal/loadertest" "sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/v3/pkg/gvk" . "sigs.k8s.io/kustomize/api/internal/accumulator"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/internal/loadertest"
"sigs.k8s.io/kustomize/api/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/types"
) )
// This defines two CRD's: Bee and MyKind. // This defines two CRD's: Bee and MyKind.
@@ -155,30 +145,30 @@ func makeLoader(t *testing.T) ifc.Loader {
} }
func TestLoadCRDs(t *testing.T) { func TestLoadCRDs(t *testing.T) {
nbrs := []NameBackReferences{ nbrs := []builtinconfig.NameBackReferences{
{ {
Gvk: gvk.Gvk{Kind: "Secret", Version: "v1"}, Gvk: resid.Gvk{Kind: "Secret", Version: "v1"},
FieldSpecs: []FieldSpec{ FieldSpecs: []types.FieldSpec{
{ {
CreateIfNotPresent: false, CreateIfNotPresent: false,
Gvk: gvk.Gvk{Kind: "MyKind"}, Gvk: resid.Gvk{Kind: "MyKind"},
Path: "spec/secretRef/name", Path: "spec/secretRef/name",
}, },
}, },
}, },
{ {
Gvk: gvk.Gvk{Kind: "Bee", Version: "v1beta1"}, Gvk: resid.Gvk{Kind: "Bee", Version: "v1beta1"},
FieldSpecs: []FieldSpec{ FieldSpecs: []types.FieldSpec{
{ {
CreateIfNotPresent: false, CreateIfNotPresent: false,
Gvk: gvk.Gvk{Kind: "MyKind"}, Gvk: resid.Gvk{Kind: "MyKind"},
Path: "spec/beeRef/name", Path: "spec/beeRef/name",
}, },
}, },
}, },
} }
expectedTc := &TransformerConfig{ expectedTc := &builtinconfig.TransformerConfig{
NameReference: nbrs, NameReference: nbrs,
} }

View File

@@ -1,28 +1,28 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package transformers package accumulator
import ( import (
"fmt" "fmt"
"log" "log"
"sigs.k8s.io/kustomize/v3/pkg/resource" "sigs.k8s.io/kustomize/api/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config" "sigs.k8s.io/kustomize/api/transform"
) )
type nameReferenceTransformer struct { type nameReferenceTransformer struct {
backRefs []config.NameBackReferences backRefs []builtinconfig.NameBackReferences
} }
var _ resmap.Transformer = &nameReferenceTransformer{} var _ resmap.Transformer = &nameReferenceTransformer{}
// NewNameReferenceTransformer constructs a nameReferenceTransformer // newNameReferenceTransformer constructs a nameReferenceTransformer
// with a given slice of NameBackReferences. // with a given slice of NameBackReferences.
func NewNameReferenceTransformer(br []config.NameBackReferences) resmap.Transformer { func newNameReferenceTransformer(br []builtinconfig.NameBackReferences) resmap.Transformer {
if br == nil { if br == nil {
log.Fatal("backrefs not expected to be nil") log.Fatal("backrefs not expected to be nil")
} }
@@ -86,7 +86,7 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
if candidates == nil { if candidates == nil {
candidates = m.SubsetThatCouldBeReferencedByResource(referrer) candidates = m.SubsetThatCouldBeReferencedByResource(referrer)
} }
err := MutateField( err := transform.MutateField(
referrer.Map(), referrer.Map(),
fSpec.PathSlice(), fSpec.PathSlice(),
fSpec.CreateIfNotPresent, fSpec.CreateIfNotPresent,
@@ -115,7 +115,7 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
func (o *nameReferenceTransformer) selectReferral( func (o *nameReferenceTransformer) selectReferral(
oldName string, oldName string,
referrer *resource.Resource, referrer *resource.Resource,
target gvk.Gvk, target resid.Gvk,
referralCandidates resmap.ResMap, referralCandidates resmap.ResMap,
referralCandidateSubset []*resource.Resource) (interface{}, interface{}, error) { referralCandidateSubset []*resource.Resource) (interface{}, interface{}, error) {
@@ -146,7 +146,7 @@ func (o *nameReferenceTransformer) selectReferral(
func (o *nameReferenceTransformer) getSimpleNameField( func (o *nameReferenceTransformer) getSimpleNameField(
oldName string, oldName string,
referrer *resource.Resource, referrer *resource.Resource,
target gvk.Gvk, target resid.Gvk,
referralCandidates resmap.ResMap, referralCandidates resmap.ResMap,
referralCandidateSubset []*resource.Resource) (interface{}, error) { referralCandidateSubset []*resource.Resource) (interface{}, error) {
@@ -161,7 +161,7 @@ func (o *nameReferenceTransformer) getSimpleNameField(
func (o *nameReferenceTransformer) getNameAndNsStruct( func (o *nameReferenceTransformer) getNameAndNsStruct(
inMap map[string]interface{}, inMap map[string]interface{},
referrer *resource.Resource, referrer *resource.Resource,
target gvk.Gvk, target resid.Gvk,
referralCandidates resmap.ResMap) (interface{}, error) { referralCandidates resmap.ResMap) (interface{}, error) {
// Example: // Example:
@@ -209,7 +209,7 @@ func (o *nameReferenceTransformer) getNameAndNsStruct(
func (o *nameReferenceTransformer) getNewNameFunc( func (o *nameReferenceTransformer) getNewNameFunc(
referrer *resource.Resource, referrer *resource.Resource,
target gvk.Gvk, target resid.Gvk,
referralCandidates resmap.ResMap) func(in interface{}) (interface{}, error) { referralCandidates resmap.ResMap) func(in interface{}) (interface{}, error) {
return func(in interface{}) (interface{}, error) { return func(in interface{}) (interface{}, error) {
switch in.(type) { switch in.(type) {

View File

@@ -1,18 +1,18 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package transformers package accumulator
import ( import (
"strings" "strings"
"testing" "testing"
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/plugins/builtinconfig"
"sigs.k8s.io/kustomize/v3/pkg/resid" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmaptest" "sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/v3/pkg/resource" "sigs.k8s.io/kustomize/api/testutils/resmaptest"
) )
func TestNameReferenceHappyRun(t *testing.T) { func TestNameReferenceHappyRun(t *testing.T) {
@@ -463,7 +463,7 @@ func TestNameReferenceHappyRun(t *testing.T) {
}, },
}).ResMap() }).ResMap()
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference) nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
err := nrt.Transform(m) err := nrt.Transform(m)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@@ -523,7 +523,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
expectedErr: "is expected to contain a name field"}, expectedErr: "is expected to contain a name field"},
} }
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference) nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
for _, test := range tests { for _, test := range tests {
err := nrt.Transform(test.resMap) err := nrt.Transform(test.resMap)
if err == nil { if err == nil {
@@ -581,7 +581,7 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
m1 := resmaptest_test.NewRmBuilder(t, rf).AddR(v1).AddR(c1).ResMap() m1 := resmaptest_test.NewRmBuilder(t, rf).AddR(v1).AddR(c1).ResMap()
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference) nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
if err := nrt.Transform(m1); err != nil { if err := nrt.Transform(m1); err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
@@ -720,7 +720,7 @@ func TestNameReferenceNamespace(t *testing.T) {
ReplaceResource(deploymentMap(ns1, prefixedname, prefixedname, prefixedname)). ReplaceResource(deploymentMap(ns1, prefixedname, prefixedname, prefixedname)).
ReplaceResource(deploymentMap(ns2, suffixedname, suffixedname, suffixedname)).ResMap() ReplaceResource(deploymentMap(ns2, suffixedname, suffixedname, suffixedname)).ResMap()
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference) nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
err := nrt.Transform(m) err := nrt.Transform(m)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@@ -877,13 +877,13 @@ func TestNameReferenceClusterWide(t *testing.T) {
}).ResMap() }).ResMap()
clusterRoleId := resid.NewResId( clusterRoleId := resid.NewResId(
gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname) resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname)
clusterRoleBindingId := resid.NewResId( clusterRoleBindingId := resid.NewResId(
gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname) resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname)
clusterRole, _ := expected.GetByCurrentId(clusterRoleId) clusterRole, _ := expected.GetByCurrentId(clusterRoleId)
clusterRole.AppendRefBy(clusterRoleBindingId) clusterRole.AppendRefBy(clusterRoleBindingId)
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference) nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
err := nrt.Transform(m) err := nrt.Transform(m)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@@ -1005,13 +1005,13 @@ func TestNameReferenceNamespaceTransformation(t *testing.T) {
}).ResMap() }).ResMap()
clusterRoleId := resid.NewResId( clusterRoleId := resid.NewResId(
gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname) resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname)
clusterRoleBindingId := resid.NewResId( clusterRoleBindingId := resid.NewResId(
gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname) resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname)
clusterRole, _ := expected.GetByCurrentId(clusterRoleId) clusterRole, _ := expected.GetByCurrentId(clusterRoleId)
clusterRole.AppendRefBy(clusterRoleBindingId) clusterRole.AppendRefBy(clusterRoleBindingId)
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference) nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
err := nrt.Transform(m) err := nrt.Transform(m)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@@ -1049,7 +1049,7 @@ func TestNameReferenceCandidateSelection(t *testing.T) {
ReplaceResource(deploymentMap("", "p1-deploy1", "p1-cm1-hash", "p1-secret1-hash")). ReplaceResource(deploymentMap("", "p1-deploy1", "p1-cm1-hash", "p1-secret1-hash")).
ResMap() ResMap()
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference) nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
err := nrt.Transform(m) err := nrt.Transform(m)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)

View File

@@ -1,41 +1,31 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package accumulator
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.
*/
package transformers
import ( import (
"fmt" "fmt"
"sigs.k8s.io/kustomize/v3/pkg/expansion"
"sigs.k8s.io/kustomize/v3/pkg/resmap" expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/transform"
"sigs.k8s.io/kustomize/api/types"
) )
type RefVarTransformer struct { type refVarTransformer struct {
varMap map[string]interface{} varMap map[string]interface{}
replacementCounts map[string]int replacementCounts map[string]int
fieldSpecs []config.FieldSpec fieldSpecs []types.FieldSpec
mappingFunc func(string) interface{} mappingFunc func(string) interface{}
} }
// NewRefVarTransformer returns a new RefVarTransformer // newRefVarTransformer returns a new refVarTransformer
// that replaces $(VAR) style variables with values. // that replaces $(VAR) style variables with values.
// The fieldSpecs are the places to look for occurrences of $(VAR). // The fieldSpecs are the places to look for occurrences of $(VAR).
func NewRefVarTransformer( func newRefVarTransformer(
varMap map[string]interface{}, fs []config.FieldSpec) *RefVarTransformer { varMap map[string]interface{}, fs []types.FieldSpec) *refVarTransformer {
return &RefVarTransformer{ return &refVarTransformer{
varMap: varMap, varMap: varMap,
fieldSpecs: fs, fieldSpecs: fs,
} }
@@ -45,12 +35,12 @@ func NewRefVarTransformer(
// embedded instances of $VAR style variables, e.g. a container command string. // embedded instances of $VAR style variables, e.g. a container command string.
// The function returns the string with the variables expanded to their final // The function returns the string with the variables expanded to their final
// values. // values.
func (rv *RefVarTransformer) replaceVars(in interface{}) (interface{}, error) { func (rv *refVarTransformer) replaceVars(in interface{}) (interface{}, error) {
switch vt := in.(type) { switch vt := in.(type) {
case []interface{}: case []interface{}:
var xs []interface{} var xs []interface{}
for _, a := range in.([]interface{}) { for _, a := range in.([]interface{}) {
xs = append(xs, expansion.Expand(a.(string), rv.mappingFunc)) xs = append(xs, expansion2.Expand(a.(string), rv.mappingFunc))
} }
return xs, nil return xs, nil
case map[string]interface{}: case map[string]interface{}:
@@ -67,7 +57,7 @@ func (rv *RefVarTransformer) replaceVars(in interface{}) (interface{}, error) {
// This field can potentially contains a $(VAR) since it is // This field can potentially contains a $(VAR) since it is
// of string type. For instance .spec.replicas: $(REPLICAS) // of string type. For instance .spec.replicas: $(REPLICAS)
// in a Deployment object // in a Deployment object
xs[k] = expansion.Expand(s, rv.mappingFunc) xs[k] = expansion2.Expand(s, rv.mappingFunc)
} }
} }
return xs, nil return xs, nil
@@ -79,7 +69,7 @@ func (rv *RefVarTransformer) replaceVars(in interface{}) (interface{}, error) {
} }
// This field can potentially contain a $(VAR) since it is // This field can potentially contain a $(VAR) since it is
// of string type. // of string type.
return expansion.Expand(s, rv.mappingFunc), nil return expansion2.Expand(s, rv.mappingFunc), nil
case nil: case nil:
return nil, nil return nil, nil
default: default:
@@ -89,7 +79,7 @@ func (rv *RefVarTransformer) replaceVars(in interface{}) (interface{}, error) {
// UnusedVars returns slice of Var names that were unused // UnusedVars returns slice of Var names that were unused
// after a Transform run. // after a Transform run.
func (rv *RefVarTransformer) UnusedVars() []string { func (rv *refVarTransformer) UnusedVars() []string {
var unused []string var unused []string
for k := range rv.varMap { for k := range rv.varMap {
_, ok := rv.replacementCounts[k] _, ok := rv.replacementCounts[k]
@@ -101,14 +91,14 @@ func (rv *RefVarTransformer) UnusedVars() []string {
} }
// Transform replaces $(VAR) style variables with values. // Transform replaces $(VAR) style variables with values.
func (rv *RefVarTransformer) Transform(m resmap.ResMap) error { func (rv *refVarTransformer) Transform(m resmap.ResMap) error {
rv.replacementCounts = make(map[string]int) rv.replacementCounts = make(map[string]int)
rv.mappingFunc = expansion.MappingFuncFor( rv.mappingFunc = expansion2.MappingFuncFor(
rv.replacementCounts, rv.varMap) rv.replacementCounts, rv.varMap)
for _, res := range m.Resources() { for _, res := range m.Resources() {
for _, fieldSpec := range rv.fieldSpecs { for _, fieldSpec := range rv.fieldSpecs {
if res.OrgId().IsSelected(&fieldSpec.Gvk) { if res.OrgId().IsSelected(&fieldSpec.Gvk) {
if err := MutateField( if err := transform.MutateField(
res.Map(), fieldSpec.PathSlice(), res.Map(), fieldSpec.PathSlice(),
false, rv.replaceVars); err != nil { false, rv.replaceVars); err != nil {
return err return err

View File

@@ -1,22 +1,24 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package transformers package accumulator
import ( import (
"reflect" "reflect"
"testing" "testing"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmaptest" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config" "sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/testutils/resmaptest"
"sigs.k8s.io/kustomize/api/types"
) )
func TestVarRef(t *testing.T) { func TestRefVarTransformer(t *testing.T) {
type given struct { type given struct {
varMap map[string]interface{} varMap map[string]interface{}
fs []config.FieldSpec fs []types.FieldSpec
res resmap.ResMap res resmap.ResMap
} }
type expected struct { type expected struct {
@@ -37,14 +39,15 @@ func TestVarRef(t *testing.T) {
"BAZ": int64(5), "BAZ": int64(5),
"BOO": true, "BOO": true,
}, },
fs: []config.FieldSpec{ fs: []types.FieldSpec{
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/map"}, {Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/map"},
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/slice"}, {Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/slice"},
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/interface"}, {Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/interface"},
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/nil"}, {Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/nil"},
{Gvk: gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/num"}, {Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/num"},
}, },
res: resmaptest_test.NewRmBuilder(t, rf). res: resmaptest_test.NewRmBuilder(
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
Add(map[string]interface{}{ Add(map[string]interface{}{
"apiVersion": "v1", "apiVersion": "v1",
"kind": "ConfigMap", "kind": "ConfigMap",
@@ -75,7 +78,8 @@ func TestVarRef(t *testing.T) {
}}).ResMap(), }}).ResMap(),
}, },
expected: expected{ expected: expected{
res: resmaptest_test.NewRmBuilder(t, rf). res: resmaptest_test.NewRmBuilder(
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
Add(map[string]interface{}{ Add(map[string]interface{}{
"apiVersion": "v1", "apiVersion": "v1",
"kind": "ConfigMap", "kind": "ConfigMap",
@@ -112,7 +116,7 @@ func TestVarRef(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) { t.Run(tc.description, func(t *testing.T) {
// arrange // arrange
tr := NewRefVarTransformer(tc.given.varMap, tc.given.fs) tr := newRefVarTransformer(tc.given.varMap, tc.given.fs)
// act // act
err := tr.Transform(tc.given.res) err := tr.Transform(tc.given.res)

View File

@@ -8,11 +8,10 @@ import (
"log" "log"
"strings" "strings"
"sigs.k8s.io/kustomize/v3/pkg/resid" "sigs.k8s.io/kustomize/api/plugins/builtinconfig"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/transformers" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/types"
) )
// ResAccumulator accumulates resources and the rules // ResAccumulator accumulates resources and the rules
@@ -20,14 +19,14 @@ import (
// plus stuff needed to modify the ResMap. // plus stuff needed to modify the ResMap.
type ResAccumulator struct { type ResAccumulator struct {
resMap resmap.ResMap resMap resmap.ResMap
tConfig *config.TransformerConfig tConfig *builtinconfig.TransformerConfig
varSet types.VarSet varSet types.VarSet
} }
func MakeEmptyAccumulator() *ResAccumulator { func MakeEmptyAccumulator() *ResAccumulator {
ra := &ResAccumulator{} ra := &ResAccumulator{}
ra.resMap = resmap.New() ra.resMap = resmap.New()
ra.tConfig = &config.TransformerConfig{} ra.tConfig = &builtinconfig.TransformerConfig{}
ra.varSet = types.NewVarSet() ra.varSet = types.NewVarSet()
return ra return ra
} }
@@ -53,12 +52,12 @@ func (ra *ResAccumulator) AbsorbAll(
} }
func (ra *ResAccumulator) MergeConfig( func (ra *ResAccumulator) MergeConfig(
tConfig *config.TransformerConfig) (err error) { tConfig *builtinconfig.TransformerConfig) (err error) {
ra.tConfig, err = ra.tConfig.Merge(tConfig) ra.tConfig, err = ra.tConfig.Merge(tConfig)
return err return err
} }
func (ra *ResAccumulator) GetTransformerConfig() *config.TransformerConfig { func (ra *ResAccumulator) GetTransformerConfig() *builtinconfig.TransformerConfig {
return ra.tConfig return ra.tConfig
} }
@@ -147,7 +146,7 @@ func (ra *ResAccumulator) ResolveVars() error {
if len(replacementMap) == 0 { if len(replacementMap) == 0 {
return nil return nil
} }
t := transformers.NewRefVarTransformer( t := newRefVarTransformer(
replacementMap, ra.tConfig.VarReference) replacementMap, ra.tConfig.VarReference)
err = ra.Transform(t) err = ra.Transform(t)
if len(t.UnusedVars()) > 0 { if len(t.UnusedVars()) > 0 {
@@ -162,6 +161,6 @@ func (ra *ResAccumulator) FixBackReferences() (err error) {
if ra.tConfig.NameReference == nil { if ra.tConfig.NameReference == nil {
return nil return nil
} }
return ra.Transform(transformers.NewNameReferenceTransformer( return ra.Transform(newNameReferenceTransformer(
ra.tConfig.NameReference)) ra.tConfig.NameReference))
} }

View File

@@ -10,19 +10,19 @@ import (
"strings" "strings"
"testing" "testing"
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct" . "sigs.k8s.io/kustomize/api/internal/accumulator"
. "sigs.k8s.io/kustomize/v3/pkg/accumulator" "sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/plugins/builtinconfig"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmaptest" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource" "sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config" "sigs.k8s.io/kustomize/api/testutils/resmaptest"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/types"
) )
func makeResAccumulator(t *testing.T) (*ResAccumulator, *resource.Factory) { func makeResAccumulator(t *testing.T) (*ResAccumulator, *resource.Factory) {
ra := MakeEmptyAccumulator() ra := MakeEmptyAccumulator()
err := ra.MergeConfig(config.MakeDefaultConfig()) err := ra.MergeConfig(builtinconfig.MakeDefaultConfig())
if err != nil { if err != nil {
t.Fatalf("unexpected err: %v", err) t.Fatalf("unexpected err: %v", err)
} }
@@ -75,13 +75,13 @@ func TestResolveVarsHappy(t *testing.T) {
{ {
Name: "SERVICE_ONE", Name: "SERVICE_ONE",
ObjRef: types.Target{ ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"}, Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne"}, Name: "backendOne"},
}, },
{ {
Name: "SERVICE_TWO", Name: "SERVICE_TWO",
ObjRef: types.Target{ ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"}, Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendTwo"}, Name: "backendTwo"},
}, },
}) })
@@ -104,13 +104,13 @@ func TestResolveVarsOneUnused(t *testing.T) {
{ {
Name: "SERVICE_ONE", Name: "SERVICE_ONE",
ObjRef: types.Target{ ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"}, Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne"}, Name: "backendOne"},
}, },
{ {
Name: "SERVICE_UNUSED", Name: "SERVICE_UNUSED",
ObjRef: types.Target{ ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"}, Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendTwo"}, Name: "backendTwo"},
}, },
}) })
@@ -165,7 +165,7 @@ func TestResolveVarsVarNeedsDisambiguation(t *testing.T) {
{ {
Name: "SERVICE_ONE", Name: "SERVICE_ONE",
ObjRef: types.Target{ ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"}, Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne", Name: "backendOne",
}, },
}, },
@@ -179,13 +179,94 @@ func TestResolveVarsVarNeedsDisambiguation(t *testing.T) {
} }
} }
func makeNamespacedConfigMapWithDataProviderValue(
namespace string,
value string,
) map[string]interface{} {
return map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "environment",
"namespace": namespace,
},
"data": map[string]interface{}{
"provider": value,
},
}
}
func makeVarToNamepaceAndPath(
name string,
namespace string,
path string,
) types.Var {
return types.Var{
Name: name,
ObjRef: types.Target{
Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"},
Name: "environment",
Namespace: namespace,
},
FieldRef: types.FieldSelector{FieldPath: path},
}
}
func TestResolveVarConflicts(t *testing.T) {
rf := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
// create configmaps in foo and bar namespaces with `data.provider` values.
fooAws := makeNamespacedConfigMapWithDataProviderValue("foo", "aws")
barAws := makeNamespacedConfigMapWithDataProviderValue("bar", "aws")
barGcp := makeNamespacedConfigMapWithDataProviderValue("bar", "gcp")
// create two variables with (apparently) conflicting names that point to
// fieldpaths that could be generalized.
varFoo := makeVarToNamepaceAndPath("PROVIDER", "foo", "data.provider")
varBar := makeVarToNamepaceAndPath("PROVIDER", "bar", "data.provider")
// create accumulators holding apparently conflicting vars that are not
// actually in conflict because they point to the same concrete value.
rm0 := resmap.New()
rm0.Append(rf.FromMap(fooAws))
ac0 := MakeEmptyAccumulator()
ac0.AppendAll(rm0)
ac0.MergeVars([]types.Var{varFoo})
rm1 := resmap.New()
rm1.Append(rf.FromMap(barAws))
ac1 := MakeEmptyAccumulator()
ac1.AppendAll(rm1)
ac1.MergeVars([]types.Var{varBar})
// validate that two vars of the same name which reference the same concrete
// value do not produce a conflict.
err := ac0.MergeAccumulator(ac1)
if err == nil {
t.Fatalf("see bug gh-1600")
}
// create an accumulator will have an actually conflicting value with the
// two above (because it contains a variable whose name is used in the other
// accumulators AND whose concrete values are different).
rm2 := resmap.New()
rm2.Append(rf.FromMap(barGcp))
ac2 := MakeEmptyAccumulator()
ac2.AppendAll(rm2)
ac2.MergeVars([]types.Var{varBar})
err = ac1.MergeAccumulator(ac2)
if err == nil {
t.Fatalf("dupe vars w/ different concrete values should conflict")
}
}
func TestResolveVarsGoodResIdBadField(t *testing.T) { func TestResolveVarsGoodResIdBadField(t *testing.T) {
ra, _ := makeResAccumulator(t) ra, _ := makeResAccumulator(t)
err := ra.MergeVars([]types.Var{ err := ra.MergeVars([]types.Var{
{ {
Name: "SERVICE_ONE", Name: "SERVICE_ONE",
ObjRef: types.Target{ ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"}, Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne"}, Name: "backendOne"},
FieldRef: types.FieldSelector{FieldPath: "nope_nope_nope"}, FieldRef: types.FieldSelector{FieldPath: "nope_nope_nope"},
}, },
@@ -210,7 +291,7 @@ func TestResolveVarsUnmappableVar(t *testing.T) {
{ {
Name: "SERVICE_THREE", Name: "SERVICE_THREE",
ObjRef: types.Target{ ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"}, Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "doesNotExist"}, Name: "doesNotExist"},
}, },
}) })
@@ -234,7 +315,7 @@ func TestResolveVarsWithNoambiguation(t *testing.T) {
{ {
Name: "SERVICE_ONE", Name: "SERVICE_ONE",
ObjRef: types.Target{ ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"}, Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne", Name: "backendOne",
}, },
}, },
@@ -289,7 +370,7 @@ func TestResolveVarsWithNoambiguation(t *testing.T) {
{ {
Name: "SUB_SERVICE_ONE", Name: "SUB_SERVICE_ONE",
ObjRef: types.Target{ ObjRef: types.Target{
Gvk: gvk.Gvk{Version: "v1", Kind: "Service"}, Gvk: resid.Gvk{Version: "v1", Kind: "Service"},
Name: "backendOne", Name: "backendOne",
}, },
}, },

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
// Package error has contextual error types. // Package error has contextual error types.
package kusterr package kusterr

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
package kusterr package kusterr

View File

@@ -7,16 +7,14 @@ package loadertest
import ( import (
"log" "log"
"sigs.k8s.io/kustomize/v3/pkg/fs" "sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/v3/pkg/loader" "sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/v3/pkg/types"
"sigs.k8s.io/kustomize/v3/pkg/validators"
) )
// FakeLoader encapsulates the delegate Loader and the fake file system. // FakeLoader encapsulates the delegate Loader and the fake file system.
type FakeLoader struct { type FakeLoader struct {
fs fs.FileSystem fs filesys.FileSystem
delegate ifc.Loader delegate ifc.Loader
} }
@@ -34,10 +32,9 @@ func NewFakeLoader(initialDir string) FakeLoader {
func NewFakeLoaderWithRestrictor( func NewFakeLoaderWithRestrictor(
lr loader.LoadRestrictorFunc, initialDir string) FakeLoader { lr loader.LoadRestrictorFunc, initialDir string) FakeLoader {
// Create fake filesystem and inject it into initial Loader. // Create fake filesystem and inject it into initial Loader.
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
fSys.Mkdir(initialDir) fSys.Mkdir(initialDir)
ldr, err := loader.NewLoader( ldr, err := loader.NewLoader(lr, initialDir, fSys)
lr, validators.MakeFakeValidator(), initialDir, fSys)
if err != nil { if err != nil {
log.Fatalf("Unable to make loader: %v", err) log.Fatalf("Unable to make loader: %v", err)
} }
@@ -77,13 +74,3 @@ func (f FakeLoader) Load(location string) ([]byte, error) {
func (f FakeLoader) Cleanup() error { func (f FakeLoader) Cleanup() error {
return f.delegate.Cleanup() return f.delegate.Cleanup()
} }
// Validator delegates.
func (f FakeLoader) Validator() ifc.Validator {
return f.delegate.Validator()
}
// LoadKvPairs delegates.
func (f FakeLoader) LoadKvPairs(args types.GeneratorArgs) ([]types.Pair, error) {
return f.delegate.LoadKvPairs(args)
}

View File

@@ -6,7 +6,7 @@ package inventory
import ( import (
"encoding/json" "encoding/json"
"sigs.k8s.io/kustomize/v3/pkg/resid" "sigs.k8s.io/kustomize/api/resid"
) )
//Refs is a reference map. Each key is the id //Refs is a reference map. Each key is the id

View File

@@ -1,25 +1,13 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package inventory_test
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.
*/
package inventory
import ( import (
"testing" "testing"
"sigs.k8s.io/kustomize/v3/pkg/resid" . "sigs.k8s.io/kustomize/api/inventory"
"sigs.k8s.io/kustomize/api/resid"
) )
func makeRefs() (Refs, Refs) { func makeRefs() (Refs, Refs) {

View File

@@ -10,7 +10,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/types"
) )
func makeFreshConfigMap( func makeFreshConfigMap(
@@ -27,7 +27,7 @@ func makeFreshConfigMap(
// MakeConfigMap returns a new ConfigMap, or nil and an error. // MakeConfigMap returns a new ConfigMap, or nil and an error.
func (f *Factory) MakeConfigMap( func (f *Factory) MakeConfigMap(
args *types.ConfigMapArgs) (*v1.ConfigMap, error) { args *types.ConfigMapArgs) (*v1.ConfigMap, error) {
all, err := f.ldr.LoadKvPairs(args.GeneratorArgs) all, err := f.kvLdr.Load(args.KvPairSources)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "loading KV pairs") return nil, errors.Wrap(err, "loading KV pairs")
} }
@@ -48,7 +48,7 @@ func (f *Factory) MakeConfigMap(
// addKvToConfigMap adds the given key and data to the given config map. // addKvToConfigMap adds the given key and data to the given config map.
// Error if key invalid, or already exists. // Error if key invalid, or already exists.
func (f *Factory) addKvToConfigMap(configMap *v1.ConfigMap, p types.Pair) error { func (f *Factory) addKvToConfigMap(configMap *v1.ConfigMap, p types.Pair) error {
if err := f.ldr.Validator().ErrIfInvalidKey(p.Key); err != nil { if err := f.kvLdr.Validator().ErrIfInvalidKey(p.Key); err != nil {
return err return err
} }
// If the configmap data contains byte sequences that are all in the UTF-8 // If the configmap data contains byte sequences that are all in the UTF-8

View File

@@ -10,10 +10,11 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/kustomize/v3/pkg/fs" "sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/v3/pkg/loader" "sigs.k8s.io/kustomize/api/kv"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/v3/pkg/validators" "sigs.k8s.io/kustomize/api/testutils/valtest"
"sigs.k8s.io/kustomize/api/types"
) )
func makeEnvConfigMap(name string) *corev1.ConfigMap { func makeEnvConfigMap(name string) *corev1.ConfigMap {
@@ -86,7 +87,7 @@ func TestConstructConfigMap(t *testing.T) {
input: types.ConfigMapArgs{ input: types.ConfigMapArgs{
GeneratorArgs: types.GeneratorArgs{ GeneratorArgs: types.GeneratorArgs{
Name: "envConfigMap", Name: "envConfigMap",
DataSources: types.DataSources{ KvPairSources: types.KvPairSources{
EnvSources: []string{ EnvSources: []string{
filepath.Join("configmap", "app.env"), filepath.Join("configmap", "app.env"),
}, },
@@ -101,7 +102,7 @@ func TestConstructConfigMap(t *testing.T) {
input: types.ConfigMapArgs{ input: types.ConfigMapArgs{
GeneratorArgs: types.GeneratorArgs{ GeneratorArgs: types.GeneratorArgs{
Name: "fileConfigMap", Name: "fileConfigMap",
DataSources: types.DataSources{ KvPairSources: types.KvPairSources{
FileSources: []string{ FileSources: []string{
filepath.Join("configmap", "app-init.ini"), filepath.Join("configmap", "app-init.ini"),
filepath.Join("configmap", "app.bin"), filepath.Join("configmap", "app.bin"),
@@ -117,7 +118,7 @@ func TestConstructConfigMap(t *testing.T) {
input: types.ConfigMapArgs{ input: types.ConfigMapArgs{
GeneratorArgs: types.GeneratorArgs{ GeneratorArgs: types.GeneratorArgs{
Name: "literalConfigMap", Name: "literalConfigMap",
DataSources: types.DataSources{ KvPairSources: types.KvPairSources{
LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"}, LiteralSources: []string{"a=x", "b=y", "c=\"Hello World\"", "d='true'"},
}, },
}, },
@@ -131,19 +132,21 @@ func TestConstructConfigMap(t *testing.T) {
}, },
} }
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
fSys.WriteFile( fSys.WriteFile(
fs.RPath("configmap", "app.env"), filesys.RootedPath("configmap", "app.env"),
[]byte("DB_USERNAME=admin\nDB_PASSWORD=somepw\n")) []byte("DB_USERNAME=admin\nDB_PASSWORD=somepw\n"))
fSys.WriteFile( fSys.WriteFile(
fs.RPath("configmap", "app-init.ini"), filesys.RootedPath("configmap", "app-init.ini"),
[]byte("FOO=bar\nBAR=baz\n")) []byte("FOO=bar\nBAR=baz\n"))
fSys.WriteFile( fSys.WriteFile(
fs.RPath("configmap", "app.bin"), filesys.RootedPath("configmap", "app.bin"),
[]byte{0xff, 0xfd}) []byte{0xff, 0xfd})
ldr := loader.NewFileLoaderAtRoot(validators.MakeFakeValidator(), fSys) kvLdr := kv.NewLoader(
loader.NewFileLoaderAtRoot(fSys),
valtest_test.MakeFakeValidator())
for _, tc := range testCases { for _, tc := range testCases {
f := NewFactory(ldr, tc.options) f := NewFactory(kvLdr, tc.options)
cm, err := f.MakeConfigMap(&tc.input) cm, err := f.MakeConfigMap(&tc.input)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)

View File

@@ -4,20 +4,20 @@
package configmapandsecret package configmapandsecret
import ( import (
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/types"
) )
// Factory makes ConfigMaps and Secrets. // Factory makes ConfigMaps and Secrets.
type Factory struct { type Factory struct {
ldr ifc.Loader kvLdr ifc.KvLoader
options *types.GeneratorOptions options *types.GeneratorOptions
} }
// NewFactory returns a new factory that makes ConfigMaps and Secrets. // NewFactory returns a new factory that makes ConfigMaps and Secrets.
func NewFactory( func NewFactory(
ldr ifc.Loader, o *types.GeneratorOptions) *Factory { kvLdr ifc.KvLoader, o *types.GeneratorOptions) *Factory {
return &Factory{ldr: ldr, options: o} return &Factory{kvLdr: kvLdr, options: o}
} }
const keyExistsErrorMsg = "cannot add key %s, another key by that name already exists: %v" const keyExistsErrorMsg = "cannot add key %s, another key by that name already exists: %v"

View File

@@ -7,7 +7,7 @@ import (
"fmt" "fmt"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/types"
) )
func makeFreshSecret( func makeFreshSecret(
@@ -28,7 +28,7 @@ func makeFreshSecret(
// MakeSecret returns a new secret. // MakeSecret returns a new secret.
func (f *Factory) MakeSecret( func (f *Factory) MakeSecret(
args *types.SecretArgs) (*corev1.Secret, error) { args *types.SecretArgs) (*corev1.Secret, error) {
all, err := f.ldr.LoadKvPairs(args.GeneratorArgs) all, err := f.kvLdr.Load(args.KvPairSources)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -47,7 +47,7 @@ func (f *Factory) MakeSecret(
} }
func (f *Factory) addKvToSecret(secret *corev1.Secret, keyName, data string) error { func (f *Factory) addKvToSecret(secret *corev1.Secret, keyName, data string) error {
if err := f.ldr.Validator().ErrIfInvalidKey(keyName); err != nil { if err := f.kvLdr.Validator().ErrIfInvalidKey(keyName); err != nil {
return err return err
} }
if _, entryExists := secret.Data[keyName]; entryExists { if _, entryExists := secret.Data[keyName]; entryExists {

View File

@@ -9,10 +9,11 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/kustomize/v3/pkg/fs" "sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/v3/pkg/loader" "sigs.k8s.io/kustomize/api/kv"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/v3/pkg/validators" "sigs.k8s.io/kustomize/api/testutils/valtest"
"sigs.k8s.io/kustomize/api/types"
) )
func makeEnvSecret(name string) *corev1.Secret { func makeEnvSecret(name string) *corev1.Secret {
@@ -83,7 +84,7 @@ func TestConstructSecret(t *testing.T) {
input: types.SecretArgs{ input: types.SecretArgs{
GeneratorArgs: types.GeneratorArgs{ GeneratorArgs: types.GeneratorArgs{
Name: "envSecret", Name: "envSecret",
DataSources: types.DataSources{ KvPairSources: types.KvPairSources{
EnvSources: []string{"secret/app.env"}, EnvSources: []string{"secret/app.env"},
}, },
}, },
@@ -96,7 +97,7 @@ func TestConstructSecret(t *testing.T) {
input: types.SecretArgs{ input: types.SecretArgs{
GeneratorArgs: types.GeneratorArgs{ GeneratorArgs: types.GeneratorArgs{
Name: "fileSecret", Name: "fileSecret",
DataSources: types.DataSources{ KvPairSources: types.KvPairSources{
FileSources: []string{"secret/app-init.ini"}, FileSources: []string{"secret/app-init.ini"},
}, },
}, },
@@ -109,7 +110,7 @@ func TestConstructSecret(t *testing.T) {
input: types.SecretArgs{ input: types.SecretArgs{
GeneratorArgs: types.GeneratorArgs{ GeneratorArgs: types.GeneratorArgs{
Name: "literalSecret", Name: "literalSecret",
DataSources: types.DataSources{ KvPairSources: types.KvPairSources{
LiteralSources: []string{"a=x", "b=y"}, LiteralSources: []string{"a=x", "b=y"},
}, },
}, },
@@ -123,12 +124,14 @@ func TestConstructSecret(t *testing.T) {
}, },
} }
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
fSys.WriteFile("/secret/app.env", []byte("DB_USERNAME=admin\nDB_PASSWORD=somepw\n")) fSys.WriteFile("/secret/app.env", []byte("DB_USERNAME=admin\nDB_PASSWORD=somepw\n"))
fSys.WriteFile("/secret/app-init.ini", []byte("FOO=bar\nBAR=baz\n")) fSys.WriteFile("/secret/app-init.ini", []byte("FOO=bar\nBAR=baz\n"))
ldr := loader.NewFileLoaderAtRoot(validators.MakeFakeValidator(), fSys) kvLdr := kv.NewLoader(
loader.NewFileLoaderAtRoot(fSys),
valtest_test.MakeFakeValidator())
for _, tc := range testCases { for _, tc := range testCases {
f := NewFactory(ldr, tc.options) f := NewFactory(kvLdr, tc.options)
cm, err := f.MakeSecret(&tc.input) cm, err := f.MakeSecret(&tc.input)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)

View File

@@ -12,9 +12,9 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/yaml" "k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/kustomize/v3/k8sdeps/configmapandsecret" "sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/k8sdeps/configmapandsecret"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/types"
) )
// KunstructuredFactoryImpl hides construction using apimachinery types. // KunstructuredFactoryImpl hides construction using apimachinery types.
@@ -73,11 +73,11 @@ func (kf *KunstructuredFactoryImpl) FromMap(
// MakeConfigMap returns an instance of Kunstructured for ConfigMap // MakeConfigMap returns an instance of Kunstructured for ConfigMap
func (kf *KunstructuredFactoryImpl) MakeConfigMap( func (kf *KunstructuredFactoryImpl) MakeConfigMap(
ldr ifc.Loader, kvLdr ifc.KvLoader,
options *types.GeneratorOptions, options *types.GeneratorOptions,
args *types.ConfigMapArgs) (ifc.Kunstructured, error) { args *types.ConfigMapArgs) (ifc.Kunstructured, error) {
o, err := configmapandsecret.NewFactory( o, err := configmapandsecret.NewFactory(
ldr, options).MakeConfigMap(args) kvLdr, options).MakeConfigMap(args)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -86,11 +86,11 @@ func (kf *KunstructuredFactoryImpl) MakeConfigMap(
// MakeSecret returns an instance of Kunstructured for Secret // MakeSecret returns an instance of Kunstructured for Secret
func (kf *KunstructuredFactoryImpl) MakeSecret( func (kf *KunstructuredFactoryImpl) MakeSecret(
ldr ifc.Loader, kvLdr ifc.KvLoader,
options *types.GeneratorOptions, options *types.GeneratorOptions,
args *types.SecretArgs) (ifc.Kunstructured, error) { args *types.SecretArgs) (ifc.Kunstructured, error) {
o, err := configmapandsecret.NewFactory( o, err := configmapandsecret.NewFactory(
ldr, options).MakeSecret(args) kvLdr, options).MakeSecret(args)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -20,7 +20,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/ifc"
) )
func TestSliceFromBytes(t *testing.T) { func TestSliceFromBytes(t *testing.T) {

View File

@@ -9,8 +9,8 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/kustomize/v3/pkg/hasher" "sigs.k8s.io/kustomize/api/hasher"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/ifc"
) )
// kustHash computes a hash of an unstructured object. // kustHash computes a hash of an unstructured object.

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
// Package kunstruct provides unstructured from api machinery and factory for creating unstructured // Package kunstruct provides unstructured from api machinery and factory for creating unstructured
package kunstruct package kunstruct
@@ -20,19 +7,17 @@ package kunstruct
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
jsonpatch "github.com/evanphx/json-patch" jsonpatch "github.com/evanphx/json-patch"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/kustomize/api/ifc"
"k8s.io/apimachinery/pkg/labels" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
) )
var _ ifc.Kunstructured = &UnstructAdapter{} var _ ifc.Kunstructured = &UnstructAdapter{}
@@ -60,9 +45,9 @@ func NewKunstructuredFromObject(obj runtime.Object) (ifc.Kunstructured, error) {
} }
// GetGvk returns the Gvk name of the object. // GetGvk returns the Gvk name of the object.
func (fs *UnstructAdapter) GetGvk() gvk.Gvk { func (fs *UnstructAdapter) GetGvk() resid.Gvk {
x := fs.GroupVersionKind() x := fs.GroupVersionKind()
return gvk.Gvk{ return resid.Gvk{
Group: x.Group, Group: x.Group,
Version: x.Version, Version: x.Version,
Kind: x.Kind, Kind: x.Kind,
@@ -70,7 +55,7 @@ func (fs *UnstructAdapter) GetGvk() gvk.Gvk {
} }
// SetGvk set the Gvk of the object to the input Gvk // SetGvk set the Gvk of the object to the input Gvk
func (fs *UnstructAdapter) SetGvk(g gvk.Gvk) { func (fs *UnstructAdapter) SetGvk(g resid.Gvk) {
fs.SetGroupVersionKind(toSchemaGvk(g)) fs.SetGroupVersionKind(toSchemaGvk(g))
} }
@@ -148,7 +133,7 @@ func (fs *UnstructAdapter) selectSubtree(path string) (map[string]interface{}, [
func (fs *UnstructAdapter) GetFieldValue(path string) (interface{}, error) { func (fs *UnstructAdapter) GetFieldValue(path string) (interface{}, error) {
content, fields, found, err := fs.selectSubtree(path) content, fields, found, err := fs.selectSubtree(path)
if !found || err != nil { if !found || err != nil {
return nil, types.NoFieldError{Field: path} return nil, noFieldError{Field: path}
} }
s, found, err := unstructured.NestedFieldNoCopy( s, found, err := unstructured.NestedFieldNoCopy(
@@ -156,14 +141,14 @@ func (fs *UnstructAdapter) GetFieldValue(path string) (interface{}, error) {
if found || err != nil { if found || err != nil {
return s, err return s, err
} }
return nil, types.NoFieldError{Field: path} return nil, noFieldError{Field: path}
} }
// GetString returns value at the given fieldpath. // GetString returns value at the given fieldpath.
func (fs *UnstructAdapter) GetString(path string) (string, error) { func (fs *UnstructAdapter) GetString(path string) (string, error) {
content, fields, found, err := fs.selectSubtree(path) content, fields, found, err := fs.selectSubtree(path)
if !found || err != nil { if !found || err != nil {
return "", types.NoFieldError{Field: path} return "", noFieldError{Field: path}
} }
s, found, err := unstructured.NestedString( s, found, err := unstructured.NestedString(
@@ -171,14 +156,14 @@ func (fs *UnstructAdapter) GetString(path string) (string, error) {
if found || err != nil { if found || err != nil {
return s, err return s, err
} }
return "", types.NoFieldError{Field: path} return "", noFieldError{Field: path}
} }
// GetStringSlice returns value at the given fieldpath. // GetStringSlice returns value at the given fieldpath.
func (fs *UnstructAdapter) GetStringSlice(path string) ([]string, error) { func (fs *UnstructAdapter) GetStringSlice(path string) ([]string, error) {
content, fields, found, err := fs.selectSubtree(path) content, fields, found, err := fs.selectSubtree(path)
if !found || err != nil { if !found || err != nil {
return []string{}, types.NoFieldError{Field: path} return []string{}, noFieldError{Field: path}
} }
s, found, err := unstructured.NestedStringSlice( s, found, err := unstructured.NestedStringSlice(
@@ -186,14 +171,14 @@ func (fs *UnstructAdapter) GetStringSlice(path string) ([]string, error) {
if found || err != nil { if found || err != nil {
return s, err return s, err
} }
return []string{}, types.NoFieldError{Field: path} return []string{}, noFieldError{Field: path}
} }
// GetBool returns value at the given fieldpath. // GetBool returns value at the given fieldpath.
func (fs *UnstructAdapter) GetBool(path string) (bool, error) { func (fs *UnstructAdapter) GetBool(path string) (bool, error) {
content, fields, found, err := fs.selectSubtree(path) content, fields, found, err := fs.selectSubtree(path)
if !found || err != nil { if !found || err != nil {
return false, types.NoFieldError{Field: path} return false, noFieldError{Field: path}
} }
s, found, err := unstructured.NestedBool( s, found, err := unstructured.NestedBool(
@@ -201,7 +186,7 @@ func (fs *UnstructAdapter) GetBool(path string) (bool, error) {
if found || err != nil { if found || err != nil {
return s, err return s, err
} }
return false, types.NoFieldError{Field: path} return false, noFieldError{Field: path}
} }
// GetFloat64 returns value at the given fieldpath. // GetFloat64 returns value at the given fieldpath.
@@ -216,14 +201,14 @@ func (fs *UnstructAdapter) GetFloat64(path string) (float64, error) {
if found || err != nil { if found || err != nil {
return s, err return s, err
} }
return 0, types.NoFieldError{Field: path} return 0, noFieldError{Field: path}
} }
// GetInt64 returns value at the given fieldpath. // GetInt64 returns value at the given fieldpath.
func (fs *UnstructAdapter) GetInt64(path string) (int64, error) { func (fs *UnstructAdapter) GetInt64(path string) (int64, error) {
content, fields, found, err := fs.selectSubtree(path) content, fields, found, err := fs.selectSubtree(path)
if !found || err != nil { if !found || err != nil {
return 0, types.NoFieldError{Field: path} return 0, noFieldError{Field: path}
} }
s, found, err := unstructured.NestedInt64( s, found, err := unstructured.NestedInt64(
@@ -231,14 +216,14 @@ func (fs *UnstructAdapter) GetInt64(path string) (int64, error) {
if found || err != nil { if found || err != nil {
return s, err return s, err
} }
return 0, types.NoFieldError{Field: path} return 0, noFieldError{Field: path}
} }
// GetSlice returns value at the given fieldpath. // GetSlice returns value at the given fieldpath.
func (fs *UnstructAdapter) GetSlice(path string) ([]interface{}, error) { func (fs *UnstructAdapter) GetSlice(path string) ([]interface{}, error) {
content, fields, found, err := fs.selectSubtree(path) content, fields, found, err := fs.selectSubtree(path)
if !found || err != nil { if !found || err != nil {
return nil, types.NoFieldError{Field: path} return nil, noFieldError{Field: path}
} }
s, found, err := unstructured.NestedSlice( s, found, err := unstructured.NestedSlice(
@@ -246,14 +231,14 @@ func (fs *UnstructAdapter) GetSlice(path string) ([]interface{}, error) {
if found || err != nil { if found || err != nil {
return s, err return s, err
} }
return nil, types.NoFieldError{Field: path} return nil, noFieldError{Field: path}
} }
// GetStringMap returns value at the given fieldpath. // GetStringMap returns value at the given fieldpath.
func (fs *UnstructAdapter) GetStringMap(path string) (map[string]string, error) { func (fs *UnstructAdapter) GetStringMap(path string) (map[string]string, error) {
content, fields, found, err := fs.selectSubtree(path) content, fields, found, err := fs.selectSubtree(path)
if !found || err != nil { if !found || err != nil {
return nil, types.NoFieldError{Field: path} return nil, noFieldError{Field: path}
} }
s, found, err := unstructured.NestedStringMap( s, found, err := unstructured.NestedStringMap(
@@ -261,14 +246,14 @@ func (fs *UnstructAdapter) GetStringMap(path string) (map[string]string, error)
if found || err != nil { if found || err != nil {
return s, err return s, err
} }
return nil, types.NoFieldError{Field: path} return nil, noFieldError{Field: path}
} }
// GetMap returns value at the given fieldpath. // GetMap returns value at the given fieldpath.
func (fs *UnstructAdapter) GetMap(path string) (map[string]interface{}, error) { func (fs *UnstructAdapter) GetMap(path string) (map[string]interface{}, error) {
content, fields, found, err := fs.selectSubtree(path) content, fields, found, err := fs.selectSubtree(path)
if !found || err != nil { if !found || err != nil {
return nil, types.NoFieldError{Field: path} return nil, noFieldError{Field: path}
} }
s, found, err := unstructured.NestedMap( s, found, err := unstructured.NestedMap(
@@ -276,7 +261,7 @@ func (fs *UnstructAdapter) GetMap(path string) (map[string]interface{}, error) {
if found || err != nil { if found || err != nil {
return s, err return s, err
} }
return nil, types.NoFieldError{Field: path} return nil, noFieldError{Field: path}
} }
func (fs *UnstructAdapter) MatchesLabelSelector(selector string) (bool, error) { func (fs *UnstructAdapter) MatchesLabelSelector(selector string) (bool, error) {
@@ -347,10 +332,19 @@ func (fs *UnstructAdapter) Patch(patch ifc.Kunstructured) error {
} }
// toSchemaGvk converts to a schema.GroupVersionKind. // toSchemaGvk converts to a schema.GroupVersionKind.
func toSchemaGvk(x gvk.Gvk) schema.GroupVersionKind { func toSchemaGvk(x resid.Gvk) schema.GroupVersionKind {
return schema.GroupVersionKind{ return schema.GroupVersionKind{
Group: x.Group, Group: x.Group,
Version: x.Version, Version: x.Version,
Kind: x.Kind, Kind: x.Kind,
} }
} }
// noFieldError is returned when a field is expected, but missing.
type noFieldError struct {
Field string
}
func (e noFieldError) Error() string {
return fmt.Sprintf("no field named '%s'", e.Field)
}

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
package kunstruct package kunstruct

View File

@@ -5,9 +5,9 @@
package transformer package transformer
import ( import (
"sigs.k8s.io/kustomize/v3/k8sdeps/transformer/patch" "sigs.k8s.io/kustomize/api/k8sdeps/transformer/patch"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resource" "sigs.k8s.io/kustomize/api/resource"
) )
// FactoryImpl makes patch transformer and name hash transformer // FactoryImpl makes patch transformer and name hash transformer

View File

@@ -7,16 +7,15 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
jsonpatch "github.com/evanphx/json-patch" jsonpatch "github.com/evanphx/json-patch"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/mergepatch" "k8s.io/apimachinery/pkg/util/mergepatch"
"k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/strategicpatch"
"sigs.k8s.io/kustomize/v3/pkg/resource" "k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
) )
type conflictDetector interface { type conflictDetector interface {
@@ -188,7 +187,7 @@ func MergePatches(patches []*resource.Resource,
} }
// toSchemaGvk converts to a schema.GroupVersionKind. // toSchemaGvk converts to a schema.GroupVersionKind.
func toSchemaGvk(x gvk.Gvk) schema.GroupVersionKind { func toSchemaGvk(x resid.Gvk) schema.GroupVersionKind {
return schema.GroupVersionKind{ return schema.GroupVersionKind{
Group: x.Group, Group: x.Group,
Version: x.Version, Version: x.Version,

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package loader package kv
import ( import (
"bufio" "bufio"
@@ -14,19 +14,32 @@ import (
"unicode/utf8" "unicode/utf8"
"github.com/pkg/errors" "github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/types"
) )
var utf8bom = []byte{0xEF, 0xBB, 0xBF} var utf8bom = []byte{0xEF, 0xBB, 0xBF}
func (fl *fileLoader) Validator() ifc.Validator { // loader reads and validates KV pairs.
return fl.validator type loader struct {
// Used to read the filesystem.
ldr ifc.Loader
// Used to validate various k8s data fields.
validator ifc.Validator
} }
func (fl *fileLoader) LoadKvPairs( func NewLoader(ldr ifc.Loader, v ifc.Validator) ifc.KvLoader {
args types.GeneratorArgs) (all []types.Pair, err error) { return &loader{ldr: ldr, validator: v}
pairs, err := fl.keyValuesFromEnvFiles(args.EnvSources) }
func (kvl *loader) Validator() ifc.Validator {
return kvl.validator
}
func (kvl *loader) Load(
args types.KvPairSources) (all []types.Pair, err error) {
pairs, err := kvl.keyValuesFromEnvFiles(args.EnvSources)
if err != nil { if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf( return nil, errors.Wrap(err, fmt.Sprintf(
"env source files: %v", "env source files: %v",
@@ -41,7 +54,7 @@ func (fl *fileLoader) LoadKvPairs(
} }
all = append(all, pairs...) all = append(all, pairs...)
pairs, err = fl.keyValuesFromFileSources(args.FileSources) pairs, err = kvl.keyValuesFromFileSources(args.FileSources)
if err != nil { if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf( return nil, errors.Wrap(err, fmt.Sprintf(
"file sources: %v", args.FileSources)) "file sources: %v", args.FileSources))
@@ -61,14 +74,14 @@ func keyValuesFromLiteralSources(sources []string) ([]types.Pair, error) {
return kvs, nil return kvs, nil
} }
func (fl *fileLoader) keyValuesFromFileSources(sources []string) ([]types.Pair, error) { func (kvl *loader) keyValuesFromFileSources(sources []string) ([]types.Pair, error) {
var kvs []types.Pair var kvs []types.Pair
for _, s := range sources { for _, s := range sources {
k, fPath, err := parseFileSource(s) k, fPath, err := parseFileSource(s)
if err != nil { if err != nil {
return nil, err return nil, err
} }
content, err := fl.Load(fPath) content, err := kvl.ldr.Load(fPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -77,14 +90,14 @@ func (fl *fileLoader) keyValuesFromFileSources(sources []string) ([]types.Pair,
return kvs, nil return kvs, nil
} }
func (fl *fileLoader) keyValuesFromEnvFiles(paths []string) ([]types.Pair, error) { func (kvl *loader) keyValuesFromEnvFiles(paths []string) ([]types.Pair, error) {
var kvs []types.Pair var kvs []types.Pair
for _, p := range paths { for _, p := range paths {
content, err := fl.Load(p) content, err := kvl.ldr.Load(p)
if err != nil { if err != nil {
return nil, err return nil, err
} }
more, err := fl.keyValuesFromLines(content) more, err := kvl.keyValuesFromLines(content)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -94,7 +107,7 @@ func (fl *fileLoader) keyValuesFromEnvFiles(paths []string) ([]types.Pair, error
} }
// keyValuesFromLines parses given content in to a list of key-value pairs. // keyValuesFromLines parses given content in to a list of key-value pairs.
func (fl *fileLoader) keyValuesFromLines(content []byte) ([]types.Pair, error) { func (kvl *loader) keyValuesFromLines(content []byte) ([]types.Pair, error) {
var kvs []types.Pair var kvs []types.Pair
scanner := bufio.NewScanner(bytes.NewReader(content)) scanner := bufio.NewScanner(bytes.NewReader(content))
@@ -103,7 +116,7 @@ func (fl *fileLoader) keyValuesFromLines(content []byte) ([]types.Pair, error) {
// Process the current line, retrieving a key/value pair if // Process the current line, retrieving a key/value pair if
// possible. // possible.
scannedBytes := scanner.Bytes() scannedBytes := scanner.Bytes()
kv, err := fl.keyValuesFromLine(scannedBytes, currentLine) kv, err := kvl.keyValuesFromLine(scannedBytes, currentLine)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -121,7 +134,7 @@ func (fl *fileLoader) keyValuesFromLines(content []byte) ([]types.Pair, error) {
// KeyValuesFromLine returns a kv with blank key if the line is empty or a comment. // KeyValuesFromLine returns a kv with blank key if the line is empty or a comment.
// The value will be retrieved from the environment if necessary. // The value will be retrieved from the environment if necessary.
func (fl *fileLoader) keyValuesFromLine(line []byte, currentLine int) (types.Pair, error) { func (kvl *loader) keyValuesFromLine(line []byte, currentLine int) (types.Pair, error) {
kv := types.Pair{} kv := types.Pair{}
if !utf8.Valid(line) { if !utf8.Valid(line) {
@@ -143,7 +156,7 @@ func (fl *fileLoader) keyValuesFromLine(line []byte, currentLine int) (types.Pai
data := strings.SplitN(string(line), "=", 2) data := strings.SplitN(string(line), "=", 2)
key := data[0] key := data[0]
if err := fl.validator.IsEnvVarName(key); err != nil { if err := kvl.validator.IsEnvVarName(key); err != nil {
return kv, err return kv, err
} }

View File

@@ -1,17 +1,24 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package loader package kv
import ( import (
"reflect" "reflect"
"testing" "testing"
"sigs.k8s.io/kustomize/v3/pkg/fs" "sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/v3/pkg/types" ldr "sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/v3/pkg/validators" "sigs.k8s.io/kustomize/api/testutils/valtest"
"sigs.k8s.io/kustomize/api/types"
) )
func makeKvLoader(fSys filesys.FileSystem) *loader {
return &loader{
ldr: ldr.NewFileLoaderAtRoot(fSys),
validator: valtest_test.MakeFakeValidator()}
}
func TestKeyValuesFromLines(t *testing.T) { func TestKeyValuesFromLines(t *testing.T) {
tests := []struct { tests := []struct {
desc string desc string
@@ -45,10 +52,9 @@ func TestKeyValuesFromLines(t *testing.T) {
// TODO: add negative testcases // TODO: add negative testcases
} }
l := NewFileLoaderAtRoot( kvl := makeKvLoader(filesys.MakeFsInMemory())
validators.MakeFakeValidator(), fs.MakeFsInMemory())
for _, test := range tests { for _, test := range tests {
pairs, err := l.keyValuesFromLines([]byte(test.content)) pairs, err := kvl.keyValuesFromLines([]byte(test.content))
if test.expectedErr && err == nil { if test.expectedErr && err == nil {
t.Fatalf("%s should not return error", test.desc) t.Fatalf("%s should not return error", test.desc)
} }
@@ -76,11 +82,11 @@ func TestKeyValuesFromFileSources(t *testing.T) {
}, },
} }
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
fSys.WriteFile("/files/app-init.ini", []byte("FOO=bar")) fSys.WriteFile("/files/app-init.ini", []byte("FOO=bar"))
l := NewFileLoaderAtRoot(validators.MakeFakeValidator(), fSys) kvl := makeKvLoader(fSys)
for _, tc := range tests { for _, tc := range tests {
kvs, err := l.keyValuesFromFileSources(tc.sources) kvs, err := kvl.keyValuesFromFileSources(tc.sources)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }

View File

@@ -9,9 +9,9 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"sigs.k8s.io/kustomize/v3/pkg/fs" "sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/v3/pkg/git" "sigs.k8s.io/kustomize/api/git"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/ifc"
) )
// fileLoader is a kustomization's interface to files. // fileLoader is a kustomization's interface to files.
@@ -74,20 +74,17 @@ type fileLoader struct {
// An absolute, cleaned path to a directory. // An absolute, cleaned path to a directory.
// The Load function will read non-absolute // The Load function will read non-absolute
// paths relative to this directory. // paths relative to this directory.
root fs.ConfirmedDir root filesys.ConfirmedDir
// Restricts behavior of Load function. // Restricts behavior of Load function.
loadRestrictor LoadRestrictorFunc loadRestrictor LoadRestrictorFunc
// Used to validate various k8s data fields.
validator ifc.Validator
// If this is non-nil, the files were // If this is non-nil, the files were
// obtained from the given repository. // obtained from the given repository.
repoSpec *git.RepoSpec repoSpec *git.RepoSpec
// File system utilities. // File system utilities.
fSys fs.FileSystem fSys filesys.FileSystem
// Used to clone repositories. // Used to clone repositories.
cloner git.Cloner cloner git.Cloner
@@ -100,16 +97,16 @@ const CWD = "."
// NewFileLoaderAtCwd returns a loader that loads from ".". // NewFileLoaderAtCwd returns a loader that loads from ".".
// A convenience for kustomize edit commands. // A convenience for kustomize edit commands.
func NewFileLoaderAtCwd(v ifc.Validator, fSys fs.FileSystem) *fileLoader { func NewFileLoaderAtCwd(fSys filesys.FileSystem) *fileLoader {
return newLoaderOrDie( return newLoaderOrDie(
RestrictionRootOnly, v, fSys, CWD) RestrictionRootOnly, fSys, CWD)
} }
// NewFileLoaderAtRoot returns a loader that loads from "/". // NewFileLoaderAtRoot returns a loader that loads from "/".
// A convenience for tests. // A convenience for tests.
func NewFileLoaderAtRoot(v ifc.Validator, fSys fs.FileSystem) *fileLoader { func NewFileLoaderAtRoot(fSys filesys.FileSystem) *fileLoader {
return newLoaderOrDie( return newLoaderOrDie(
RestrictionRootOnly, v, fSys, string(filepath.Separator)) RestrictionRootOnly, fSys, string(filepath.Separator))
} }
// Root returns the absolute path that is prepended to any // Root returns the absolute path that is prepended to any
@@ -119,25 +116,23 @@ func (fl *fileLoader) Root() string {
} }
func newLoaderOrDie( func newLoaderOrDie(
lr LoadRestrictorFunc, v ifc.Validator, lr LoadRestrictorFunc,
fSys fs.FileSystem, path string) *fileLoader { fSys filesys.FileSystem, path string) *fileLoader {
root, err := demandDirectoryRoot(fSys, path) root, err := demandDirectoryRoot(fSys, path)
if err != nil { if err != nil {
log.Fatalf("unable to make loader at '%s'; %v", path, err) log.Fatalf("unable to make loader at '%s'; %v", path, err)
} }
return newLoaderAtConfirmedDir( return newLoaderAtConfirmedDir(
lr, v, root, fSys, nil, git.ClonerUsingGitExec) lr, root, fSys, nil, git.ClonerUsingGitExec)
} }
// newLoaderAtConfirmedDir returns a new fileLoader with given root. // newLoaderAtConfirmedDir returns a new fileLoader with given root.
func newLoaderAtConfirmedDir( func newLoaderAtConfirmedDir(
lr LoadRestrictorFunc, lr LoadRestrictorFunc,
v ifc.Validator, root filesys.ConfirmedDir, fSys filesys.FileSystem,
root fs.ConfirmedDir, fSys fs.FileSystem,
referrer *fileLoader, cloner git.Cloner) *fileLoader { referrer *fileLoader, cloner git.Cloner) *fileLoader {
return &fileLoader{ return &fileLoader{
loadRestrictor: lr, loadRestrictor: lr,
validator: v,
root: root, root: root,
referrer: referrer, referrer: referrer,
fSys: fSys, fSys: fSys,
@@ -148,7 +143,7 @@ func newLoaderAtConfirmedDir(
// Assure that the given path is in fact a directory. // Assure that the given path is in fact a directory.
func demandDirectoryRoot( func demandDirectoryRoot(
fSys fs.FileSystem, path string) (fs.ConfirmedDir, error) { fSys filesys.FileSystem, path string) (filesys.ConfirmedDir, error) {
if path == "" { if path == "" {
return "", fmt.Errorf( return "", fmt.Errorf(
"loader root cannot be empty") "loader root cannot be empty")
@@ -179,7 +174,7 @@ func (fl *fileLoader) New(path string) (ifc.Loader, error) {
return nil, err return nil, err
} }
return newLoaderAtGitClone( return newLoaderAtGitClone(
repoSpec, fl.validator, fl.fSys, fl, fl.cloner) repoSpec, fl.fSys, fl, fl.cloner)
} }
if filepath.IsAbs(path) { if filepath.IsAbs(path) {
return nil, fmt.Errorf("new root '%s' cannot be absolute", path) return nil, fmt.Errorf("new root '%s' cannot be absolute", path)
@@ -195,21 +190,23 @@ func (fl *fileLoader) New(path string) (ifc.Loader, error) {
return nil, err return nil, err
} }
return newLoaderAtConfirmedDir( return newLoaderAtConfirmedDir(
fl.loadRestrictor, fl.validator, root, fl.fSys, fl, fl.cloner), nil fl.loadRestrictor, root, fl.fSys, fl, fl.cloner), nil
} }
// newLoaderAtGitClone returns a new Loader pinned to a temporary // newLoaderAtGitClone returns a new Loader pinned to a temporary
// directory holding a cloned git repo. // directory holding a cloned git repo.
func newLoaderAtGitClone( func newLoaderAtGitClone(
repoSpec *git.RepoSpec, repoSpec *git.RepoSpec, fSys filesys.FileSystem,
v ifc.Validator, fSys fs.FileSystem,
referrer *fileLoader, cloner git.Cloner) (ifc.Loader, error) { referrer *fileLoader, cloner git.Cloner) (ifc.Loader, error) {
cleaner := repoSpec.Cleaner(fSys)
err := cloner(repoSpec) err := cloner(repoSpec)
if err != nil { if err != nil {
cleaner()
return nil, err return nil, err
} }
root, f, err := fSys.CleanedAbs(repoSpec.AbsPath()) root, f, err := fSys.CleanedAbs(repoSpec.AbsPath())
if err != nil { if err != nil {
cleaner()
return nil, err return nil, err
} }
// We don't know that the path requested in repoSpec // We don't know that the path requested in repoSpec
@@ -217,6 +214,7 @@ func newLoaderAtGitClone(
// inside. That just happened, hence the error check // inside. That just happened, hence the error check
// is here. // is here.
if f != "" { if f != "" {
cleaner()
return nil, fmt.Errorf( return nil, fmt.Errorf(
"'%s' refers to file '%s'; expecting directory", "'%s' refers to file '%s'; expecting directory",
repoSpec.AbsPath(), f) repoSpec.AbsPath(), f)
@@ -224,18 +222,17 @@ func newLoaderAtGitClone(
return &fileLoader{ return &fileLoader{
// Clones never allowed to escape root. // Clones never allowed to escape root.
loadRestrictor: RestrictionRootOnly, loadRestrictor: RestrictionRootOnly,
validator: v,
root: root, root: root,
referrer: referrer, referrer: referrer,
repoSpec: repoSpec, repoSpec: repoSpec,
fSys: fSys, fSys: fSys,
cloner: cloner, cloner: cloner,
cleaner: repoSpec.Cleaner(fSys), cleaner: cleaner,
}, nil }, nil
} }
func (fl *fileLoader) errIfGitContainmentViolation( func (fl *fileLoader) errIfGitContainmentViolation(
base fs.ConfirmedDir) error { base filesys.ConfirmedDir) error {
containingRepo := fl.containingRepo() containingRepo := fl.containingRepo()
if containingRepo == nil { if containingRepo == nil {
return nil return nil
@@ -265,7 +262,7 @@ func (fl *fileLoader) containingRepo() *git.RepoSpec {
// errIfArgEqualOrHigher tests whether the argument, // errIfArgEqualOrHigher tests whether the argument,
// is equal to or above the root of any ancestor. // is equal to or above the root of any ancestor.
func (fl *fileLoader) errIfArgEqualOrHigher( func (fl *fileLoader) errIfArgEqualOrHigher(
candidateRoot fs.ConfirmedDir) error { candidateRoot filesys.ConfirmedDir) error {
if fl.root.HasPrefix(candidateRoot) { if fl.root.HasPrefix(candidateRoot) {
return fmt.Errorf( return fmt.Errorf(
"cycle detected: candidate root '%s' contains visited root '%s'", "cycle detected: candidate root '%s' contains visited root '%s'",

View File

@@ -1,18 +1,5 @@
/* /// Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
package loader package loader
@@ -25,11 +12,10 @@ import (
"strings" "strings"
"testing" "testing"
"sigs.k8s.io/kustomize/v3/pkg/fs" "sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/v3/pkg/git" "sigs.k8s.io/kustomize/api/git"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig" "sigs.k8s.io/kustomize/api/pgmconfig"
"sigs.k8s.io/kustomize/v3/pkg/validators"
) )
type testData struct { type testData struct {
@@ -56,8 +42,8 @@ var testCases = []testData{
}, },
} }
func MakeFakeFs(td []testData) fs.FileSystem { func MakeFakeFs(td []testData) filesys.FileSystem {
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
for _, x := range td { for _, x := range td {
fSys.WriteFile("/"+x.path, []byte(x.expectedContent)) fSys.WriteFile("/"+x.path, []byte(x.expectedContent))
} }
@@ -65,7 +51,7 @@ func MakeFakeFs(td []testData) fs.FileSystem {
} }
func makeLoader() *fileLoader { func makeLoader() *fileLoader {
return NewFileLoaderAtRoot(validators.MakeFakeValidator(), MakeFakeFs(testCases)) return NewFileLoaderAtRoot(MakeFakeFs(testCases))
} }
func TestLoaderLoad(t *testing.T) { func TestLoaderLoad(t *testing.T) {
@@ -225,12 +211,12 @@ const (
// │ └── symLinkToExteriorData -> ../exteriorData // │ └── symLinkToExteriorData -> ../exteriorData
// └── exteriorData // └── exteriorData
// //
func commonSetupForLoaderRestrictionTest() (string, fs.FileSystem, error) { func commonSetupForLoaderRestrictionTest() (string, filesys.FileSystem, error) {
dir, err := ioutil.TempDir("", "kustomize-test-") dir, err := ioutil.TempDir("", "kustomize-test-")
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
fSys := fs.MakeFsOnDisk() fSys := filesys.MakeFsOnDisk()
fSys.Mkdir(filepath.Join(dir, "base")) fSys.Mkdir(filepath.Join(dir, "base"))
fSys.WriteFile( fSys.WriteFile(
@@ -302,8 +288,7 @@ func TestRestrictionRootOnlyInRealLoader(t *testing.T) {
var l ifc.Loader var l ifc.Loader
l = newLoaderOrDie( l = newLoaderOrDie(RestrictionRootOnly, fSys, dir)
RestrictionRootOnly, validators.MakeFakeValidator(), fSys, dir)
l = doSanityChecksAndDropIntoBase(t, l) l = doSanityChecksAndDropIntoBase(t, l)
@@ -336,8 +321,7 @@ func TestRestrictionNoneInRealLoader(t *testing.T) {
var l ifc.Loader var l ifc.Loader
l = newLoaderOrDie( l = newLoaderOrDie(RestrictionNone, fSys, dir)
RestrictionNone, validators.MakeFakeValidator(), fSys, dir)
l = doSanityChecksAndDropIntoBase(t, l) l = doSanityChecksAndDropIntoBase(t, l)
@@ -385,7 +369,7 @@ func TestNewLoaderAtGitClone(t *testing.T) {
pathInRepo := "foo/base" pathInRepo := "foo/base"
url := rootUrl + "/" + pathInRepo url := rootUrl + "/" + pathInRepo
coRoot := "/tmp" coRoot := "/tmp"
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(coRoot) fSys.MkdirAll(coRoot)
fSys.MkdirAll(coRoot + "/" + pathInRepo) fSys.MkdirAll(coRoot + "/" + pathInRepo)
fSys.WriteFile( fSys.WriteFile(
@@ -400,8 +384,8 @@ whatever
t.Fatalf("unexpected err: %v\n", err) t.Fatalf("unexpected err: %v\n", err)
} }
l, err := newLoaderAtGitClone( l, err := newLoaderAtGitClone(
repoSpec, validators.MakeFakeValidator(), fSys, nil, repoSpec, fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(coRoot))) git.DoNothingCloner(filesys.ConfirmedDir(coRoot)))
if err != nil { if err != nil {
t.Fatalf("unexpected err: %v\n", err) t.Fatalf("unexpected err: %v\n", err)
} }
@@ -433,7 +417,7 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
// Define an overlay-base structure in the file system. // Define an overlay-base structure in the file system.
topDir := "/whatever" topDir := "/whatever"
cloneRoot := topDir + "/someClone" cloneRoot := topDir + "/someClone"
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(topDir + "/highBase") fSys.MkdirAll(topDir + "/highBase")
fSys.MkdirAll(cloneRoot + "/foo/base") fSys.MkdirAll(cloneRoot + "/foo/base")
fSys.MkdirAll(cloneRoot + "/foo/overlay") fSys.MkdirAll(cloneRoot + "/foo/overlay")
@@ -443,7 +427,7 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
// Establish that a local overlay can navigate // Establish that a local overlay can navigate
// to the local bases. // to the local bases.
l1 = newLoaderOrDie( l1 = newLoaderOrDie(
RestrictionRootOnly, validators.MakeFakeValidator(), fSys, cloneRoot+"/foo/overlay") RestrictionRootOnly, fSys, cloneRoot+"/foo/overlay")
if l1.Root() != cloneRoot+"/foo/overlay" { if l1.Root() != cloneRoot+"/foo/overlay" {
t.Fatalf("unexpected root %s", l1.Root()) t.Fatalf("unexpected root %s", l1.Root())
} }
@@ -479,8 +463,8 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
t.Fatalf("unexpected err: %v\n", err) t.Fatalf("unexpected err: %v\n", err)
} }
l1, err = newLoaderAtGitClone( l1, err = newLoaderAtGitClone(
repoSpec, validators.MakeFakeValidator(), fSys, nil, repoSpec, fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(cloneRoot))) git.DoNothingCloner(filesys.ConfirmedDir(cloneRoot)))
if err != nil { if err != nil {
t.Fatalf("unexpected err: %v\n", err) t.Fatalf("unexpected err: %v\n", err)
} }
@@ -509,7 +493,7 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
func TestLocalLoaderReferencingGitBase(t *testing.T) { func TestLocalLoaderReferencingGitBase(t *testing.T) {
topDir := "/whatever" topDir := "/whatever"
cloneRoot := topDir + "/someClone" cloneRoot := topDir + "/someClone"
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(topDir) fSys.MkdirAll(topDir)
fSys.MkdirAll(cloneRoot + "/foo/base") fSys.MkdirAll(cloneRoot + "/foo/base")
@@ -518,8 +502,8 @@ func TestLocalLoaderReferencingGitBase(t *testing.T) {
t.Fatalf("unexpected err: %v\n", err) t.Fatalf("unexpected err: %v\n", err)
} }
l1 := newLoaderAtConfirmedDir( l1 := newLoaderAtConfirmedDir(
RestrictionRootOnly, validators.MakeFakeValidator(), root, fSys, nil, RestrictionRootOnly, root, fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(cloneRoot))) git.DoNothingCloner(filesys.ConfirmedDir(cloneRoot)))
if l1.Root() != topDir { if l1.Root() != topDir {
t.Fatalf("unexpected root %s", l1.Root()) t.Fatalf("unexpected root %s", l1.Root())
} }
@@ -535,7 +519,7 @@ func TestLocalLoaderReferencingGitBase(t *testing.T) {
func TestRepoDirectCycleDetection(t *testing.T) { func TestRepoDirectCycleDetection(t *testing.T) {
topDir := "/cycles" topDir := "/cycles"
cloneRoot := topDir + "/someClone" cloneRoot := topDir + "/someClone"
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(topDir) fSys.MkdirAll(topDir)
fSys.MkdirAll(cloneRoot) fSys.MkdirAll(cloneRoot)
@@ -544,8 +528,8 @@ func TestRepoDirectCycleDetection(t *testing.T) {
t.Fatalf("unexpected err: %v\n", err) t.Fatalf("unexpected err: %v\n", err)
} }
l1 := newLoaderAtConfirmedDir( l1 := newLoaderAtConfirmedDir(
RestrictionRootOnly, validators.MakeFakeValidator(), root, fSys, nil, RestrictionRootOnly, root, fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(cloneRoot))) git.DoNothingCloner(filesys.ConfirmedDir(cloneRoot)))
p1 := "github.com/someOrg/someRepo/foo" p1 := "github.com/someOrg/someRepo/foo"
rs1, err := git.NewRepoSpecFromUrl(p1) rs1, err := git.NewRepoSpecFromUrl(p1)
if err != nil { if err != nil {
@@ -564,7 +548,7 @@ func TestRepoDirectCycleDetection(t *testing.T) {
func TestRepoIndirectCycleDetection(t *testing.T) { func TestRepoIndirectCycleDetection(t *testing.T) {
topDir := "/cycles" topDir := "/cycles"
cloneRoot := topDir + "/someClone" cloneRoot := topDir + "/someClone"
fSys := fs.MakeFsInMemory() fSys := filesys.MakeFsInMemory()
fSys.MkdirAll(topDir) fSys.MkdirAll(topDir)
fSys.MkdirAll(cloneRoot) fSys.MkdirAll(cloneRoot)
@@ -573,8 +557,8 @@ func TestRepoIndirectCycleDetection(t *testing.T) {
t.Fatalf("unexpected err: %v", err) t.Fatalf("unexpected err: %v", err)
} }
l0 := newLoaderAtConfirmedDir( l0 := newLoaderAtConfirmedDir(
RestrictionRootOnly, validators.MakeFakeValidator(), root, fSys, nil, RestrictionRootOnly, root, fSys, nil,
git.DoNothingCloner(fs.ConfirmedDir(cloneRoot))) git.DoNothingCloner(filesys.ConfirmedDir(cloneRoot)))
p1 := "github.com/someOrg/someRepo1" p1 := "github.com/someOrg/someRepo1"
p2 := "github.com/someOrg/someRepo2" p2 := "github.com/someOrg/someRepo2"

34
api/loader/loader.go Normal file
View File

@@ -0,0 +1,34 @@
// 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/api/filesys"
"sigs.k8s.io/kustomize/api/git"
"sigs.k8s.io/kustomize/api/ifc"
)
// NewLoader returns a Loader pointed at the given target.
// If the target is remote, the loader will be restricted
// to the root and below only. If the target is local, the
// loader will have the restrictions passed in. Regardless,
// if a local target attempts to transitively load remote bases,
// the remote bases will all be root-only restricted.
func NewLoader(
lr LoadRestrictorFunc,
target string, fSys filesys.FileSystem) (ifc.Loader, error) {
repoSpec, err := git.NewRepoSpecFromUrl(target)
if err == nil {
// The target qualifies as a remote git target.
return newLoaderAtGitClone(
repoSpec, fSys, nil, git.ClonerUsingGitExec)
}
root, err := demandDirectoryRoot(fSys, target)
if err != nil {
return nil, err
}
return newLoaderAtConfirmedDir(
lr, root, fSys, nil, git.ClonerUsingGitExec), nil
}

View File

@@ -1,18 +1,5 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
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.
*/
package loader package loader
@@ -20,7 +7,7 @@ import (
"fmt" "fmt"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"sigs.k8s.io/kustomize/v3/pkg/fs" "sigs.k8s.io/kustomize/api/filesys"
) )
//go:generate stringer -type=loadRestrictions //go:generate stringer -type=loadRestrictions
@@ -64,10 +51,10 @@ func ValidateFlagLoadRestrictor() (LoadRestrictorFunc, error) {
} }
type LoadRestrictorFunc func( type LoadRestrictorFunc func(
fs.FileSystem, fs.ConfirmedDir, string) (string, error) filesys.FileSystem, filesys.ConfirmedDir, string) (string, error)
func RestrictionRootOnly( 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) d, f, err := fSys.CleanedAbs(path)
if err != nil { if err != nil {
return "", err return "", err
@@ -84,6 +71,6 @@ func RestrictionRootOnly(
} }
func RestrictionNone( func RestrictionNone(
_ fs.FileSystem, _ fs.ConfirmedDir, path string) (string, error) { _ filesys.FileSystem, _ filesys.ConfirmedDir, path string) (string, error) {
return path, nil return path, nil
} }

View File

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

View File

@@ -8,7 +8,7 @@ import (
"fmt" "fmt"
"os" "os"
"sigs.k8s.io/kustomize/v3/provenance" "sigs.k8s.io/kustomize/api/provenance"
) )
// TODO: delete this when we find a better way to generate release notes. // TODO: delete this when we find a better way to generate release notes.

View File

@@ -1,7 +1,6 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// Package pgmconfig holds global constants for the kustomize tool.
package pgmconfig package pgmconfig
// RecognizedKustomizationFileNames is a list of file names // RecognizedKustomizationFileNames is a list of file names
@@ -32,14 +31,11 @@ const (
// Program name, for help, finding the XDG_CONFIG_DIR, etc. // Program name, for help, finding the XDG_CONFIG_DIR, etc.
ProgramName = "kustomize" ProgramName = "kustomize"
// Domain from which kustomize code is imported, for locating // TODO: delete this. it's a copy of a const
// plugin source code under $GOPATH. // defined elsewhere but used by pluginator.
// TODO: move to pgk/plugin/config.go or equivalent
// as part of v4 release. Cannot move till then
// because of pluginator dependence at v3.
DomainName = "sigs.k8s.io" DomainName = "sigs.k8s.io"
// Name of directory housing all plugins. // TODO: delete this. its a copy of a const
// TODO: move to pgk/plugin/config.go or equivalent // defined elsewhere but used by pluginator.
PluginRoot = "plugin" PluginRoot = "plugin"
) )

View File

@@ -1,20 +1,7 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package consts
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.
*/
package defaultconfig
const commonAnnotationFieldSpecs = ` const commonAnnotationFieldSpecs = `
commonAnnotations: commonAnnotations:

View File

@@ -1,20 +1,7 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package consts
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.
*/
package defaultconfig
const commonLabelFieldSpecs = ` const commonLabelFieldSpecs = `
commonLabels: commonLabels:

View File

@@ -1,22 +1,7 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package consts
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.
*/
// Package defaultconfig provides the default
// transformer configurations
package defaultconfig
import ( import (
"bytes" "bytes"

View File

@@ -0,0 +1,5 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package consts provides builtin plugin configuration data.
package consts

View File

@@ -0,0 +1,10 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package consts
const (
// imageFieldSpecs is left empty since `containers` and `initContainers`
// of *ANY* kind in *ANY* path are builtin supported in code
imagesFieldSpecs = ``
)

View File

@@ -0,0 +1,11 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package consts
const (
namePrefixFieldSpecs = `
namePrefix:
- path: metadata/name
`
)

View File

@@ -1,20 +1,7 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package consts
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.
*/
package defaultconfig
const ( const (
nameReferenceFieldSpecs = ` nameReferenceFieldSpecs = `

View File

@@ -0,0 +1,16 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package consts
const (
namespaceFieldSpecs = `
namespace:
- path: metadata/namespace
create: true
- path: subjects
kind: RoleBinding
- path: subjects
kind: ClusterRoleBinding
`
)

View File

@@ -1,4 +1,7 @@
package defaultconfig // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package consts
const replicasFieldSpecs = ` const replicasFieldSpecs = `
replicas: replicas:

View File

@@ -1,20 +1,7 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package consts
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.
*/
package defaultconfig
const ( const (
varReferenceFieldSpecs = ` varReferenceFieldSpecs = `

View File

@@ -0,0 +1,10 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package builtinconfig provides legacy methods for
// configuring builtin plugins from a common config file.
// As a user, its best to configure plugins individually
// with plugin config files specified in the `transformers:`
// or `generators:` field, than to use this legacy
// configuration technique.
package builtinconfig

View File

@@ -0,0 +1,42 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package builtinconfig
import (
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/yaml"
)
// loadDefaultConfig returns a TranformerConfig
// object from a list of files.
func loadDefaultConfig(
ldr ifc.Loader, paths []string) (*TransformerConfig, error) {
result := &TransformerConfig{}
for _, path := range paths {
data, err := ldr.Load(path)
if err != nil {
return nil, err
}
t, err := makeTransformerConfigFromBytes(data)
if err != nil {
return nil, err
}
result, err = result.Merge(t)
if err != nil {
return nil, err
}
}
return result, nil
}
// makeTransformerConfigFromBytes returns a TransformerConfig object from bytes
func makeTransformerConfigFromBytes(data []byte) (*TransformerConfig, error) {
var t TransformerConfig
err := yaml.Unmarshal(data, &t)
if err != nil {
return nil, err
}
t.sortFields()
return &t, nil
}

View File

@@ -1,37 +1,32 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package config package builtinconfig
import ( import (
"reflect" "reflect"
"testing" "testing"
"sigs.k8s.io/kustomize/v3/internal/loadertest" "sigs.k8s.io/kustomize/api/internal/loadertest"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/types"
) )
func TestMakeDefaultConfig(t *testing.T) { func TestLoadDefaultConfigsFromFiles(t *testing.T) {
// Confirm default can be made without fatal error inside call.
_ = MakeDefaultConfig()
}
func TestFromFiles(t *testing.T) {
ldr := loadertest.NewFakeLoader("/app") ldr := loadertest.NewFakeLoader("/app")
ldr.AddFile("/app/config.yaml", []byte(` ldr.AddFile("/app/config.yaml", []byte(`
namePrefix: namePrefix:
- path: nameprefix/path - path: nameprefix/path
kind: SomeKind kind: SomeKind
`)) `))
tcfg, err := NewFactory(ldr).FromFiles([]string{"/app/config.yaml"}) tcfg, err := loadDefaultConfig(ldr, []string{"/app/config.yaml"})
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
expected := &TransformerConfig{ expected := &TransformerConfig{
NamePrefix: []FieldSpec{ NamePrefix: []types.FieldSpec{
{ {
Gvk: gvk.Gvk{Kind: "SomeKind"}, Gvk: resid.Gvk{Kind: "SomeKind"},
Path: "nameprefix/path", Path: "nameprefix/path",
}, },
}, },

View File

@@ -1,25 +1,13 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package builtinconfig
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.
*/
package config
import ( import (
"strings" "strings"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/types"
) )
// NameBackReferences is an association between a gvk.GVK and a list // NameBackReferences is an association between a gvk.GVK and a list
@@ -51,8 +39,8 @@ import (
// (etc.) // (etc.)
// } // }
type NameBackReferences struct { type NameBackReferences struct {
gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"` resid.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
FieldSpecs fsSlice `json:"FieldSpecs,omitempty" yaml:"FieldSpecs,omitempty"` FieldSpecs types.FsSlice `json:"FieldSpecs,omitempty" yaml:"FieldSpecs,omitempty"`
} }
func (n NameBackReferences) String() string { func (n NameBackReferences) String() string {
@@ -89,7 +77,7 @@ func (s nbrSlice) mergeOne(other NameBackReferences) (nbrSlice, error) {
found := false found := false
for _, c := range s { for _, c := range s {
if c.Gvk.Equals(other.Gvk) { if c.Gvk.Equals(other.Gvk) {
c.FieldSpecs, err = c.FieldSpecs.mergeAll(other.FieldSpecs) c.FieldSpecs, err = c.FieldSpecs.MergeAll(other.FieldSpecs)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -1,54 +1,43 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package builtinconfig
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.
*/
package config
import ( import (
"reflect" "reflect"
"sigs.k8s.io/kustomize/v3/pkg/gvk"
"testing" "testing"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/types"
) )
func TestMergeAll(t *testing.T) { func TestMergeAll(t *testing.T) {
fsSlice1 := []FieldSpec{ fsSlice1 := []types.FieldSpec{
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "Pod", Kind: "Pod",
}, },
Path: "path/to/a/name", Path: "path/to/a/name",
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: "another/path/to/some/name", Path: "another/path/to/some/name",
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
} }
fsSlice2 := []FieldSpec{ fsSlice2 := []types.FieldSpec{
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: "morepath/to/name", Path: "morepath/to/name",
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: "yet/another/path/to/a/name", Path: "yet/another/path/to/a/name",
@@ -58,13 +47,13 @@ func TestMergeAll(t *testing.T) {
nbrsSlice1 := nbrSlice{ nbrsSlice1 := nbrSlice{
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "ConfigMap", Kind: "ConfigMap",
}, },
FieldSpecs: fsSlice1, FieldSpecs: fsSlice1,
}, },
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "Secret", Kind: "Secret",
}, },
FieldSpecs: fsSlice2, FieldSpecs: fsSlice2,
@@ -72,13 +61,13 @@ func TestMergeAll(t *testing.T) {
} }
nbrsSlice2 := nbrSlice{ nbrsSlice2 := nbrSlice{
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "ConfigMap", Kind: "ConfigMap",
}, },
FieldSpecs: fsSlice1, FieldSpecs: fsSlice1,
}, },
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "Secret", Kind: "Secret",
}, },
FieldSpecs: fsSlice2, FieldSpecs: fsSlice2,
@@ -86,13 +75,13 @@ func TestMergeAll(t *testing.T) {
} }
expected := nbrSlice{ expected := nbrSlice{
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "ConfigMap", Kind: "ConfigMap",
}, },
FieldSpecs: fsSlice1, FieldSpecs: fsSlice1,
}, },
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "Secret", Kind: "Secret",
}, },
FieldSpecs: fsSlice2, FieldSpecs: fsSlice2,

View File

@@ -0,0 +1,148 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package builtinconfig
import (
"log"
"sort"
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/plugins/builtinconfig/consts"
"sigs.k8s.io/kustomize/api/types"
)
// TransformerConfig holds the data needed to perform transformations.
type TransformerConfig struct {
NamePrefix types.FsSlice `json:"namePrefix,omitempty" yaml:"namePrefix,omitempty"`
NameSuffix types.FsSlice `json:"nameSuffix,omitempty" yaml:"nameSuffix,omitempty"`
NameSpace types.FsSlice `json:"namespace,omitempty" yaml:"namespace,omitempty"`
CommonLabels types.FsSlice `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"`
CommonAnnotations types.FsSlice `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"`
NameReference nbrSlice `json:"nameReference,omitempty" yaml:"nameReference,omitempty"`
VarReference types.FsSlice `json:"varReference,omitempty" yaml:"varReference,omitempty"`
Images types.FsSlice `json:"images,omitempty" yaml:"images,omitempty"`
Replicas types.FsSlice `json:"replicas,omitempty" yaml:"replicas,omitempty"`
}
// MakeEmptyConfig returns an empty TransformerConfig object
func MakeEmptyConfig() *TransformerConfig {
return &TransformerConfig{}
}
// MakeDefaultConfig returns a default TransformerConfig.
func MakeDefaultConfig() *TransformerConfig {
c, err := makeTransformerConfigFromBytes(
consts.GetDefaultFieldSpecs())
if err != nil {
log.Fatalf("Unable to make default transformconfig: %v", err)
}
return c
}
// MakeTransformerConfig returns a merger of custom config,
// if any, with default config.
func MakeTransformerConfig(
ldr ifc.Loader, paths []string) (*TransformerConfig, error) {
t1 := MakeDefaultConfig()
if len(paths) == 0 {
return t1, nil
}
t2, err := loadDefaultConfig(ldr, paths)
if err != nil {
return nil, err
}
return t1.Merge(t2)
}
// sortFields provides determinism in logging, tests, etc.
func (t *TransformerConfig) sortFields() {
sort.Sort(t.NamePrefix)
sort.Sort(t.NameSpace)
sort.Sort(t.CommonLabels)
sort.Sort(t.CommonAnnotations)
sort.Sort(t.NameReference)
sort.Sort(t.VarReference)
sort.Sort(t.Images)
sort.Sort(t.Replicas)
}
// AddPrefixFieldSpec adds a FieldSpec to NamePrefix
func (t *TransformerConfig) AddPrefixFieldSpec(fs types.FieldSpec) (err error) {
t.NamePrefix, err = t.NamePrefix.MergeOne(fs)
return err
}
// AddSuffixFieldSpec adds a FieldSpec to NameSuffix
func (t *TransformerConfig) AddSuffixFieldSpec(fs types.FieldSpec) (err error) {
t.NameSuffix, err = t.NameSuffix.MergeOne(fs)
return err
}
// AddLabelFieldSpec adds a FieldSpec to CommonLabels
func (t *TransformerConfig) AddLabelFieldSpec(fs types.FieldSpec) (err error) {
t.CommonLabels, err = t.CommonLabels.MergeOne(fs)
return err
}
// AddAnnotationFieldSpec adds a FieldSpec to CommonAnnotations
func (t *TransformerConfig) AddAnnotationFieldSpec(fs types.FieldSpec) (err error) {
t.CommonAnnotations, err = t.CommonAnnotations.MergeOne(fs)
return err
}
// AddNamereferenceFieldSpec adds a NameBackReferences to NameReference
func (t *TransformerConfig) AddNamereferenceFieldSpec(
nbrs NameBackReferences) (err error) {
t.NameReference, err = t.NameReference.mergeOne(nbrs)
return err
}
// Merge merges two TransformerConfigs objects into
// a new TransformerConfig object
func (t *TransformerConfig) Merge(input *TransformerConfig) (
merged *TransformerConfig, err error) {
if input == nil {
return t, nil
}
merged = &TransformerConfig{}
merged.NamePrefix, err = t.NamePrefix.MergeAll(input.NamePrefix)
if err != nil {
return nil, err
}
merged.NameSuffix, err = t.NameSuffix.MergeAll(input.NameSuffix)
if err != nil {
return nil, err
}
merged.NameSpace, err = t.NameSpace.MergeAll(input.NameSpace)
if err != nil {
return nil, err
}
merged.CommonAnnotations, err = t.CommonAnnotations.MergeAll(
input.CommonAnnotations)
if err != nil {
return nil, err
}
merged.CommonLabels, err = t.CommonLabels.MergeAll(input.CommonLabels)
if err != nil {
return nil, err
}
merged.VarReference, err = t.VarReference.MergeAll(input.VarReference)
if err != nil {
return nil, err
}
merged.NameReference, err = t.NameReference.mergeAll(input.NameReference)
if err != nil {
return nil, err
}
merged.Images, err = t.Images.MergeAll(input.Images)
if err != nil {
return nil, err
}
merged.Replicas, err = t.Replicas.MergeAll(input.Replicas)
if err != nil {
return nil, err
}
merged.sortFields()
return merged, nil
}

View File

@@ -1,39 +1,32 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2018 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package builtinconfig_test
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.
*/
package config
import ( import (
"reflect"
"testing" "testing"
"reflect" . "sigs.k8s.io/kustomize/api/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/types"
) )
func TestMakeDefaultConfig(t *testing.T) {
// Confirm default can be made without fatal error inside call.
_ = MakeDefaultConfig()
}
func TestAddNamereferenceFieldSpec(t *testing.T) { func TestAddNamereferenceFieldSpec(t *testing.T) {
cfg := &TransformerConfig{} cfg := &TransformerConfig{}
nbrs := NameBackReferences{ nbrs := NameBackReferences{
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "KindA", Kind: "KindA",
}, },
FieldSpecs: []FieldSpec{ FieldSpecs: []types.FieldSpec{
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "KindB", Kind: "KindB",
}, },
Path: "path/to/a/field", Path: "path/to/a/field",
@@ -54,8 +47,8 @@ func TestAddNamereferenceFieldSpec(t *testing.T) {
func TestAddFieldSpecs(t *testing.T) { func TestAddFieldSpecs(t *testing.T) {
cfg := &TransformerConfig{} cfg := &TransformerConfig{}
fieldSpec := FieldSpec{ fieldSpec := types.FieldSpec{
Gvk: gvk.Gvk{Group: "GroupA", Kind: "KindB"}, Gvk: resid.Gvk{Group: "GroupA", Kind: "KindB"},
Path: "path/to/a/field", Path: "path/to/a/field",
CreateIfNotPresent: true, CreateIfNotPresent: true,
} }
@@ -93,12 +86,12 @@ func TestAddFieldSpecs(t *testing.T) {
func TestMerge(t *testing.T) { func TestMerge(t *testing.T) {
nameReference := []NameBackReferences{ nameReference := []NameBackReferences{
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "KindA", Kind: "KindA",
}, },
FieldSpecs: []FieldSpec{ FieldSpecs: []types.FieldSpec{
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "KindB", Kind: "KindB",
}, },
Path: "path/to/a/field", Path: "path/to/a/field",
@@ -107,12 +100,12 @@ func TestMerge(t *testing.T) {
}, },
}, },
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "KindA", Kind: "KindA",
}, },
FieldSpecs: []FieldSpec{ FieldSpecs: []types.FieldSpec{
{ {
Gvk: gvk.Gvk{ Gvk: resid.Gvk{
Kind: "KindC", Kind: "KindC",
}, },
Path: "path/to/a/field", Path: "path/to/a/field",
@@ -121,14 +114,14 @@ func TestMerge(t *testing.T) {
}, },
}, },
} }
fieldSpecs := []FieldSpec{ fieldSpecs := []types.FieldSpec{
{ {
Gvk: gvk.Gvk{Group: "GroupA", Kind: "KindB"}, Gvk: resid.Gvk{Group: "GroupA", Kind: "KindB"},
Path: "path/to/a/field", Path: "path/to/a/field",
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
Gvk: gvk.Gvk{Group: "GroupA", Kind: "KindC"}, Gvk: resid.Gvk{Group: "GroupA", Kind: "KindC"},
Path: "path/to/a/field", Path: "path/to/a/field",
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },

View File

@@ -0,0 +1,37 @@
// Code generated by "stringer -type=BuiltinPluginType"; DO NOT EDIT.
package builtinhelpers
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[Unknown-0]
_ = x[AnnotationsTransformer-1]
_ = x[ConfigMapGenerator-2]
_ = x[HashTransformer-3]
_ = x[ImageTagTransformer-4]
_ = x[InventoryTransformer-5]
_ = x[LabelTransformer-6]
_ = x[LegacyOrderTransformer-7]
_ = x[NamespaceTransformer-8]
_ = x[PatchJson6902Transformer-9]
_ = x[PatchStrategicMergeTransformer-10]
_ = x[PatchTransformer-11]
_ = x[PrefixSuffixTransformer-12]
_ = x[ReplicaCountTransformer-13]
_ = x[SecretGenerator-14]
}
const _BuiltinPluginType_name = "UnknownAnnotationsTransformerConfigMapGeneratorHashTransformerImageTagTransformerInventoryTransformerLabelTransformerLegacyOrderTransformerNamespaceTransformerPatchJson6902TransformerPatchStrategicMergeTransformerPatchTransformerPrefixSuffixTransformerReplicaCountTransformerSecretGenerator"
var _BuiltinPluginType_index = [...]uint16{0, 7, 29, 47, 62, 81, 101, 117, 139, 159, 183, 213, 229, 252, 275, 290}
func (i BuiltinPluginType) String() string {
if i < 0 || i >= BuiltinPluginType(len(_BuiltinPluginType_index)-1) {
return "BuiltinPluginType(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _BuiltinPluginType_name[_BuiltinPluginType_index[i]:_BuiltinPluginType_index[i+1]]
}

View File

@@ -1,11 +1,11 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package plugins package builtinhelpers
import ( import (
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/plugins/builtins"
"sigs.k8s.io/kustomize/v3/plugin/builtin" "sigs.k8s.io/kustomize/api/resmap"
) )
//go:generate stringer -type=BuiltinPluginType //go:generate stringer -type=BuiltinPluginType
@@ -13,20 +13,20 @@ type BuiltinPluginType int
const ( const (
Unknown BuiltinPluginType = iota Unknown BuiltinPluginType = iota
SecretGenerator AnnotationsTransformer
ConfigMapGenerator ConfigMapGenerator
ReplicaCountTransformer HashTransformer
ImageTagTransformer
InventoryTransformer
LabelTransformer
LegacyOrderTransformer
NamespaceTransformer NamespaceTransformer
PatchJson6902Transformer PatchJson6902Transformer
PatchStrategicMergeTransformer PatchStrategicMergeTransformer
PatchTransformer PatchTransformer
LabelTransformer
AnnotationsTransformer
PrefixSuffixTransformer PrefixSuffixTransformer
ImageTagTransformer ReplicaCountTransformer
HashTransformer SecretGenerator
InventoryTransformer
LegacyOrderTransformer
) )
var stringToBuiltinPluginTypeMap map[string]BuiltinPluginType var stringToBuiltinPluginTypeMap map[string]BuiltinPluginType
@@ -55,21 +55,21 @@ func GetBuiltinPluginType(n string) BuiltinPluginType {
} }
var GeneratorFactories = map[BuiltinPluginType]func() resmap.GeneratorPlugin{ var GeneratorFactories = map[BuiltinPluginType]func() resmap.GeneratorPlugin{
SecretGenerator: builtin.NewSecretGeneratorPlugin, ConfigMapGenerator: builtins.NewConfigMapGeneratorPlugin,
ConfigMapGenerator: builtin.NewConfigMapGeneratorPlugin, SecretGenerator: builtins.NewSecretGeneratorPlugin,
} }
var TransformerFactories = map[BuiltinPluginType]func() resmap.TransformerPlugin{ var TransformerFactories = map[BuiltinPluginType]func() resmap.TransformerPlugin{
NamespaceTransformer: builtin.NewNamespaceTransformerPlugin, AnnotationsTransformer: builtins.NewAnnotationsTransformerPlugin,
ReplicaCountTransformer: builtin.NewReplicaCountTransformerPlugin, HashTransformer: builtins.NewHashTransformerPlugin,
PatchJson6902Transformer: builtin.NewPatchJson6902TransformerPlugin, ImageTagTransformer: builtins.NewImageTagTransformerPlugin,
PatchStrategicMergeTransformer: builtin.NewPatchStrategicMergeTransformerPlugin, InventoryTransformer: builtins.NewInventoryTransformerPlugin,
PatchTransformer: builtin.NewPatchTransformerPlugin, LabelTransformer: builtins.NewLabelTransformerPlugin,
LabelTransformer: builtin.NewLabelTransformerPlugin, LegacyOrderTransformer: builtins.NewLegacyOrderTransformerPlugin,
AnnotationsTransformer: builtin.NewAnnotationsTransformerPlugin, NamespaceTransformer: builtins.NewNamespaceTransformerPlugin,
PrefixSuffixTransformer: builtin.NewPrefixSuffixTransformerPlugin, PatchJson6902Transformer: builtins.NewPatchJson6902TransformerPlugin,
ImageTagTransformer: builtin.NewImageTagTransformerPlugin, PatchStrategicMergeTransformer: builtins.NewPatchStrategicMergeTransformerPlugin,
HashTransformer: builtin.NewHashTransformerPlugin, PatchTransformer: builtins.NewPatchTransformerPlugin,
InventoryTransformer: builtin.NewInventoryTransformerPlugin, PrefixSuffixTransformer: builtins.NewPrefixSuffixTransformerPlugin,
LegacyOrderTransformer: builtin.NewLegacyOrderTransformerPlugin, ReplicaCountTransformer: builtins.NewReplicaCountTransformerPlugin,
} }

View File

@@ -3,10 +3,11 @@
# Generate the Go code for the generator and # Generate the Go code for the generator and
# transformer factory functions in # transformer factory functions in
# #
# sigs.k8s.io/kustomize/v3/plugin/builtin # sigs.k8s.io/kustomize/api/plugins/builtins
# #
# from the raw plugin directories found _below_ # from the raw plugin directories found under
# that directory. #
# sigs.k8s.io/kustomize/plugin/builtin
set -e set -e
@@ -27,15 +28,11 @@ if [ ! -d "$dir" ]; then
exit 1 exit 1
fi fi
echo Generating linkable plugins... for goMod in $(find ./plugin/builtin -name 'go.mod'); do
dir=$(dirname "${goMod}")
pushd $dir >& /dev/null (cd $dir; GOPATH=$myGoPath go generate ./...)
echo "Formatting $dir"
GOPATH=$myGoPath go generate \ (cd $dir; GOPATH=$myGoPath go fmt ./...)
sigs.k8s.io/kustomize/v3/plugin/builtin/... done
GOPATH=$myGoPath go fmt \
sigs.k8s.io/kustomize/v3/plugin/builtin
popd >& /dev/null
echo All done. echo All done.

View File

@@ -1,29 +1,33 @@
// Code generated by pluginator on AnnotationsTransformer; DO NOT EDIT. // Code generated by pluginator on AnnotationsTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/transform"
"sigs.k8s.io/kustomize/v3/pkg/transformers" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
// Add the given annotations to the given field specifications. // Add the given annotations to the given field specifications.
type AnnotationsTransformerPlugin struct { type AnnotationsTransformerPlugin struct {
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"` Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"` FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
} }
func (p *AnnotationsTransformerPlugin) Config( func (p *AnnotationsTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
p.Annotations = nil p.Annotations = nil
p.FieldSpecs = nil p.FieldSpecs = nil
return yaml.Unmarshal(c, p) return yaml.Unmarshal(c, p)
} }
func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error { func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error {
t, err := transformers.NewMapTransformer( t, err := transform.NewMapTransformer(
p.FieldSpecs, p.FieldSpecs,
p.Annotations, p.Annotations,
) )
@@ -34,5 +38,5 @@ func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error {
} }
func NewAnnotationsTransformerPlugin() resmap.TransformerPlugin { func NewAnnotationsTransformerPlugin() resmap.TransformerPlugin {
return &AnnotationsTransformerPlugin{} return &AnnotationsTransformerPlugin{}
} }

View File

@@ -1,23 +1,27 @@
// Code generated by pluginator on ConfigMapGenerator; DO NOT EDIT. // Code generated by pluginator on ConfigMapGenerator; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/kv"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
type ConfigMapGeneratorPlugin struct { type ConfigMapGeneratorPlugin struct {
ldr ifc.Loader h *resmap.PluginHelpers
rf *resmap.Factory
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
types.GeneratorOptions types.GeneratorOptions
types.ConfigMapArgs types.ConfigMapArgs
} }
func (p *ConfigMapGeneratorPlugin) Config( func (p *ConfigMapGeneratorPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, config []byte) (err error) { h *resmap.PluginHelpers, config []byte) (err error) {
p.GeneratorOptions = types.GeneratorOptions{} p.GeneratorOptions = types.GeneratorOptions{}
p.ConfigMapArgs = types.ConfigMapArgs{} p.ConfigMapArgs = types.ConfigMapArgs{}
err = yaml.Unmarshal(config, p) err = yaml.Unmarshal(config, p)
@@ -27,15 +31,16 @@ func (p *ConfigMapGeneratorPlugin) Config(
if p.ConfigMapArgs.Namespace == "" { if p.ConfigMapArgs.Namespace == "" {
p.ConfigMapArgs.Namespace = p.Namespace p.ConfigMapArgs.Namespace = p.Namespace
} }
p.ldr = ldr p.h = h
p.rf = rf
return return
} }
func (p *ConfigMapGeneratorPlugin) Generate() (resmap.ResMap, error) { func (p *ConfigMapGeneratorPlugin) Generate() (resmap.ResMap, error) {
return p.rf.FromConfigMapArgs(p.ldr, &p.GeneratorOptions, p.ConfigMapArgs) return p.h.ResmapFactory().FromConfigMapArgs(
kv.NewLoader(p.h.Loader(), p.h.Validator()),
&p.GeneratorOptions, p.ConfigMapArgs)
} }
func NewConfigMapGeneratorPlugin() resmap.GeneratorPlugin { func NewConfigMapGeneratorPlugin() resmap.GeneratorPlugin {
return &ConfigMapGeneratorPlugin{} return &ConfigMapGeneratorPlugin{}
} }

View File

@@ -1,20 +1,25 @@
// Code generated by pluginator on HashTransformer; DO NOT EDIT. // Code generated by pluginator on HashTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"fmt" "fmt"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resmap"
) )
type HashTransformerPlugin struct { type HashTransformerPlugin struct {
hasher ifc.KunstructuredHasher hasher ifc.KunstructuredHasher
} }
func (p *HashTransformerPlugin) Config( func (p *HashTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, config []byte) (err error) { h *resmap.PluginHelpers, config []byte) (err error) {
p.hasher = rf.RF().Hasher() p.hasher = h.ResmapFactory().RF().Hasher()
return nil return nil
} }
@@ -33,5 +38,5 @@ func (p *HashTransformerPlugin) Transform(m resmap.ResMap) error {
} }
func NewHashTransformerPlugin() resmap.TransformerPlugin { func NewHashTransformerPlugin() resmap.TransformerPlugin {
return &HashTransformerPlugin{} return &HashTransformerPlugin{}
} }

View File

@@ -1,29 +1,33 @@
// Code generated by pluginator on ImageTagTransformer; DO NOT EDIT. // Code generated by pluginator on ImageTagTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"fmt" "fmt"
"regexp" "regexp"
"strings" "strings"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/transform"
"sigs.k8s.io/kustomize/v3/pkg/image" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
// Find matching image declarations and replace // Find matching image declarations and replace
// the name, tag and/or digest. // the name, tag and/or digest.
type ImageTagTransformerPlugin struct { type ImageTagTransformerPlugin struct {
ImageTag image.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"` ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"` FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
} }
func (p *ImageTagTransformerPlugin) Config( func (p *ImageTagTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
p.ImageTag = image.Image{} p.ImageTag = types.Image{}
p.FieldSpecs = nil p.FieldSpecs = nil
return yaml.Unmarshal(c, p) return yaml.Unmarshal(c, p)
} }
@@ -34,7 +38,7 @@ func (p *ImageTagTransformerPlugin) Transform(m resmap.ResMap) error {
if !r.OrgId().IsSelected(&path.Gvk) { if !r.OrgId().IsSelected(&path.Gvk) {
continue continue
} }
err := transformers.MutateField( err := transform.MutateField(
r.Map(), path.PathSlice(), false, p.mutateImage) r.Map(), path.PathSlice(), false, p.mutateImage)
if err != nil { if err != nil {
return err return err
@@ -180,5 +184,5 @@ func split(imageName string) (name string, tag string) {
} }
func NewImageTagTransformerPlugin() resmap.TransformerPlugin { func NewImageTagTransformerPlugin() resmap.TransformerPlugin {
return &ImageTagTransformerPlugin{} return &ImageTagTransformerPlugin{}
} }

View File

@@ -1,31 +1,33 @@
// Code generated by pluginator on InventoryTransformer; DO NOT EDIT. // Code generated by pluginator on InventoryTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"fmt" "fmt"
"sigs.k8s.io/kustomize/v3/pkg/resource" "sigs.k8s.io/kustomize/api/hasher"
"sigs.k8s.io/kustomize/api/inventory"
"sigs.k8s.io/kustomize/v3/pkg/hasher" "sigs.k8s.io/kustomize/api/kv"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/inventory" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resid" "sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/types"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
type InventoryTransformerPlugin struct { type InventoryTransformerPlugin struct {
ldr ifc.Loader h *resmap.PluginHelpers
rf *resmap.Factory
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Policy string `json:"policy,omitempty" yaml:"policy,omitempty"` Policy string `json:"policy,omitempty" yaml:"policy,omitempty"`
} }
func (p *InventoryTransformerPlugin) Config( func (p *InventoryTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
p.ldr = ldr p.h = h
p.rf = rf
err = yaml.Unmarshal(c, p) err = yaml.Unmarshal(c, p)
if err != nil { if err != nil {
return err return err
@@ -74,7 +76,8 @@ func (p *InventoryTransformerPlugin) Transform(m resmap.ResMap) error {
return err return err
} }
cm, err := p.rf.RF().MakeConfigMap(p.ldr, opts, &args) cm, err := p.h.ResmapFactory().RF().MakeConfigMap(
kv.NewLoader(p.h.Loader(), p.h.Validator()), opts, &args)
if err != nil { if err != nil {
return err return err
} }
@@ -124,5 +127,5 @@ func computeRefs(
} }
func NewInventoryTransformerPlugin() resmap.TransformerPlugin { func NewInventoryTransformerPlugin() resmap.TransformerPlugin {
return &InventoryTransformerPlugin{} return &InventoryTransformerPlugin{}
} }

View File

@@ -0,0 +1,42 @@
// Code generated by pluginator on LabelTransformer; DO NOT EDIT.
// pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import (
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/transform"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/yaml"
)
// Add the given labels to the given field specifications.
type LabelTransformerPlugin struct {
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
func (p *LabelTransformerPlugin) Config(
h *resmap.PluginHelpers, c []byte) (err error) {
p.Labels = nil
p.FieldSpecs = nil
return yaml.Unmarshal(c, p)
}
func (p *LabelTransformerPlugin) Transform(m resmap.ResMap) error {
t, err := transform.NewMapTransformer(
p.FieldSpecs,
p.Labels,
)
if err != nil {
return err
}
return t.Transform(m)
}
func NewLabelTransformerPlugin() resmap.TransformerPlugin {
return &LabelTransformerPlugin{}
}

View File

@@ -1,13 +1,16 @@
// Code generated by pluginator on LegacyOrderTransformer; DO NOT EDIT. // Code generated by pluginator on LegacyOrderTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"sort" "sort"
"github.com/pkg/errors" "github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/v3/pkg/resource"
) )
// Sort the resources using an ordering defined in the Gvk class. // Sort the resources using an ordering defined in the Gvk class.
@@ -17,9 +20,10 @@ import (
// (like ValidatingWebhookConfiguration) last. // (like ValidatingWebhookConfiguration) last.
type LegacyOrderTransformerPlugin struct{} type LegacyOrderTransformerPlugin struct{}
// Nothing needed for configuration. // Nothing needed for configuration.
func (p *LegacyOrderTransformerPlugin) Config( func (p *LegacyOrderTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
return nil return nil
} }
@@ -41,5 +45,5 @@ func (p *LegacyOrderTransformerPlugin) Transform(m resmap.ResMap) (err error) {
} }
func NewLegacyOrderTransformerPlugin() resmap.TransformerPlugin { func NewLegacyOrderTransformerPlugin() resmap.TransformerPlugin {
return &LegacyOrderTransformerPlugin{} return &LegacyOrderTransformerPlugin{}
} }

View File

@@ -1,27 +1,31 @@
// Code generated by pluginator on NamespaceTransformer; DO NOT EDIT. // Code generated by pluginator on NamespaceTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"fmt" "fmt"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/transform"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/resource" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers" "sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/types"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
// Change or set the namespace of non-cluster level resources. // Change or set the namespace of non-cluster level resources.
type NamespaceTransformerPlugin struct { type NamespaceTransformerPlugin struct {
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"` FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
} }
func (p *NamespaceTransformerPlugin) Config( func (p *NamespaceTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
p.Namespace = "" p.Namespace = ""
p.FieldSpecs = nil p.FieldSpecs = nil
return yaml.Unmarshal(c, p) return yaml.Unmarshal(c, p)
@@ -41,7 +45,7 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
applicableFs := p.applicableFieldSpecs(id) applicableFs := p.applicableFieldSpecs(id)
for _, fs := range applicableFs { for _, fs := range applicableFs {
err := transformers.MutateField( err := transform.MutateField(
r.Map(), fs.PathSlice(), fs.CreateIfNotPresent, r.Map(), fs.PathSlice(), fs.CreateIfNotPresent,
p.changeNamespace(r)) p.changeNamespace(r))
if err != nil { if err != nil {
@@ -63,8 +67,8 @@ const metaNamespace = "metadata/namespace"
// all objects have it, even "ClusterKind" objects // all objects have it, even "ClusterKind" objects
// that don't exist in a namespace (the Namespace // that don't exist in a namespace (the Namespace
// object itself doesn't live in a namespace). // object itself doesn't live in a namespace).
func (p *NamespaceTransformerPlugin) applicableFieldSpecs(id resid.ResId) []config.FieldSpec { func (p *NamespaceTransformerPlugin) applicableFieldSpecs(id resid.ResId) []types.FieldSpec {
var res []config.FieldSpec var res []types.FieldSpec
for _, fs := range p.FieldSpecs { for _, fs := range p.FieldSpecs {
if id.IsSelected(&fs.Gvk) && (fs.Path != metaNamespace || (fs.Path == metaNamespace && id.IsNamespaceableKind())) { if id.IsSelected(&fs.Gvk) && (fs.Path != metaNamespace || (fs.Path == metaNamespace && id.IsNamespaceableKind())) {
res = append(res, fs) res = append(res, fs)
@@ -126,5 +130,5 @@ func (p *NamespaceTransformerPlugin) changeNamespace(
} }
func NewNamespaceTransformerPlugin() resmap.TransformerPlugin { func NewNamespaceTransformerPlugin() resmap.TransformerPlugin {
return &NamespaceTransformerPlugin{} return &NamespaceTransformerPlugin{}
} }

View File

@@ -1,16 +1,19 @@
// Code generated by pluginator on PatchJson6902Transformer; DO NOT EDIT. // Code generated by pluginator on PatchJson6902Transformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"fmt" "fmt"
jsonpatch "github.com/evanphx/json-patch" "github.com/evanphx/json-patch"
"github.com/pkg/errors" "github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/resid" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/types"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
@@ -22,9 +25,10 @@ type PatchJson6902TransformerPlugin struct {
JsonOp string `json:"jsonOp,omitempty" yaml:"jsonOp,omitempty"` JsonOp string `json:"jsonOp,omitempty" yaml:"jsonOp,omitempty"`
} }
func (p *PatchJson6902TransformerPlugin) Config( func (p *PatchJson6902TransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
p.ldr = ldr p.ldr = h.Loader()
err = yaml.Unmarshal(c, p) err = yaml.Unmarshal(c, p)
if err != nil { if err != nil {
return err return err
@@ -70,7 +74,7 @@ func (p *PatchJson6902TransformerPlugin) Config(
func (p *PatchJson6902TransformerPlugin) Transform(m resmap.ResMap) error { func (p *PatchJson6902TransformerPlugin) Transform(m resmap.ResMap) error {
id := resid.NewResIdWithNamespace( id := resid.NewResIdWithNamespace(
gvk.Gvk{ resid.Gvk{
Group: p.Target.Group, Group: p.Target.Group,
Version: p.Target.Version, Version: p.Target.Version,
Kind: p.Target.Kind, Kind: p.Target.Kind,
@@ -95,5 +99,5 @@ func (p *PatchJson6902TransformerPlugin) Transform(m resmap.ResMap) error {
} }
func NewPatchJson6902TransformerPlugin() resmap.TransformerPlugin { func NewPatchJson6902TransformerPlugin() resmap.TransformerPlugin {
return &PatchJson6902TransformerPlugin{} return &PatchJson6902TransformerPlugin{}
} }

View File

@@ -1,28 +1,30 @@
// Code generated by pluginator on PatchStrategicMergeTransformer; DO NOT EDIT. // Code generated by pluginator on PatchStrategicMergeTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"fmt" "fmt"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/v3/pkg/resource" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/types"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
type PatchStrategicMergeTransformerPlugin struct { type PatchStrategicMergeTransformerPlugin struct {
ldr ifc.Loader h *resmap.PluginHelpers
rf *resmap.Factory
loadedPatches []*resource.Resource loadedPatches []*resource.Resource
Paths []types.PatchStrategicMerge `json:"paths,omitempty" yaml:"paths,omitempty"` Paths []types.PatchStrategicMerge `json:"paths,omitempty" yaml:"paths,omitempty"`
Patches string `json:"patches,omitempty" yaml:"patches,omitempty"` Patches string `json:"patches,omitempty" yaml:"patches,omitempty"`
} }
func (p *PatchStrategicMergeTransformerPlugin) Config( func (p *PatchStrategicMergeTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
p.ldr = ldr p.h = h
p.rf = rf
err = yaml.Unmarshal(c, p) err = yaml.Unmarshal(c, p)
if err != nil { if err != nil {
return err return err
@@ -32,12 +34,13 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
} }
if len(p.Paths) != 0 { if len(p.Paths) != 0 {
for _, onePath := range p.Paths { for _, onePath := range p.Paths {
res, err := p.rf.RF().SliceFromBytes([]byte(onePath)) res, err := p.h.ResmapFactory().RF().SliceFromBytes([]byte(onePath))
if err == nil { if err == nil {
p.loadedPatches = append(p.loadedPatches, res...) p.loadedPatches = append(p.loadedPatches, res...)
continue continue
} }
res, err = p.rf.RF().SliceFromPatches(ldr, []types.PatchStrategicMerge{onePath}) res, err = p.h.ResmapFactory().RF().SliceFromPatches(
p.h.Loader(), []types.PatchStrategicMerge{onePath})
if err != nil { if err != nil {
return err return err
} }
@@ -45,7 +48,7 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
} }
} }
if p.Patches != "" { if p.Patches != "" {
res, err := p.rf.RF().SliceFromBytes([]byte(p.Patches)) res, err := p.h.ResmapFactory().RF().SliceFromBytes([]byte(p.Patches))
if err != nil { if err != nil {
return err return err
} }
@@ -60,7 +63,7 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
} }
func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error { func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error {
patches, err := p.rf.MergePatches(p.loadedPatches) patches, err := p.h.ResmapFactory().MergePatches(p.loadedPatches)
if err != nil { if err != nil {
return err return err
} }
@@ -86,5 +89,5 @@ func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error
} }
func NewPatchStrategicMergeTransformerPlugin() resmap.TransformerPlugin { func NewPatchStrategicMergeTransformerPlugin() resmap.TransformerPlugin {
return &PatchStrategicMergeTransformerPlugin{} return &PatchStrategicMergeTransformerPlugin{}
} }

View File

@@ -1,21 +1,22 @@
// Code generated by pluginator on PatchTransformer; DO NOT EDIT. // Code generated by pluginator on PatchTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"fmt" "fmt"
"github.com/evanphx/json-patch" "github.com/evanphx/json-patch"
"github.com/pkg/errors" "github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/v3/pkg/resource" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/types"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
type PatchTransformerPlugin struct { type PatchTransformerPlugin struct {
ldr ifc.Loader
rf *resmap.Factory
loadedPatch *resource.Resource loadedPatch *resource.Resource
decodedPatch jsonpatch.Patch decodedPatch jsonpatch.Patch
Path string `json:"path,omitempty" yaml:"path,omitempty"` Path string `json:"path,omitempty" yaml:"path,omitempty"`
@@ -23,10 +24,9 @@ type PatchTransformerPlugin struct {
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"` Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
} }
func (p *PatchTransformerPlugin) Config( func (p *PatchTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
p.ldr = ldr
p.rf = rf
err = yaml.Unmarshal(c, p) err = yaml.Unmarshal(c, p)
if err != nil { if err != nil {
return err return err
@@ -43,7 +43,7 @@ func (p *PatchTransformerPlugin) Config(
} }
var in []byte var in []byte
if p.Path != "" { if p.Path != "" {
in, err = ldr.Load(p.Path) in, err = h.Loader().Load(p.Path)
if err != nil { if err != nil {
return return
} }
@@ -52,7 +52,7 @@ func (p *PatchTransformerPlugin) Config(
in = []byte(p.Patch) in = []byte(p.Patch)
} }
patchSM, errSM := p.rf.RF().FromBytes(in) patchSM, errSM := h.ResmapFactory().RF().FromBytes(in)
patchJson, errJson := jsonPatchFromBytes(in) patchJson, errJson := jsonPatchFromBytes(in)
if errSM != nil && errJson != nil { if errSM != nil && errJson != nil {
err = fmt.Errorf( err = fmt.Errorf(
@@ -144,5 +144,5 @@ func jsonPatchFromBytes(
} }
func NewPatchTransformerPlugin() resmap.TransformerPlugin { func NewPatchTransformerPlugin() resmap.TransformerPlugin {
return &PatchTransformerPlugin{} return &PatchTransformerPlugin{}
} }

View File

@@ -1,38 +1,42 @@
// Code generated by pluginator on PrefixSuffixTransformer; DO NOT EDIT. // Code generated by pluginator on PrefixSuffixTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"errors" "errors"
"fmt" "fmt"
"sigs.k8s.io/kustomize/v3/pkg/gvk" "sigs.k8s.io/kustomize/api/transform"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/transformers" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
// Add the given prefix and suffix to the field. // Add the given prefix and suffix to the field.
type PrefixSuffixTransformerPlugin struct { type PrefixSuffixTransformerPlugin struct {
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"` Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"` Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"` FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
} }
// Not placed in a file yet due to lack of demand. // Not placed in a file yet due to lack of demand.
var prefixSuffixFieldSpecsToSkip = []config.FieldSpec{ var prefixSuffixFieldSpecsToSkip = []types.FieldSpec{
{ {
Gvk: gvk.Gvk{Kind: "CustomResourceDefinition"}, Gvk: resid.Gvk{Kind: "CustomResourceDefinition"},
}, },
{ {
Gvk: gvk.Gvk{Group: "apiregistration.k8s.io", Kind: "APIService"}, Gvk: resid.Gvk{Group: "apiregistration.k8s.io", Kind: "APIService"},
}, },
} }
func (p *PrefixSuffixTransformerPlugin) Config( func (p *PrefixSuffixTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
p.Prefix = "" p.Prefix = ""
p.Suffix = "" p.Suffix = ""
p.FieldSpecs = nil p.FieldSpecs = nil
@@ -81,7 +85,7 @@ func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
// the addPrefixSuffix method will not // the addPrefixSuffix method will not
// change the name if both the prefix and suffix // change the name if both the prefix and suffix
// are empty. // are empty.
err := transformers.MutateField( err := transform.MutateField(
r.Map(), r.Map(),
path.PathSlice(), path.PathSlice(),
path.CreateIfNotPresent, path.CreateIfNotPresent,
@@ -94,7 +98,7 @@ func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
return nil return nil
} }
func smellsLikeANameChange(fs *config.FieldSpec) bool { func smellsLikeANameChange(fs *types.FieldSpec) bool {
return fs.Path == "metadata/name" return fs.Path == "metadata/name"
} }
@@ -118,5 +122,5 @@ func (p *PrefixSuffixTransformerPlugin) addPrefixSuffix(
} }
func NewPrefixSuffixTransformerPlugin() resmap.TransformerPlugin { func NewPrefixSuffixTransformerPlugin() resmap.TransformerPlugin {
return &PrefixSuffixTransformerPlugin{} return &PrefixSuffixTransformerPlugin{}
} }

View File

@@ -1,27 +1,31 @@
// Code generated by pluginator on ReplicaCountTransformer; DO NOT EDIT. // Code generated by pluginator on ReplicaCountTransformer; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"fmt" "fmt"
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/transform"
"sigs.k8s.io/kustomize/v3/pkg/resid"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/v3/pkg/transformers" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/v3/pkg/types"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
// Find matching replicas declarations and replace the count. // Find matching replicas declarations and replace the count.
// Eases the kustomization configuration of replica changes. // Eases the kustomization configuration of replica changes.
type ReplicaCountTransformerPlugin struct { type ReplicaCountTransformerPlugin struct {
Replica types.Replica `json:"replica,omitempty" yaml:"replica,omitempty"` Replica types.Replica `json:"replica,omitempty" yaml:"replica,omitempty"`
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"` FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
} }
func (p *ReplicaCountTransformerPlugin) Config( func (p *ReplicaCountTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) { h *resmap.PluginHelpers, c []byte) (err error) {
p.Replica = types.Replica{} p.Replica = types.Replica{}
p.FieldSpecs = nil p.FieldSpecs = nil
@@ -29,7 +33,6 @@ func (p *ReplicaCountTransformerPlugin) Config(
} }
func (p *ReplicaCountTransformerPlugin) Transform(m resmap.ResMap) error { func (p *ReplicaCountTransformerPlugin) Transform(m resmap.ResMap) error {
found := false found := false
for i, replicaSpec := range p.FieldSpecs { for i, replicaSpec := range p.FieldSpecs {
matcher := p.createMatcher(i) matcher := p.createMatcher(i)
@@ -38,7 +41,7 @@ func (p *ReplicaCountTransformerPlugin) Transform(m resmap.ResMap) error {
for _, res := range append(matchOriginal, matchCurrent...) { for _, res := range append(matchOriginal, matchCurrent...) {
found = true found = true
err := transformers.MutateField( err := transform.MutateField(
res.Map(), replicaSpec.PathSlice(), res.Map(), replicaSpec.PathSlice(),
replicaSpec.CreateIfNotPresent, p.addReplicas) replicaSpec.CreateIfNotPresent, p.addReplicas)
if err != nil { if err != nil {
@@ -85,5 +88,5 @@ func (p *ReplicaCountTransformerPlugin) addReplicas(in interface{}) (interface{}
} }
func NewReplicaCountTransformerPlugin() resmap.TransformerPlugin { func NewReplicaCountTransformerPlugin() resmap.TransformerPlugin {
return &ReplicaCountTransformerPlugin{} return &ReplicaCountTransformerPlugin{}
} }

View File

@@ -1,23 +1,26 @@
// Code generated by pluginator on SecretGenerator; DO NOT EDIT. // Code generated by pluginator on SecretGenerator; DO NOT EDIT.
package builtin // pluginator {Version:unknown GitCommit:$Format:%H$ BuildDate:1970-01-01T00:00:00Z GoOs:linux GoArch:amd64}
package builtins
import ( import (
"sigs.k8s.io/kustomize/v3/pkg/ifc" "sigs.k8s.io/kustomize/api/kv"
"sigs.k8s.io/kustomize/v3/pkg/resmap" "sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/v3/pkg/types" "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
) )
type SecretGeneratorPlugin struct { type SecretGeneratorPlugin struct {
ldr ifc.Loader h *resmap.PluginHelpers
rf *resmap.Factory
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
types.GeneratorOptions types.GeneratorOptions
types.SecretArgs types.SecretArgs
} }
func (p *SecretGeneratorPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, config []byte) (err error) { func (p *SecretGeneratorPlugin) Config(h *resmap.PluginHelpers, config []byte) (err error) {
p.GeneratorOptions = types.GeneratorOptions{} p.GeneratorOptions = types.GeneratorOptions{}
p.SecretArgs = types.SecretArgs{} p.SecretArgs = types.SecretArgs{}
err = yaml.Unmarshal(config, p) err = yaml.Unmarshal(config, p)
@@ -27,15 +30,16 @@ func (p *SecretGeneratorPlugin) Config(
if p.SecretArgs.Namespace == "" { if p.SecretArgs.Namespace == "" {
p.SecretArgs.Namespace = p.Namespace p.SecretArgs.Namespace = p.Namespace
} }
p.ldr = ldr p.h = h
p.rf = rf
return return
} }
func (p *SecretGeneratorPlugin) Generate() (resmap.ResMap, error) { func (p *SecretGeneratorPlugin) Generate() (resmap.ResMap, error) {
return p.rf.FromSecretArgs(p.ldr, &p.GeneratorOptions, p.SecretArgs) return p.h.ResmapFactory().FromSecretArgs(
kv.NewLoader(p.h.Loader(), p.h.Validator()),
&p.GeneratorOptions, p.SecretArgs)
} }
func NewSecretGeneratorPlugin() resmap.GeneratorPlugin { func NewSecretGeneratorPlugin() resmap.GeneratorPlugin {
return &SecretGeneratorPlugin{} return &SecretGeneratorPlugin{}
} }

View File

@@ -0,0 +1,8 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package builtins holds code generated from the builtin plugins.
// The "builtin" plugins are written as normal plugins and can
// be used as such, but they are also used to generate the code
// in this package so they can be statically linked to client code.
package builtins

View File

@@ -0,0 +1,17 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// +build tools
// This file exists to declare that its containing
// package explicitly depends on the pluginator
// tool (via go:generate directives)
package builtins
// TODO: replace this, with the appropriate version
// once the API is launched, and the new pluginator
// has been compiled against it and released.
//
// import (
// _ "sigs.k8s.io/kustomize/pluginator"
// )

View File

@@ -1,20 +1,7 @@
/* // Copyright 2019 The Kubernetes Authors.
Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); package compiler
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.
*/
package plugins
import ( import (
"fmt" "fmt"
@@ -25,7 +12,8 @@ import (
"strings" "strings"
"time" "time"
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig" "sigs.k8s.io/kustomize/api/pgmconfig"
"sigs.k8s.io/kustomize/api/plugins/config"
) )
// Compiler creates Go plugin object files. // Compiler creates Go plugin object files.
@@ -48,23 +36,20 @@ func DefaultSrcRoot() (string, error) {
root = filepath.Join( root = filepath.Join(
os.Getenv("GOPATH"), "src", os.Getenv("GOPATH"), "src",
pgmconfig.DomainName, config.DomainName, pgmconfig.ProgramName, config.PluginRoot)
pgmconfig.ProgramName, pgmconfig.PluginRoot)
if FileExists(root) { if FileExists(root) {
return root, nil return root, nil
} }
nope = append(nope, root) nope = append(nope, root)
root = DefaultPluginConfig().DirectoryPath root = config.DefaultPluginConfig().DirectoryPath
if FileExists(root) { if FileExists(root) {
return root, nil return root, nil
} }
nope = append(nope, root) nope = append(nope, root)
root = filepath.Join( root = filepath.Join(
homeDir(), config.HomeDir(), pgmconfig.ProgramName, config.PluginRoot)
pgmconfig.ProgramName, pgmconfig.PluginRoot)
if FileExists(root) { if FileExists(root) {
return root, nil return root, nil
} }

Some files were not shown because too many files have changed in this diff Show More