Skip to content

Commit

Permalink
Adds output to kpt live init for ResourceGroup and flag
Browse files Browse the repository at this point in the history
  • Loading branch information
seans3 committed Dec 12, 2020
1 parent c1460eb commit f952ebb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion commands/initcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ type KptInitOptions struct {
name string // Inventory object name
namespace string // Inventory object namespace
inventoryID string // Inventory object unique identifier label
Quiet bool // Print output or not
}

// NewKptInitOptions returns a pointer to an initial KptInitOptions structure.
func NewKptInitOptions(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *KptInitOptions {
return &KptInitOptions{
factory: f,
ioStreams: ioStreams,
Quiet: false,
}
}

Expand Down Expand Up @@ -83,8 +85,17 @@ func (io *KptInitOptions) Run(args []string) error {
return err
}
io.inventoryID = id
if !io.Quiet {
fmt.Fprintf(io.ioStreams.Out, "namespace: %s is used for inventory object\n", io.namespace)
}
// Finally, update these values in the Inventory section of the Kptfile.
return io.updateKptfile()
if err := io.updateKptfile(); err != nil {
return err
}
if !io.Quiet {
fmt.Fprintf(io.ioStreams.Out, "Initialized: %s/Kptfile\n", io.dir)
}
return nil
}

// generateID returns the string which is a SHA1 hash of the passed namespace
Expand Down Expand Up @@ -177,5 +188,6 @@ func NewCmdInit(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra
}
cmd.Flags().StringVar(&io.name, "name", "", "Inventory object name")
cmd.Flags().BoolVar(&io.force, "force", false, "Set inventory values even if already set in Kptfile")
cmd.Flags().BoolVar(&io.Quiet, "quiet", false, "If true, do not print output during initialization of Kptfile")
return cmd
}
1 change: 1 addition & 0 deletions commands/migratecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func GetMigrateRunner(cmProvider provider.Provider, rgProvider provider.Provider
rgLoader: rgLoader,
dir: "",
}
r.initOptions.Quiet = true // Do not print output during migration
cmd := &cobra.Command{
Use: "migrate DIRECTORY",
DisableFlagsInUseLine: true,
Expand Down
3 changes: 3 additions & 0 deletions e2e/live/end-to-end-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ cp -f e2e/live/testdata/Kptfile e2e/live/testdata/migrate-error
echo "Testing kpt live init for Kptfile (ResourceGroup inventory)"
echo "kpt live init e2e/live/testdata/migrate-error"
${BIN_DIR}/kpt live init e2e/live/testdata/migrate-error > $OUTPUT_DIR/status 2>&1
assertContains "namespace: test-rg-namespace is used for inventory object"
assertContains "Initialized: "
assertContains "Kptfile"
# Difference in Kptfile should have inventory data
diff e2e/live/testdata/Kptfile e2e/live/testdata/migrate-error/Kptfile > $OUTPUT_DIR/status 2>&1
assertContains "inventory:"
Expand Down

0 comments on commit f952ebb

Please sign in to comment.