mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 17:34:21 +00:00
Put goplugins behind flag.
This commit is contained in:
@@ -21,10 +21,10 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc/transformer"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/target"
|
||||
)
|
||||
@@ -67,7 +67,7 @@ func NewCmdBuild(
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "build [path]",
|
||||
Short: "Print current configuration per contents of " + constants.KustomizationFileNames[0],
|
||||
Short: "Print current configuration per contents of " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: examples,
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@@ -88,7 +88,7 @@ func NewCmdBuild(
|
||||
// Validate validates build command.
|
||||
func (o *Options) Validate(args []string) error {
|
||||
if len(args) > 1 {
|
||||
return errors.New("specify one path to " + constants.KustomizationFileNames[0])
|
||||
return errors.New("specify one path to " + pgmconfig.KustomizationFileNames[0])
|
||||
}
|
||||
if len(args) == 0 {
|
||||
o.kustomizationPath = "./"
|
||||
|
||||
@@ -19,7 +19,7 @@ package build
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
)
|
||||
|
||||
func TestNewOptionsToSilenceCodeInspectionError(t *testing.T) {
|
||||
@@ -39,7 +39,7 @@ func TestBuildValidate(t *testing.T) {
|
||||
{"file", []string{"beans"}, "beans", ""},
|
||||
{"path", []string{"a/b/c"}, "a/b/c", ""},
|
||||
{"path", []string{"too", "many"},
|
||||
"", "specify one path to " + constants.KustomizationFileNames[0]},
|
||||
"", "specify one path to " + pgmconfig.KustomizationFileNames[0]},
|
||||
}
|
||||
for _, mycase := range cases {
|
||||
opts := Options{}
|
||||
|
||||
@@ -20,35 +20,57 @@ package commands
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/validator"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/build"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/misc"
|
||||
"sigs.k8s.io/kustomize/pkg/factory"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
// NewDefaultCommand returns the default (aka root) command for kustomize command.
|
||||
func NewDefaultCommand(f *factory.KustFactory) *cobra.Command {
|
||||
fsys := fs.MakeRealFS()
|
||||
func NewDefaultCommand() *cobra.Command {
|
||||
fSys := fs.MakeRealFS()
|
||||
stdOut := os.Stdout
|
||||
|
||||
c := &cobra.Command{
|
||||
Use: "kustomize",
|
||||
Short: "kustomize manages declarative configuration of Kubernetes",
|
||||
Use: pgmconfig.PgmName,
|
||||
Short: "Manages declarative configuration of Kubernetes",
|
||||
Long: `
|
||||
kustomize manages declarative configuration of Kubernetes.
|
||||
|
||||
Manages declarative configuration of Kubernetes.
|
||||
See https://sigs.k8s.io/kustomize
|
||||
`,
|
||||
}
|
||||
|
||||
// Configuration for ConfigMap and Secret generators.
|
||||
genMetaArgs := types.GeneratorMetaArgs{
|
||||
PluginConfig: plugin.DefaultPluginConfig(),
|
||||
}
|
||||
|
||||
c.Flags().BoolVar(
|
||||
&genMetaArgs.PluginConfig.GoEnabled,
|
||||
plugin.EnableGoPluginsFlagName,
|
||||
false, plugin.EnableGoPluginsFlagHelp)
|
||||
// Not advertising this alpha feature.
|
||||
c.Flags().MarkHidden(plugin.EnableGoPluginsFlagName)
|
||||
|
||||
uf := kunstruct.NewKunstructuredFactoryWithGeneratorArgs(&genMetaArgs)
|
||||
|
||||
c.AddCommand(
|
||||
// TODO: Make consistent API for newCmd* functions.
|
||||
build.NewCmdBuild(stdOut, fsys, f.ResmapF, f.TransformerF),
|
||||
edit.NewCmdEdit(fsys, f.ValidatorF, f.UnstructF),
|
||||
misc.NewCmdConfig(fsys),
|
||||
build.NewCmdBuild(
|
||||
stdOut, fSys,
|
||||
resmap.NewFactory(resource.NewFactory(uf)),
|
||||
transformer.NewFactoryImpl()),
|
||||
edit.NewCmdEdit(fSys, validator.NewKustValidator(), uf),
|
||||
misc.NewCmdConfig(fSys),
|
||||
misc.NewCmdVersion(stdOut),
|
||||
)
|
||||
c.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
@@ -59,7 +59,7 @@ func newCmdAddAnnotation(fSys fs.FileSystem, v func(map[string]string) error) *c
|
||||
o.mapValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "annotation",
|
||||
Short: "Adds one or more commonAnnotations to " + constants.KustomizationFileNames[0],
|
||||
Short: "Adds one or more commonAnnotations to " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: `
|
||||
add annotation {annotationKey1:annotationValue1},{annotationKey2:annotationValue2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@@ -76,7 +76,7 @@ func newCmdAddLabel(fSys fs.FileSystem, v func(map[string]string) error) *cobra.
|
||||
o.mapValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "label",
|
||||
Short: "Adds one or more commonLabels to " + constants.KustomizationFileNames[0],
|
||||
Short: "Adds one or more commonLabels to " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: `
|
||||
add label {labelKey1:labelValue1},{labelKey2:labelValue2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -27,8 +27,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
@@ -129,7 +129,7 @@ func NewKustomizationFile(fSys fs.FileSystem) (*kustomizationFile, error) { // n
|
||||
func (mf *kustomizationFile) validate() error {
|
||||
match := 0
|
||||
var path []string
|
||||
for _, kfilename := range constants.KustomizationFileNames {
|
||||
for _, kfilename := range pgmconfig.KustomizationFileNames {
|
||||
if mf.fSys.Exists(kfilename) {
|
||||
match += 1
|
||||
path = append(path, kfilename)
|
||||
@@ -138,7 +138,7 @@ func (mf *kustomizationFile) validate() error {
|
||||
|
||||
switch match {
|
||||
case 0:
|
||||
return fmt.Errorf("Missing kustomization file '%s'.\n", constants.KustomizationFileNames[0])
|
||||
return fmt.Errorf("Missing kustomization file '%s'.\n", pgmconfig.KustomizationFileNames[0])
|
||||
case 1:
|
||||
mf.path = path[0]
|
||||
default:
|
||||
|
||||
@@ -21,8 +21,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/constants"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
@@ -112,12 +112,12 @@ configMapGenerator:
|
||||
name: my-configmap
|
||||
`
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteFile(constants.KustomizationFileNames[1], []byte(kcontent))
|
||||
fakeFS.WriteFile(pgmconfig.KustomizationFileNames[1], []byte(kcontent))
|
||||
k, err := NewKustomizationFile(fakeFS)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected Error: %v", err)
|
||||
}
|
||||
if k.path != constants.KustomizationFileNames[1] {
|
||||
if k.path != pgmconfig.KustomizationFileNames[1] {
|
||||
t.Fatalf("Load incorrect file path %s", k.path)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user