mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-18 05:35:47 +00:00
@@ -78,6 +78,7 @@ func NewConfigCommand(name string) *cobra.Command {
|
||||
root.AddCommand(commands.CountCommand(name))
|
||||
root.AddCommand(commands.RunFnCommand(name))
|
||||
root.AddCommand(commands.SetCommand(name))
|
||||
root.AddCommand(commands.ListSettersCommand(name))
|
||||
root.AddCommand(commands.CreateSetterCommand(name))
|
||||
|
||||
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
|
||||
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT OWNER
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
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"
|
||||
performed 2 substitutions
|
||||
set 2 values
|
||||
|
||||
Show substitutions: Show the new values
|
||||
List setters: Show the new values
|
||||
|
||||
$ config set dir
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
||||
prefix 'test environment' test string 2 true dev
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
name-prefix 'test environment' test string 2 dev
|
||||
|
||||
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 (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"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.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
|
||||
err := kio.Pipeline{
|
||||
Inputs: []kio.Reader{&kio.LocalPackageReader{PackagePath: args[0]}},
|
||||
Filters: []kio.Filter{&r.Lookup},
|
||||
Filters: []kio.Filter{&l},
|
||||
}.Execute()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -86,8 +87,8 @@ func (r *SetRunner) lookup(c *cobra.Command, args []string) error {
|
||||
table.SetHeader([]string{
|
||||
"NAME", "DESCRIPTION", "VALUE", "TYPE", "COUNT", "SETBY",
|
||||
})
|
||||
for i := range r.Lookup.SetterCounts {
|
||||
s := r.Lookup.SetterCounts[i]
|
||||
for i := range l.SetterCounts {
|
||||
s := l.SetterCounts[i]
|
||||
v := s.Value
|
||||
if s.Value == "" {
|
||||
v = s.Value
|
||||
@@ -102,6 +103,11 @@ func (r *SetRunner) lookup(c *cobra.Command, args []string) error {
|
||||
})
|
||||
}
|
||||
table.Render()
|
||||
|
||||
if len(l.SetterCounts) == 0 {
|
||||
// exit non-0 if no matching setters are found
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -142,6 +142,25 @@ var GrepExamples = `
|
||||
# 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`
|
||||
|
||||
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 MergeLong = `
|
||||
[Alpha] Merge Resource configuration files
|
||||
@@ -286,19 +305,19 @@ var SetExamples = `
|
||||
List setters: Show the possible setters
|
||||
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT OWNER
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
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"
|
||||
performed 2 substitutions
|
||||
set 2 values
|
||||
|
||||
Show substitutions: Show the new values
|
||||
List setters: Show the new values
|
||||
|
||||
$ config set dir
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
||||
prefix 'test environment' test string 2 true dev
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
name-prefix 'test environment' test string 2 dev
|
||||
|
||||
New Resource YAML:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user