Moves ctl kubeconfig flags to top level

Signed-off-by: JoshVanL <vleeuwenjoshua@gmail.com>
This commit is contained in:
JoshVanL 2020-04-30 12:02:29 +01:00
parent 1bc930a484
commit 5af4fa8e87
No known key found for this signature in database
GPG Key ID: E7A7196576A219DA
8 changed files with 11 additions and 38 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
/acmesolver
/controller
/ingress-shim
/ctl
/hack/build/dockerfiles/cert-manager-*_*_*
.vscode
.venv

View File

@ -5,16 +5,7 @@ go_library(
srcs = ["main.go"],
importpath = "github.com/jetstack/cert-manager/cmd/ctl",
visibility = ["//visibility:private"],
deps = [
"//cmd/ctl/cmd:go_default_library",
"//pkg/util/cmd:go_default_library",
<<<<<<< HEAD
"@io_k8s_klog//:go_default_library",
=======
"@com_github_spf13_cobra//:go_default_library",
"@io_k8s_cli_runtime//pkg/genericclioptions:go_default_library",
>>>>>>> 65e8ff5db... Cleans up renew kube flags and adds --namespace validation
],
deps = ["//pkg/util/cmd:go_default_library"],
)
go_binary(

View File

@ -12,6 +12,7 @@ go_library(
"@com_github_spf13_cobra//:go_default_library",
"@io_k8s_cli_runtime//pkg/genericclioptions:go_default_library",
"@io_k8s_client_go//plugin/pkg/client/auth:go_default_library",
"@io_k8s_klog//:go_default_library",
"@io_k8s_kubectl//pkg/cmd/util:go_default_library",
],
)

View File

@ -62,7 +62,7 @@ cert-manager-ctl is a CLI tool manage and configure cert-manager resources for K
ioStreams := genericclioptions.IOStreams{In: in, Out: out, ErrOut: err}
cmds.AddCommand(version.NewCmdVersion(ioStreams))
cmds.AddCommand(convert.NewCmdConvert(ioStreams))
cmds.AddCommand(renew.NewCmdRenew(ioStreams))
cmds.AddCommand(renew.NewCmdRenew(ioStreams, factory))
return cmds
}

View File

@ -15,9 +15,7 @@ go_library(
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_cli_runtime//pkg/genericclioptions:go_default_library",
"@io_k8s_client_go//kubernetes:go_default_library",
"@io_k8s_client_go//plugin/pkg/client/auth:go_default_library",
"@io_k8s_client_go//rest:go_default_library",
"@io_k8s_klog//:go_default_library",
"@io_k8s_kubectl//pkg/cmd/util:go_default_library",
"@io_k8s_kubectl//pkg/util/i18n:go_default_library",
"@io_k8s_kubectl//pkg/util/templates:go_default_library",

View File

@ -19,19 +19,14 @@ package renew
import (
"context"
"errors"
"flag"
"fmt"
"os"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
// Load all auth plugins
_ "k8s.io/client-go/plugin/pkg/client/auth"
restclient "k8s.io/client-go/rest"
"k8s.io/klog"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
@ -80,10 +75,8 @@ func NewOptions(ioStreams genericclioptions.IOStreams) *Options {
}
// NewCmdRenew returns a cobra command for renewing Certificates
func NewCmdRenew(ioStreams genericclioptions.IOStreams) *cobra.Command {
func NewCmdRenew(ioStreams genericclioptions.IOStreams, factory cmdutil.Factory) *cobra.Command {
o := NewOptions(ioStreams)
var factory cmdutil.Factory
cmd := &cobra.Command{
Use: "renew",
Short: "Mark a Certificate for manual renewal",
@ -100,21 +93,6 @@ func NewCmdRenew(ioStreams genericclioptions.IOStreams) *cobra.Command {
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.")
kubeConfigFlags := genericclioptions.NewConfigFlags(true)
kubeConfigFlags.AddFlags(cmd.PersistentFlags())
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(kubeConfigFlags)
matchVersionKubeConfigFlags.AddFlags(cmd.PersistentFlags())
factory = cmdutil.NewFactory(matchVersionKubeConfigFlags)
cmd.Flags().AddGoFlagSet(flag.CommandLine)
flag.CommandLine.Parse([]string{})
fakefs := flag.NewFlagSet("fake", flag.ExitOnError)
klog.InitFlags(fakefs)
if err := fakefs.Parse([]string{"-logtostderr=false"}); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
return cmd
}

View File

@ -2,9 +2,13 @@ load("@io_bazel_rules_go//go:def.bzl", "go_test")
go_test(
name = "go_default_test",
srcs = ["ctl_convert_test.go"],
srcs = [
"ctl_convert_test.go",
"ctl_renew_test.go",
],
data = glob(["testdata/**"]),
deps = [
"//cmd/ctl/pkg/convert:go_default_library",
"//cmd/ctl/pkg/renew:go_default_library",
"//pkg/api/util:go_default_library",
"//pkg/apis/certmanager/v1alpha2:go_default_library",

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package certificates
package ctl
import (
"context"