Register logger flags

Signed-off-by: James Munnelly <jmunnelly@apple.com>
This commit is contained in:
James Munnelly 2021-10-21 18:18:48 +01:00
parent 97863d245f
commit 2e3eb29327
3 changed files with 44 additions and 3 deletions

View File

@ -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",
],

View File

@ -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)
}

View File

@ -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()))