mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 08:20:59 +00:00
Make plugin utils package.
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||
)
|
||||
|
||||
// Compiler creates Go plugin object files.
|
||||
@@ -64,7 +65,7 @@ func (b *Compiler) Cleanup() {
|
||||
// ${pluginRoot}/${g}/${v}/$lower(${k} and places
|
||||
// object code next to source code.
|
||||
func (b *Compiler) Compile() error {
|
||||
if !FileExists(b.srcPath()) {
|
||||
if !utils.FileExists(b.srcPath()) {
|
||||
return fmt.Errorf("cannot find source at '%s'", b.srcPath())
|
||||
}
|
||||
// If you use an IDE, make sure it's go build and test flags
|
||||
@@ -77,8 +78,8 @@ func (b *Compiler) Compile() error {
|
||||
"plugin",
|
||||
"-o", b.objFile(),
|
||||
}
|
||||
goBin := goBin()
|
||||
if !FileExists(goBin) {
|
||||
goBin := utils.GoBin()
|
||||
if !utils.FileExists(goBin) {
|
||||
return fmt.Errorf(
|
||||
"cannot find go compiler %s", goBin)
|
||||
}
|
||||
@@ -95,7 +96,7 @@ func (b *Compiler) Compile() error {
|
||||
err, "cannot compile %s:\nSTDERR\n%s\n",
|
||||
b.srcPath(), b.stderr.String())
|
||||
}
|
||||
if result := filepath.Join(b.workDir, b.objFile()); !FileExists(result) {
|
||||
if result := filepath.Join(b.workDir, b.objFile()); !utils.FileExists(result) {
|
||||
return fmt.Errorf("post compile, cannot find '%s'", result)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -9,11 +9,12 @@ import (
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
. "sigs.k8s.io/kustomize/api/internal/plugins/compiler"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||
)
|
||||
|
||||
// Regression coverage over compiler behavior.
|
||||
func TestCompiler(t *testing.T) {
|
||||
srcRoot, err := DeterminePluginSrcRoot(filesys.MakeFsOnDisk())
|
||||
srcRoot, err := utils.DeterminePluginSrcRoot(filesys.MakeFsOnDisk())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -29,11 +30,11 @@ func TestCompiler(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !FileExists(expectObj) {
|
||||
if !utils.FileExists(expectObj) {
|
||||
t.Errorf("didn't find expected obj file %s", expectObj)
|
||||
}
|
||||
c.Cleanup()
|
||||
if FileExists(expectObj) {
|
||||
if utils.FileExists(expectObj) {
|
||||
t.Errorf("obj file '%s' should be gone", expectObj)
|
||||
}
|
||||
|
||||
@@ -48,11 +49,11 @@ func TestCompiler(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !FileExists(expectObj) {
|
||||
if !utils.FileExists(expectObj) {
|
||||
t.Errorf("didn't find expected obj file %s", expectObj)
|
||||
}
|
||||
c.Cleanup()
|
||||
if FileExists(expectObj) {
|
||||
if utils.FileExists(expectObj) {
|
||||
t.Errorf("obj file '%s' should be gone", expectObj)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
|
||||
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/resid"
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
@@ -202,8 +203,11 @@ func (l *Loader) loadGoPlugin(id resid.ResId) (resmap.Configurable, error) {
|
||||
if c, ok := registry[regId]; ok {
|
||||
return copyPlugin(c), nil
|
||||
}
|
||||
absPath := l.absolutePluginPath(id)
|
||||
p, err := plugin.Open(absPath + ".so")
|
||||
absPath := l.absolutePluginPath(id) + ".so"
|
||||
if !utils.FileExists(absPath) {
|
||||
return nil, fmt.Errorf("cannot find Go object code '%s'", absPath)
|
||||
}
|
||||
p, err := plugin.Open(absPath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "plugin %s fails to load", absPath)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2020 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package compiler
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
)
|
||||
|
||||
func goBin() string {
|
||||
func GoBin() string {
|
||||
return filepath.Join(runtime.GOROOT(), "bin", "go")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2020 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package compiler
|
||||
package utils
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
Reference in New Issue
Block a user