mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
publish list-setters command
This commit is contained in:
@@ -78,6 +78,7 @@ func NewConfigCommand(name string) *cobra.Command {
|
|||||||
root.AddCommand(commands.CountCommand(name))
|
root.AddCommand(commands.CountCommand(name))
|
||||||
root.AddCommand(commands.RunFnCommand(name))
|
root.AddCommand(commands.RunFnCommand(name))
|
||||||
root.AddCommand(commands.SetCommand(name))
|
root.AddCommand(commands.SetCommand(name))
|
||||||
|
root.AddCommand(commands.ListSettersCommand(name))
|
||||||
root.AddCommand(commands.CreateSetterCommand(name))
|
root.AddCommand(commands.CreateSetterCommand(name))
|
||||||
|
|
||||||
root.AddCommand(&cobra.Command{
|
root.AddCommand(&cobra.Command{
|
||||||
|
|||||||
23
cmd/config/docs/commands/list-setters.md
Normal file
23
cmd/config/docs/commands/list-setters.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
## set
|
||||||
|
|
||||||
|
[Alpha] List setters for Resources.
|
||||||
|
|
||||||
|
### Synopsis
|
||||||
|
|
||||||
|
List setters for Resources.
|
||||||
|
|
||||||
|
DIR
|
||||||
|
|
||||||
|
A directory containing Resource configuration.
|
||||||
|
|
||||||
|
NAME
|
||||||
|
|
||||||
|
Optional. The name of the setter to display.
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
Show setters:
|
||||||
|
|
||||||
|
$ config set DIR/
|
||||||
|
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||||
|
name-prefix '' PREFIX string 2
|
||||||
@@ -59,19 +59,19 @@ To create a custom setter for a field see: `kustomize help config create-setter`
|
|||||||
List setters: Show the possible setters
|
List setters: Show the possible setters
|
||||||
|
|
||||||
$ config set DIR/
|
$ config set DIR/
|
||||||
NAME DESCRIPTION VALUE TYPE COUNT OWNER
|
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||||
name-prefix '' PREFIX string 2
|
name-prefix '' PREFIX string 2
|
||||||
|
|
||||||
Perform substitution: set a new value, owner and description
|
Perform set: set a new value, owner and description
|
||||||
|
|
||||||
$ kustomize config set DIR/ name-prefix "test" --description "test environment" --set-by "dev"
|
$ kustomize config set DIR/ name-prefix "test" --description "test environment" --set-by "dev"
|
||||||
performed 2 substitutions
|
set 2 values
|
||||||
|
|
||||||
Show substitutions: Show the new values
|
List setters: Show the new values
|
||||||
|
|
||||||
$ config set dir
|
$ config set DIR/
|
||||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||||
prefix 'test environment' test string 2 true dev
|
name-prefix 'test environment' test string 2 dev
|
||||||
|
|
||||||
New Resource YAML:
|
New Resource YAML:
|
||||||
|
|
||||||
|
|||||||
47
cmd/config/internal/commands/cmdlistsetters.go
Normal file
47
cmd/config/internal/commands/cmdlistsetters.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/setters"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewListSettersRunner returns a command runner.
|
||||||
|
func NewListSettersRunner(parent string) *ListSettersRunner {
|
||||||
|
r := &ListSettersRunner{}
|
||||||
|
c := &cobra.Command{
|
||||||
|
Use: "list-setters DIR [NAME]",
|
||||||
|
Args: cobra.RangeArgs(1, 2),
|
||||||
|
Short: commands.ListSettersShort,
|
||||||
|
Long: commands.ListSettersLong,
|
||||||
|
Example: commands.ListSettersExamples,
|
||||||
|
PreRunE: r.preRunE,
|
||||||
|
RunE: r.runE,
|
||||||
|
}
|
||||||
|
fixDocs(parent, c)
|
||||||
|
r.Command = c
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func ListSettersCommand(parent string) *cobra.Command {
|
||||||
|
return NewListSettersRunner(parent).Command
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListSettersRunner struct {
|
||||||
|
Command *cobra.Command
|
||||||
|
Lookup setters.LookupSetters
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ListSettersRunner) preRunE(c *cobra.Command, args []string) error {
|
||||||
|
if len(args) > 1 {
|
||||||
|
r.Lookup.Name = args[1]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ListSettersRunner) runE(c *cobra.Command, args []string) error {
|
||||||
|
return handleError(c, lookup(r.Lookup, c, args))
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -63,14 +64,14 @@ func (r *SetRunner) runE(c *cobra.Command, args []string) error {
|
|||||||
return handleError(c, r.perform(c, args))
|
return handleError(c, r.perform(c, args))
|
||||||
}
|
}
|
||||||
|
|
||||||
return handleError(c, r.lookup(c, args))
|
return handleError(c, lookup(r.Lookup, c, args))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *SetRunner) lookup(c *cobra.Command, args []string) error {
|
func lookup(l setters.LookupSetters, c *cobra.Command, args []string) error {
|
||||||
// lookup the setters
|
// lookup the setters
|
||||||
err := kio.Pipeline{
|
err := kio.Pipeline{
|
||||||
Inputs: []kio.Reader{&kio.LocalPackageReader{PackagePath: args[0]}},
|
Inputs: []kio.Reader{&kio.LocalPackageReader{PackagePath: args[0]}},
|
||||||
Filters: []kio.Filter{&r.Lookup},
|
Filters: []kio.Filter{&l},
|
||||||
}.Execute()
|
}.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -86,8 +87,8 @@ func (r *SetRunner) lookup(c *cobra.Command, args []string) error {
|
|||||||
table.SetHeader([]string{
|
table.SetHeader([]string{
|
||||||
"NAME", "DESCRIPTION", "VALUE", "TYPE", "COUNT", "SETBY",
|
"NAME", "DESCRIPTION", "VALUE", "TYPE", "COUNT", "SETBY",
|
||||||
})
|
})
|
||||||
for i := range r.Lookup.SetterCounts {
|
for i := range l.SetterCounts {
|
||||||
s := r.Lookup.SetterCounts[i]
|
s := l.SetterCounts[i]
|
||||||
v := s.Value
|
v := s.Value
|
||||||
if s.Value == "" {
|
if s.Value == "" {
|
||||||
v = s.Value
|
v = s.Value
|
||||||
@@ -102,6 +103,11 @@ func (r *SetRunner) lookup(c *cobra.Command, args []string) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
table.Render()
|
table.Render()
|
||||||
|
|
||||||
|
if len(l.SetterCounts) == 0 {
|
||||||
|
// exit non-0 if no matching setters are found
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,25 @@ var GrepExamples = `
|
|||||||
# look for Resources matching a specific container image
|
# look for Resources matching a specific container image
|
||||||
kustomize config grep "spec.template.spec.containers[name=nginx].image=nginx:1\.7\.9" my-dir/ | kustomize config tree`
|
kustomize config grep "spec.template.spec.containers[name=nginx].image=nginx:1\.7\.9" my-dir/ | kustomize config tree`
|
||||||
|
|
||||||
|
var ListSettersShort = `[Alpha] List setters for Resources.`
|
||||||
|
var ListSettersLong = `
|
||||||
|
List setters for Resources.
|
||||||
|
|
||||||
|
DIR
|
||||||
|
|
||||||
|
A directory containing Resource configuration.
|
||||||
|
|
||||||
|
NAME
|
||||||
|
|
||||||
|
Optional. The name of the setter to display.
|
||||||
|
`
|
||||||
|
var ListSettersExamples = `
|
||||||
|
Show setters:
|
||||||
|
|
||||||
|
$ config set DIR/
|
||||||
|
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||||
|
name-prefix '' PREFIX string 2`
|
||||||
|
|
||||||
var MergeShort = `[Alpha] Merge Resource configuration files`
|
var MergeShort = `[Alpha] Merge Resource configuration files`
|
||||||
var MergeLong = `
|
var MergeLong = `
|
||||||
[Alpha] Merge Resource configuration files
|
[Alpha] Merge Resource configuration files
|
||||||
@@ -286,19 +305,19 @@ var SetExamples = `
|
|||||||
List setters: Show the possible setters
|
List setters: Show the possible setters
|
||||||
|
|
||||||
$ config set DIR/
|
$ config set DIR/
|
||||||
NAME DESCRIPTION VALUE TYPE COUNT OWNER
|
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||||
name-prefix '' PREFIX string 2
|
name-prefix '' PREFIX string 2
|
||||||
|
|
||||||
Perform substitution: set a new value, owner and description
|
Perform set: set a new value, owner and description
|
||||||
|
|
||||||
$ kustomize config set DIR/ name-prefix "test" --description "test environment" --set-by "dev"
|
$ kustomize config set DIR/ name-prefix "test" --description "test environment" --set-by "dev"
|
||||||
performed 2 substitutions
|
set 2 values
|
||||||
|
|
||||||
Show substitutions: Show the new values
|
List setters: Show the new values
|
||||||
|
|
||||||
$ config set dir
|
$ config set DIR/
|
||||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||||
prefix 'test environment' test string 2 true dev
|
name-prefix 'test environment' test string 2 dev
|
||||||
|
|
||||||
New Resource YAML:
|
New Resource YAML:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user