diff --git a/.gitignore b/.gitignore index a264827f4..7b3af179f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /acmesolver /controller /ingress-shim +/ctl /hack/build/dockerfiles/cert-manager-*_*_* .vscode .venv diff --git a/cmd/ctl/BUILD.bazel b/cmd/ctl/BUILD.bazel index f88c743a0..bf237106e 100644 --- a/cmd/ctl/BUILD.bazel +++ b/cmd/ctl/BUILD.bazel @@ -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( diff --git a/cmd/ctl/cmd/BUILD.bazel b/cmd/ctl/cmd/BUILD.bazel index 5598b4f17..be6c2bd27 100644 --- a/cmd/ctl/cmd/BUILD.bazel +++ b/cmd/ctl/cmd/BUILD.bazel @@ -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", ], ) diff --git a/cmd/ctl/cmd/cmd.go b/cmd/ctl/cmd/cmd.go index ebaf09e34..2b2ddabb1 100644 --- a/cmd/ctl/cmd/cmd.go +++ b/cmd/ctl/cmd/cmd.go @@ -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 } diff --git a/cmd/ctl/pkg/renew/BUILD.bazel b/cmd/ctl/pkg/renew/BUILD.bazel index 8932c07e3..004d314f9 100644 --- a/cmd/ctl/pkg/renew/BUILD.bazel +++ b/cmd/ctl/pkg/renew/BUILD.bazel @@ -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", diff --git a/cmd/ctl/pkg/renew/renew.go b/cmd/ctl/pkg/renew/renew.go index 53d92bf1d..716e521ce 100644 --- a/cmd/ctl/pkg/renew/renew.go +++ b/cmd/ctl/pkg/renew/renew.go @@ -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 } diff --git a/test/integration/ctl/BUILD.bazel b/test/integration/ctl/BUILD.bazel index 851e61234..d9fa7849e 100644 --- a/test/integration/ctl/BUILD.bazel +++ b/test/integration/ctl/BUILD.bazel @@ -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", diff --git a/test/integration/ctl/ctl_renew_test.go b/test/integration/ctl/ctl_renew_test.go index d6f7827c1..02baebd62 100644 --- a/test/integration/ctl/ctl_renew_test.go +++ b/test/integration/ctl/ctl_renew_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package certificates +package ctl import ( "context"