diff --git a/cmd/webhook/app/options/BUILD.bazel b/cmd/webhook/app/options/BUILD.bazel index 114d757f1..34b828dd3 100644 --- a/cmd/webhook/app/options/BUILD.bazel +++ b/cmd/webhook/app/options/BUILD.bazel @@ -2,13 +2,17 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "go_default_library", - srcs = ["options.go"], + srcs = [ + "globalflags.go", + "options.go", + ], importpath = "github.com/jetstack/cert-manager/cmd/webhook/app/options", visibility = ["//visibility:public"], deps = [ "//internal/apis/config:go_default_library", "//internal/apis/config/scheme:go_default_library", "//pkg/apis/config/v1alpha1:go_default_library", + "//pkg/logs:go_default_library", "@com_github_spf13_pflag//:go_default_library", "@io_k8s_component_base//cli/flag:go_default_library", ], diff --git a/cmd/webhook/app/options/globalflags.go b/cmd/webhook/app/options/globalflags.go new file mode 100644 index 000000000..d442f267c --- /dev/null +++ b/cmd/webhook/app/options/globalflags.go @@ -0,0 +1,36 @@ +/* +Copyright 2021 The cert-manager Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package options + +import ( + "flag" + "os" + + "github.com/spf13/pflag" + + "github.com/jetstack/cert-manager/pkg/logs" +) + +func AddGlobalFlags(fs *pflag.FlagSet) { + addKlogFlags(fs) +} + +func addKlogFlags(fs *pflag.FlagSet) { + local := flag.NewFlagSet(os.Args[0], flag.ExitOnError) + logs.InitLogs(local) + fs.AddGoFlagSet(local) +} diff --git a/cmd/webhook/app/webhook.go b/cmd/webhook/app/webhook.go index 0f1a61fc3..f6fbdf62f 100644 --- a/cmd/webhook/app/webhook.go +++ b/cmd/webhook/app/webhook.go @@ -119,8 +119,8 @@ func NewServerCommand(stopCh <-chan struct{}) *cobra.Command { } cmd := &cobra.Command{ - Use: componentWebhook, - Short: fmt.Sprintf("Webhook component providing API validation, mutation and conversion functionality for cert-manager (%s) (%s)", util.AppVersion, util.AppGitCommit), + Use: componentWebhook, + Long: fmt.Sprintf("Webhook component providing API validation, mutation and conversion functionality for cert-manager (%s) (%s)", util.AppVersion, util.AppGitCommit), // The webhook has special flag parsing requirements to handle precedence of providing // configuration via versioned configuration files and flag values. // Setting DisableFlagParsing=true prevents Cobra from interfering with flag parsing @@ -168,6 +168,7 @@ func NewServerCommand(stopCh <-chan struct{}) *cobra.Command { webhookFlags.AddFlags(cleanFlagSet) options.AddConfigFlags(cleanFlagSet, webhookConfig) + options.AddGlobalFlags(cleanFlagSet) cleanFlagSet.BoolP("help", "h", false, fmt.Sprintf("help for %s", cmd.Name()))