mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Make api/plugins
This commit is contained in:
@@ -3,87 +3,11 @@
|
||||
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
)
|
||||
|
||||
const (
|
||||
// Used with Go plugins.
|
||||
// TODO: delete this from API in favor of api/plugins/config
|
||||
PluginSymbol = "KustomizePlugin"
|
||||
|
||||
// Location of builtins.
|
||||
// TODO: delete this from API in favor of api/plugins/config
|
||||
BuiltinPluginPackage = "builtin"
|
||||
|
||||
// ApiVersion of builtins.
|
||||
BuiltinPluginApiVersion = BuiltinPluginPackage
|
||||
|
||||
flagEnablePluginsName = "enable_alpha_plugins"
|
||||
flagEnablePluginsHelp = `enable plugins, an alpha feature.
|
||||
See https://github.com/kubernetes-sigs/kustomize/blob/master/docs/plugins/README.md
|
||||
`
|
||||
flagErrorFmt = `
|
||||
unable to load external plugin %s because plugins disabled
|
||||
specify the flag
|
||||
--%s
|
||||
to %s`
|
||||
)
|
||||
|
||||
func ActivePluginConfig() *types.PluginConfig {
|
||||
pc := DefaultPluginConfig()
|
||||
pc.Enabled = true
|
||||
return pc
|
||||
}
|
||||
|
||||
func DefaultPluginConfig() *types.PluginConfig {
|
||||
return &types.PluginConfig{
|
||||
Enabled: false,
|
||||
DirectoryPath: filepath.Join(
|
||||
configRoot(), pgmconfig.PluginRoot),
|
||||
}
|
||||
}
|
||||
|
||||
func notEnabledErr(name string) error {
|
||||
return fmt.Errorf(
|
||||
flagErrorFmt,
|
||||
name,
|
||||
flagEnablePluginsName,
|
||||
flagEnablePluginsHelp)
|
||||
}
|
||||
|
||||
func AddFlagEnablePlugins(set *pflag.FlagSet, v *bool) {
|
||||
set.BoolVar(
|
||||
v, flagEnablePluginsName,
|
||||
false, flagEnablePluginsHelp)
|
||||
}
|
||||
|
||||
// Use https://github.com/kirsle/configdir instead?
|
||||
func configRoot() string {
|
||||
dir := os.Getenv(pgmconfig.XdgConfigHome)
|
||||
if len(dir) == 0 {
|
||||
dir = filepath.Join(
|
||||
homeDir(), pgmconfig.DefaultConfigSubdir)
|
||||
}
|
||||
return filepath.Join(dir, pgmconfig.ProgramName)
|
||||
}
|
||||
|
||||
func homeDir() string {
|
||||
home := os.Getenv(homeEnv())
|
||||
if len(home) > 0 {
|
||||
return home
|
||||
}
|
||||
return "~"
|
||||
}
|
||||
|
||||
func homeEnv() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return "USERPROFILE"
|
||||
}
|
||||
return "HOME"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user