Refactor into RenderAgent and ApplyAgent
This commit is contained in:
@@ -6,7 +6,9 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
assets "example.com/monok8s/pkg/assets"
|
||||
render "example.com/monok8s/pkg/render"
|
||||
)
|
||||
|
||||
@@ -42,13 +44,20 @@ func NewCmdCreate(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
||||
return err
|
||||
},
|
||||
},
|
||||
&cobra.Command{
|
||||
Use: "crds",
|
||||
Short: "Print the bundled CRDs",
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return assets.PrintCRDs(cmd.OutOrStdout())
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
var authorizedKeysPath string
|
||||
|
||||
sshdcmd := cobra.Command{
|
||||
Use: "sshd",
|
||||
Short: "Print sshd deployment template",
|
||||
Short: "Print sshd deployments template",
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
ns, _, err := flags.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
@@ -77,8 +86,12 @@ func NewCmdCreate(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
||||
cconf := render.ControllerConf{}
|
||||
controllercmd := cobra.Command{
|
||||
Use: "controller",
|
||||
Short: "Print controller deployment template",
|
||||
Short: "Print controller deployments template",
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
if len(cconf.ImagePullSecrets) > 0 && strings.TrimSpace(cconf.Image) == "" {
|
||||
return fmt.Errorf("--image-pull-secret requires --image")
|
||||
}
|
||||
|
||||
ns, _, err := flags.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -102,9 +115,56 @@ func NewCmdCreate(flags *genericclioptions.ConfigFlags) *cobra.Command {
|
||||
"",
|
||||
"Controller image, including optional registry and tag",
|
||||
)
|
||||
controllercmd.Flags().StringSliceVar(
|
||||
&cconf.ImagePullSecrets,
|
||||
"image-pull-secret",
|
||||
nil,
|
||||
"Image pull secret name for the agent image; may be specified multiple times or as a comma-separated list",
|
||||
)
|
||||
|
||||
cmd.AddCommand(&controllercmd)
|
||||
|
||||
aconf := render.AgentConf{}
|
||||
agentcmd := cobra.Command{
|
||||
Use: "agent",
|
||||
Short: "Print agent daemonsets template",
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
if len(aconf.ImagePullSecrets) > 0 && strings.TrimSpace(aconf.Image) == "" {
|
||||
return fmt.Errorf("--image-pull-secret requires --image")
|
||||
}
|
||||
|
||||
ns, _, err := flags.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
aconf.Namespace = ns
|
||||
|
||||
out, err := render.RenderAgentDaemonSets(aconf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprint(cmd.OutOrStdout(), out)
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
agentcmd.Flags().StringVar(
|
||||
&aconf.Image,
|
||||
"image",
|
||||
"",
|
||||
"Agent image, including optional registry and tag",
|
||||
)
|
||||
agentcmd.Flags().StringSliceVar(
|
||||
&aconf.ImagePullSecrets,
|
||||
"image-pull-secret",
|
||||
nil,
|
||||
"Image pull secret name for the agent image; may be specified multiple times or as a comma-separated list",
|
||||
)
|
||||
|
||||
cmd.AddCommand(&agentcmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user