Remove the -f option

This commit is contained in:
Jeffrey Regan 2018-04-04 13:27:25 -07:00
parent b49f931498
commit d7d2c843de
7 changed files with 59 additions and 28 deletions

View File

@ -12,7 +12,7 @@ sed -i 's/app: hello/app: my-hello/' \
See the effect:
<!-- @manifest @test -->
```
kinflate inflate -f $BASE | grep -C 3 app:
kinflate inflate $BASE | grep -C 3 app:
```
__Next:__ [Overlays](overlays)

View File

@ -13,7 +13,7 @@ to `stdout`:
<!-- @manifest @test -->
```
kinflate inflate -f $BASE
kinflate inflate $BASE
```
__Next:__ [Customize it](customize.md)

View File

@ -4,23 +4,23 @@ The individual resource sets are:
<!-- @runKinflateStaging @test -->
```
kinflate inflate -f $OVERLAYS/staging
kinflate inflate $OVERLAYS/staging
```
<!-- @runKinflateProduction @test -->
```
kinflate inflate -f $OVERLAYS/production
kinflate inflate $OVERLAYS/production
```
To deploy, pipe the above commands to kubectl apply:
> ```
> kinflate inflate -f $OVERLAYS/staging |\
> kinflate inflate $OVERLAYS/staging |\
> kubectl apply -f -
> ```
> ```
> kinflate inflate -f $OVERLAYS/production |\
> kinflate inflate $OVERLAYS/production |\
> kubectl apply -f -
> ```

View File

@ -44,14 +44,14 @@ Confirm that the prefix appears in the output:
<!-- @confirmResourceNames @test -->
```
kinflate inflate -f . | grep --context=3 acme-
kinflate inflate | grep --context=3 acme-
```
Optionally apply the modified configuration to a cluster
<!-- @applyToCluster -->
```
kinflate inflate -f . | kubectl apply -f -
kinflate inflate | kubectl apply -f -
```
This fork of [example-hello] could be commited to a

View File

@ -128,7 +128,7 @@ resource names.
<!-- @genNamePrefixConfig @test -->
```
kinflate inflate -f $DEMO_HOME
kinflate inflate $DEMO_HOME
```
The output should contain:
@ -176,7 +176,7 @@ sed -i 's/app: helloworld/app: prod/' \
$DEMO_HOME/Kube-manifest.yaml
```
At this point, running `kinflate inflate -f .` will
At this point, running `kinflate inflate` will
generate MySQL configs with name-prefix 'prod-' and
labels `env:prod`.
@ -235,5 +235,5 @@ create the production environment.
<!-- @finalInflation @test -->
```
kinflate inflate -f $DEMO_HOME # | kubectl apply -f -
kinflate inflate $DEMO_HOME # | kubectl apply -f -
```

View File

@ -24,6 +24,8 @@ import (
"github.com/spf13/cobra"
"errors"
"k8s.io/kubectl/pkg/kinflate/app"
kutil "k8s.io/kubectl/pkg/kinflate/util"
"k8s.io/kubectl/pkg/kinflate/util/fs"
@ -39,19 +41,14 @@ func newCmdInflate(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
var o inflateOptions
cmd := &cobra.Command{
Use: "inflate -f [path]",
Use: "inflate [path]",
Short: "Use a Manifest file to generate a set of api resources",
Long: "Use a Manifest file to generate a set of api resources",
Example: `
# Use the Kube-manifest.yaml file under somedir/ to generate a set of api resources.
inflate -f somedir/`,
inflate somedir/`,
Run: func(cmd *cobra.Command, args []string) {
err := o.Validate(cmd, args)
if err != nil {
fmt.Fprintf(errOut, "error: %v\n", err)
os.Exit(1)
}
err = o.Complete(cmd, args)
err := o.Validate(args)
if err != nil {
fmt.Fprintf(errOut, "error: %v\n", err)
os.Exit(1)
@ -63,19 +60,19 @@ func newCmdInflate(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
}
},
}
cmd.Flags().StringVarP(&o.manifestPath, "filename", "f", "", "Pass in a Kube-manifest.yaml file or a directory that contains the file.")
cmd.MarkFlagRequired("filename")
return cmd
}
// Validate validates inflate command.
func (o *inflateOptions) Validate(cmd *cobra.Command, args []string) error {
return nil
}
// Complete completes inflate command.
func (o *inflateOptions) Complete(cmd *cobra.Command, args []string) error {
func (o *inflateOptions) Validate(args []string) error {
if len(args) > 1 {
return errors.New("specify one path to manifest")
}
if len(args) == 0 {
o.manifestPath = "./"
return nil
}
o.manifestPath = args[0]
return nil
}

View File

@ -39,6 +39,40 @@ type InflateTestCase struct {
ExpectedStdout string `yaml:"expectedStdout"`
}
func TestInflateValidate(t *testing.T) {
var cases = []struct {
name string
args []string
path string
erMsg string
}{
{"noargs", []string{}, "./", ""},
{"file", []string{"beans"}, "beans", ""},
{"path", []string{"a/b/c"}, "a/b/c", ""},
{"path", []string{"too", "many"}, "", "specify one path to manifest"},
}
for _, mycase := range cases {
opts := inflateOptions{}
e := opts.Validate(mycase.args)
if len(mycase.erMsg) > 0 {
if e == nil {
t.Errorf("%s: Expected an error %v", mycase.name, mycase.erMsg)
}
if e.Error() != mycase.erMsg {
t.Errorf("%s: Expected error %s, but got %v", mycase.name, mycase.erMsg, e)
}
continue
}
if e != nil {
t.Errorf("%s: unknown error %v", mycase.name, e)
continue
}
if opts.manifestPath != mycase.path {
t.Errorf("%s: expected path '%s', got '%s'", mycase.name, mycase.path, opts.manifestPath)
}
}
}
func TestInflate(t *testing.T) {
const updateEnvVar = "UPDATE_KINFLATE_EXPECTED_DATA"
updateKinflateExpected := os.Getenv(updateEnvVar) == "true"