Remove config file requirement for plugin command

Change 725820 [1] configured airshipctl to fail an airship config file
isn't present.  The present change makes an exception to that behavior
for the document plugin subcommand, and moves the plugin loading from
the parent document command into the pull subcommand.

There are multiple reasons we don't want config enforcement in place for plugins:

- If a non-standard config file location is configured via an environment variable,
  the plugin won't know about it (since it's invoked separately by kustomize), and it
  would look for a potentially non-existant default config file, and fail.

- If a user is using the kustomize cli by hand along with airshipctl plugins
  (as opposed to driving the process via airshipctl itself), then they do not
  need the config anyway -- the plugin subcommand doesn't actually use it.
  Forcing the user to create a config file seems awkward here.

[1]: https://review.opendev.org/#/c/725820/16

Change-Id: Ic1b652efb14439ed2757eb9fb0a86feb8b3ef21c
This commit is contained in:
Matt McEuen 2020-06-22 17:50:01 -05:00
parent f1471d1189
commit 6af3da8d7b
3 changed files with 11 additions and 6 deletions

View File

@ -27,14 +27,13 @@ func NewDocumentCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Com
Use: "document",
Short: "Manage deployment documents",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Note: config is not loaded here; the kustomize plugin command doesn't
// require it, and multiple use cases fail if we assume the file is there.
log.Init(rootSettings.Debug, cmd.OutOrStderr())
// Load or Initialize airship Config
rootSettings.InitConfig()
},
}
documentRootCmd.AddCommand(NewPullCommand(rootSettings))
documentRootCmd.AddCommand(NewPullCommand(rootSettings, true))
documentRootCmd.AddCommand(NewPluginCommand(rootSettings))
return documentRootCmd

View File

@ -22,12 +22,18 @@ import (
)
// NewPullCommand creates a new command for pulling airship document repositories
func NewPullCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
// initConfig determines whether it's appropriate to load configuration from
// disk; e.g. this is skipped when unit testing the command.
func NewPullCommand(rootSettings *environment.AirshipCTLSettings, initConfig bool) *cobra.Command {
settings := pull.Settings{AirshipCTLSettings: rootSettings}
documentPullCmd := &cobra.Command{
Use: "pull",
Short: "Pulls documents from remote git repository",
RunE: func(cmd *cobra.Command, args []string) error {
if initConfig {
// Load or Initialize airship Config
rootSettings.InitConfig()
}
return settings.Pull()
},
}

View File

@ -50,7 +50,7 @@ func TestPull(t *testing.T) {
{
Name: "document-pull-cmd",
CmdLine: "",
Cmd: NewPullCommand(getDummyAirshipSettings()),
Cmd: NewPullCommand(getDummyAirshipSettings(), false),
},
}