mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 00:52:55 +00:00
Merge pull request #1467 from richardmarshall/create_fixes
Fixes to create sub-command
This commit is contained in:
@@ -63,12 +63,12 @@ func NewCmdCreate(fSys fs.FileSystem, uf ifc.KunstructuredFactory) *cobra.Comman
|
|||||||
"Set the value of the namespace field in the customization file.")
|
"Set the value of the namespace field in the customization file.")
|
||||||
c.Flags().StringVar(
|
c.Flags().StringVar(
|
||||||
&opts.annotations,
|
&opts.annotations,
|
||||||
"annotation",
|
"annotations",
|
||||||
"",
|
"",
|
||||||
"Add one or more common annotations.")
|
"Add one or more common annotations.")
|
||||||
c.Flags().StringVar(
|
c.Flags().StringVar(
|
||||||
&opts.labels,
|
&opts.labels,
|
||||||
"label",
|
"labels",
|
||||||
"",
|
"",
|
||||||
"Add one or more common labels.")
|
"Add one or more common labels.")
|
||||||
c.Flags().StringVar(
|
c.Flags().StringVar(
|
||||||
@@ -95,11 +95,15 @@ func NewCmdCreate(fSys fs.FileSystem, uf ifc.KunstructuredFactory) *cobra.Comman
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runCreate(opts createFlags, fSys fs.FileSystem, uf ifc.KunstructuredFactory) error {
|
func runCreate(opts createFlags, fSys fs.FileSystem, uf ifc.KunstructuredFactory) error {
|
||||||
resources, err := util.GlobPatterns(fSys, strings.Split(opts.resources, ","))
|
var resources []string
|
||||||
if err != nil {
|
var err error
|
||||||
return err
|
if opts.resources != "" {
|
||||||
|
resources, err = util.GlobPatterns(fSys, strings.Split(opts.resources, ","))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if _, err := kustfile.NewKustomizationFile(fSys); err == nil {
|
if _, err = kustfile.NewKustomizationFile(fSys); err == nil {
|
||||||
return fmt.Errorf("kustomization file already exists")
|
return fmt.Errorf("kustomization file already exists")
|
||||||
}
|
}
|
||||||
if opts.detectResources {
|
if opts.detectResources {
|
||||||
|
|||||||
@@ -132,6 +132,12 @@ metadata:
|
|||||||
fakeFS.WriteFile("/README.md", []byte(`
|
fakeFS.WriteFile("/README.md", []byte(`
|
||||||
# Not a k8s resource
|
# Not a k8s resource
|
||||||
This file is not a valid kubernetes object.`))
|
This file is not a valid kubernetes object.`))
|
||||||
|
fakeFS.WriteFile("/non-k8s.yaml", []byte(`
|
||||||
|
# Not a k8s resource
|
||||||
|
other: yaml
|
||||||
|
foo:
|
||||||
|
- bar
|
||||||
|
- baz`))
|
||||||
fakeFS.Mkdir("/sub")
|
fakeFS.Mkdir("/sub")
|
||||||
fakeFS.WriteFile("/sub/test.yaml", []byte(`
|
fakeFS.WriteFile("/sub/test.yaml", []byte(`
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@@ -141,6 +147,12 @@ metadata:
|
|||||||
fakeFS.WriteFile("/sub/README.md", []byte(`
|
fakeFS.WriteFile("/sub/README.md", []byte(`
|
||||||
# Not a k8s resource
|
# Not a k8s resource
|
||||||
This file in a subdirectory is not a valid kubernetes object.`))
|
This file in a subdirectory is not a valid kubernetes object.`))
|
||||||
|
fakeFS.WriteFile("/sub/non-k8s.yaml", []byte(`
|
||||||
|
# Not a k8s resource
|
||||||
|
other: yaml
|
||||||
|
foo:
|
||||||
|
- bar
|
||||||
|
- baz`))
|
||||||
fakeFS.Mkdir("/overlay")
|
fakeFS.Mkdir("/overlay")
|
||||||
fakeFS.WriteFile("/overlay/test.yaml", []byte(`
|
fakeFS.WriteFile("/overlay/test.yaml", []byte(`
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ func GlobPatterns(fsys fs.FileSystem, patterns []string) ([]string, error) {
|
|||||||
// `key:value` into a map.
|
// `key:value` into a map.
|
||||||
func ConvertToMap(input string, kind string) (map[string]string, error) {
|
func ConvertToMap(input string, kind string) (map[string]string, error) {
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
|
if input == "" {
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
inputs := strings.Split(input, ",")
|
inputs := strings.Split(input, ",")
|
||||||
for _, input := range inputs {
|
for _, input := range inputs {
|
||||||
c := strings.Index(input, ":")
|
c := strings.Index(input, ":")
|
||||||
|
|||||||
Reference in New Issue
Block a user