diff --git a/cmd/command/opts.go b/cmd/command/opts.go index bcb10ab706d5ff681c5a96684bf0c4c9e88cd2a8..0fb42f19e92a3f815c738b414c3e7743d00f98ed 100644 --- a/cmd/command/opts.go +++ b/cmd/command/opts.go @@ -16,19 +16,21 @@ limitations under the License. package command +import "github.com/spf13/cobra" + var ( RootOptDir string ) -// 部署集群可选配置参数集合 -var ClusterOpts struct { - ClusterId string - GatherDeployOpts +var clusterOpts struct { + clusterId string + gatherDeployOpts } -type GatherDeployOpts struct { - SSHKey string - Platform string +type gatherDeployOpts struct { + sshkey string + platform string + deployConfig string // } @@ -36,3 +38,11 @@ var HousekeeperOpts struct { OperatorImageUrl string ControllerImageUrl string } + +func SetupDeployCmdOpts(deployCmd *cobra.Command) { + flags := deployCmd.Flags() + flags.StringVarP(&clusterOpts.deployConfig, "file", "f", "./deploy-config.yaml", "location of cluster deploy config file, default ./deploy-config.yaml") + flags.StringVarP(&clusterOpts.clusterId, "cluster-id", "", "", "ClusterID of kubernetes cluster") + flags.StringVarP(&clusterOpts.sshkey, "sshkey", "", "", "Path to SSH private keys that should be used for authentication.") + flags.StringVarP(&clusterOpts.platform, "platform", "", "", "Select the infrastructure platform to deploy the cluster") +} diff --git a/cmd/deploy.go b/cmd/deploy.go index 2933f482b3cf944d8d92128bfd275a0c3a03c4c2..118a2071438dcab5ac014e97366dd4efab941f7b 100755 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -38,20 +38,16 @@ type crdTmplData struct { } func NewDeployCommand() *cobra.Command { - cmd := &cobra.Command{ + deployCmd := &cobra.Command{ Use: "deploy", Short: "Deploy a kubernetes cluster", RunE: runDeployCmd, } - - cmd.PersistentFlags().StringVar(&command.ClusterOpts.ClusterId, "cluster-id", "", "clusterID of kubernetes cluster") - cmd.PersistentFlags().StringVar(&command.ClusterOpts.GatherDeployOpts.SSHKey, "sshkey", "", "Path to SSH private keys that should be used for authentication.") - cmd.PersistentFlags().StringVar(&command.ClusterOpts.Platform, "platform", "", "Select the infrastructure platform to deploy the cluster") - + command.SetupDeployCmdOpts(deployCmd) // cmd.AddCommand(deploy.NewDeployMasterCommand()) // cmd.AddCommand(deploy.NewDeployWorkerCommand()) - return cmd + return deployCmd } func runDeployCmd(cmd *cobra.Command, args []string) error {