further standardise logging across components

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
This commit is contained in:
Tim Ramlot 2023-05-04 12:16:39 +02:00
parent 5091a3bff4
commit f0871eb6b8
No known key found for this signature in database
GPG Key ID: 47428728E0C2878D
6 changed files with 15 additions and 10 deletions

View File

@ -17,9 +17,6 @@ limitations under the License.
package main
import (
"fmt"
"os"
"github.com/cert-manager/cert-manager/acmesolver-binary/app"
"github.com/cert-manager/cert-manager/internal/cmd/util"
logf "github.com/cert-manager/cert-manager/pkg/logs"
@ -39,7 +36,7 @@ func main() {
cmd := app.NewACMESolverCommand(stopCh)
if err := cmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
logf.Log.Error(err, "error executing command")
util.SetExitCode(err)
}
}

View File

@ -39,11 +39,10 @@ func main() {
ctrl.SetLogger(logf.Log)
ctx := util.ContextWithStopCh(context.Background(), stopCh)
cmd := app.NewCommandStartInjectorController(ctx, os.Stdout, os.Stderr)
if err := cmd.Execute(); err != nil {
cmd.PrintErrln(err)
logf.Log.Error(err, "error executing command")
util.SetExitCode(err)
}
}

View File

@ -32,7 +32,7 @@ func main() {
cmd := app.NewCommandStartCertManagerController(stopCh)
if err := cmd.Execute(); err != nil {
logf.Log.Error(err, "error while executing")
logf.Log.Error(err, "error executing command")
util.SetExitCode(err)
}
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package cmd
import (
"flag"
"os"
"runtime"
@ -46,7 +45,7 @@ func RunWebhookServer(groupName string, hooks ...webhook.Solver) {
}
cmd := server.NewCommandStartWebhookServer(os.Stdout, os.Stderr, stopCh, groupName, hooks...)
cmd.Flags().AddGoFlagSet(flag.CommandLine)
if err := cmd.Execute(); err != nil {
logf.Log.Error(err, "error executing command")
util.SetExitCode(err)

View File

@ -25,15 +25,19 @@ import (
genericapiserver "k8s.io/apiserver/pkg/server"
genericoptions "k8s.io/apiserver/pkg/server/options"
"k8s.io/component-base/logs"
"github.com/cert-manager/cert-manager/pkg/acme/webhook"
whapi "github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
"github.com/cert-manager/cert-manager/pkg/acme/webhook/apiserver"
logf "github.com/cert-manager/cert-manager/pkg/logs"
)
const defaultEtcdPathPrefix = "/registry/acme.cert-manager.io"
type WebhookServerOptions struct {
Logging *logs.Options
RecommendedOptions *genericoptions.RecommendedOptions
SolverGroup string
@ -45,6 +49,8 @@ type WebhookServerOptions struct {
func NewWebhookServerOptions(out, errOut io.Writer, groupName string, solvers ...webhook.Solver) *WebhookServerOptions {
o := &WebhookServerOptions{
Logging: logs.NewOptions(),
// TODO we will nil out the etcd storage options. This requires a later level of k8s.io/apiserver
RecommendedOptions: genericoptions.NewRecommendedOptions(
defaultEtcdPathPrefix,
@ -84,12 +90,17 @@ func NewCommandStartWebhookServer(out, errOut io.Writer, stopCh <-chan struct{},
}
flags := cmd.Flags()
logf.AddFlags(o.Logging, flags)
o.RecommendedOptions.AddFlags(flags)
return cmd
}
func (o WebhookServerOptions) Validate(args []string) error {
if err := logf.ValidateAndApply(o.Logging); err != nil {
return err
}
return nil
}

View File

@ -82,7 +82,6 @@ func AddFlags(opts *logs.Options, fs *pflag.FlagSet) {
}
})
}
_ = fs.Set("logtostderr", "true")
{
var allFlags pflag.FlagSet