Added options and scaffold Run function.
Signed-off-by: Haoxiang Zhou <haoxiang.zhou@jetstack.io>
This commit is contained in:
parent
19ad36a819
commit
990cb6ab15
@ -31,9 +31,9 @@ import (
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/convert"
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/create"
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/renew"
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/version"
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/create"
|
||||
)
|
||||
|
||||
func NewCertManagerCtlCommand(in io.Reader, out, err io.Writer, stopCh <-chan struct{}) *cobra.Command {
|
||||
|
||||
@ -19,9 +19,12 @@ package create
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
|
||||
cmclient "github.com/jetstack/cert-manager/pkg/client/clientset/versioned"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -34,26 +37,69 @@ Create a cert-manager CertificateRequest resource for one-time Certificate issui
|
||||
alias = []string{"cr"}
|
||||
)
|
||||
|
||||
// Options is a struct to support renew command
|
||||
type Options struct {
|
||||
CMClient cmclient.Interface
|
||||
RESTConfig *restclient.Config
|
||||
|
||||
// The Namespace that the CertificateRequest to be created resides in.
|
||||
// This flag registration is handled by cmdutil.Factory
|
||||
Namespace string
|
||||
// Path to the manifest for the Certificate resource (yaml file)
|
||||
FilePath string
|
||||
|
||||
genericclioptions.IOStreams
|
||||
}
|
||||
|
||||
// NewOptions returns initialized Options
|
||||
func NewOptions(ioStreams genericclioptions.IOStreams) *Options {
|
||||
return &Options{
|
||||
IOStreams: ioStreams,
|
||||
}
|
||||
}
|
||||
|
||||
// NewCmdRenew returns a cobra command for renewing Certificates
|
||||
func NewCmdCreateCertficate(ioStreams genericclioptions.IOStreams, factory cmdutil.Factory) *cobra.Command {
|
||||
//o := NewOptions(ioStreams)
|
||||
o := NewOptions(ioStreams)
|
||||
cmd := &cobra.Command{
|
||||
Use: "certificaterequest",
|
||||
Aliases: alias,
|
||||
Short: "Create a CertificateRequest resource",
|
||||
Long: long,
|
||||
Example: example,
|
||||
//Run: func(cmd *cobra.Command, args []string) {
|
||||
// cmdutil.CheckErr(o.Complete(factory))
|
||||
// cmdutil.CheckErr(o.Validate(cmd, args))
|
||||
// cmdutil.CheckErr(o.Run(args))
|
||||
//},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(factory))
|
||||
cmdutil.CheckErr(o.Run(args))
|
||||
},
|
||||
}
|
||||
|
||||
// TODO: add flags
|
||||
//cmd.Flags().StringVarP(&o.LabelSelector, "selector", "l", o.LabelSelector, "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
|
||||
//cmd.Flags().BoolVarP(&o.AllNamespaces, "all-namespaces", "A", o.AllNamespaces, "If present, mark Certificates across namespaces for manual renewal. Namespace in current context is ignored even if specified with --namespace.")
|
||||
//cmd.Flags().BoolVar(&o.All, "all", o.All, "Renew all Certificates in the given Namespace, or all namespaces with --all-namespaces enabled.")
|
||||
cmd.Flags().StringVarP(&o.FilePath, "from-file", "f", o.FilePath, "Path to the manifest for the Certificate resource (yaml file) based on which the CertificateRequest is going to be created.")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Complete takes the command arguments and factory and infers any remaining options.
|
||||
func (o *Options) Complete(f cmdutil.Factory) error {
|
||||
var err error
|
||||
o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.RESTConfig, err = f.ToRESTConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
o.CMClient, err = cmclient.NewForConfig(o.RESTConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run executes renew command
|
||||
func (o *Options) Run(args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -35,4 +35,4 @@ func NewCmdCreate(ioStreams genericclioptions.IOStreams, factory cmdutil.Factory
|
||||
cmds.AddCommand(NewCmdCreateCertficate(ioStreams, factory))
|
||||
|
||||
return cmds
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user