Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move logging options to webhook config file #6243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/webhook/app/webhook.go
Expand Up @@ -95,7 +95,7 @@ func NewServerCommand(stopCh <-chan struct{}) *cobra.Command {
os.Exit(1)
}

if err := logf.ValidateAndApply(webhookFlags.Logging); err != nil {
if err := logf.ValidateAndApply(&webhookConfig.Logging); err != nil {
log.Error(err, "Failed to validate webhook flags")
os.Exit(1)
}
Expand All @@ -117,6 +117,11 @@ func NewServerCommand(stopCh <-chan struct{}) *cobra.Command {
log.Error(err, "Failed to set feature gates from config file")
os.Exit(1)
}

if err := logf.ValidateAndApply(&webhookConfig.Logging); err != nil {
log.Error(err, "Failed to validate webhook flags")
os.Exit(1)
}
}

srv, err := cmwebhook.NewCertManagerWebhookServer(log, *webhookConfig)
Expand Down
5 changes: 2 additions & 3 deletions internal/apis/config/controller/types.go
Expand Up @@ -19,9 +19,8 @@ package controller
import (
"time"

"k8s.io/component-base/logs"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logsapi "k8s.io/component-base/logs/api/v1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -110,7 +109,7 @@ type ControllerConfiguration struct {
PprofAddress string

// https://pkg.go.dev/k8s.io/component-base@v0.27.3/logs/api/v1#LoggingConfiguration
Logging logs.Options
Logging logsapi.LoggingConfiguration

// featureGates is a map of feature names to bools that enable or disable experimental
// features.
Expand Down
3 changes: 3 additions & 0 deletions internal/apis/config/webhook/fuzzer/fuzzer.go
Expand Up @@ -19,6 +19,7 @@ package fuzzer
import (
fuzz "github.com/google/gofuzz"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
logsapi "k8s.io/component-base/logs/api/v1"

"github.com/cert-manager/cert-manager/internal/apis/config/webhook"
)
Expand All @@ -32,6 +33,8 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
if s.PprofAddress == "" {
s.PprofAddress = "something:1234"
}

logsapi.SetRecommendedLoggingConfiguration(&s.Logging)
},
}
}
4 changes: 4 additions & 0 deletions internal/apis/config/webhook/types.go
Expand Up @@ -18,6 +18,7 @@ package webhook

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logsapi "k8s.io/component-base/logs/api/v1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -53,6 +54,9 @@ type WebhookConfiguration struct {
// Defaults to 'localhost:6060'.
PprofAddress string

// https://pkg.go.dev/k8s.io/component-base@v0.27.3/logs/api/v1#LoggingConfiguration
Logging logsapi.LoggingConfiguration

// featureGates is a map of feature names to bools that enable or disable experimental
// features.
// Default: nil
Expand Down
3 changes: 3 additions & 0 deletions internal/apis/config/webhook/v1alpha1/defaults.go
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime"
logsapi "k8s.io/component-base/logs/api/v1"
"k8s.io/utils/pointer"

"github.com/cert-manager/cert-manager/pkg/apis/config/webhook/v1alpha1"
Expand All @@ -37,4 +38,6 @@ func SetDefaults_WebhookConfiguration(obj *v1alpha1.WebhookConfiguration) {
if obj.PprofAddress == "" {
obj.PprofAddress = "localhost:6060"
}

logsapi.SetRecommendedLoggingConfiguration(&obj.Logging)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/apis/config/webhook/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/config/webhook/v1alpha1/types.go
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logsapi "k8s.io/component-base/logs/api/v1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -53,6 +54,10 @@ type WebhookConfiguration struct {
// Defaults to 'localhost:6060'.
PprofAddress string `json:"pprofAddress,omitempty"`

// logging configures the logging behaviour of the webhook.
// https://pkg.go.dev/k8s.io/component-base@v0.27.3/logs/api/v1#LoggingConfiguration
Logging logsapi.LoggingConfiguration `json:"logging"`
Comment on lines +57 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, the the Kubernetes API documentation contains a broken link:

logging [Required] LoggingConfiguration

logging specifies the options of logging. Refer to Logs Options for more information. Default: Format: text


// featureGates is a map of feature names to bools that enable or disable experimental
// features.
// Default: nil
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/config/webhook/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/logs/logs.go
Expand Up @@ -68,7 +68,7 @@ func InitLogs() {
log.SetFlags(0)
}

func AddFlagsNonDeprecated(opts *logs.Options, fs *pflag.FlagSet) {
func AddFlagsNonDeprecated(opts *logsapi.LoggingConfiguration, fs *pflag.FlagSet) {
var allFlags pflag.FlagSet
logsapi.AddFlags(opts, &allFlags)

Expand All @@ -80,7 +80,7 @@ func AddFlagsNonDeprecated(opts *logs.Options, fs *pflag.FlagSet) {
})
}

func AddFlags(opts *logs.Options, fs *pflag.FlagSet) {
func AddFlags(opts *logsapi.LoggingConfiguration, fs *pflag.FlagSet) {
var allFlags flag.FlagSet
klog.InitFlags(&allFlags)

Expand All @@ -95,7 +95,7 @@ func AddFlags(opts *logs.Options, fs *pflag.FlagSet) {
AddFlagsNonDeprecated(opts, fs)
}

func ValidateAndApply(opts *logs.Options) error {
func ValidateAndApply(opts *logsapi.LoggingConfiguration) error {
return logsapi.ValidateAndApply(opts, nil)
}

Expand Down
10 changes: 3 additions & 7 deletions pkg/webhook/options/options.go
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/spf13/pflag"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"

config "github.com/cert-manager/cert-manager/internal/apis/config/webhook"
configscheme "github.com/cert-manager/cert-manager/internal/apis/config/webhook/scheme"
Expand All @@ -32,21 +31,16 @@ import (

// WebhookFlags defines options that can only be configured via flags.
type WebhookFlags struct {
Logging *logs.Options

// Path to a file containing a WebhookConfiguration resource
Config string
}

func NewWebhookFlags() *WebhookFlags {
return &WebhookFlags{
Logging: logs.NewOptions(),
}
return &WebhookFlags{}
}

func (f *WebhookFlags) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&f.Config, "config", "", "Path to a file containing a WebhookConfiguration object used to configure the webhook")
logf.AddFlags(f.Logging, fs)
}

func NewWebhookConfiguration() (*config.WebhookConfiguration, error) {
Expand Down Expand Up @@ -93,4 +87,6 @@ func AddConfigFlags(fs *pflag.FlagSet, c *config.WebhookConfiguration) {
"Possible values: "+strings.Join(tlsPossibleVersions, ", "))
fs.Var(cliflag.NewMapStringBool(&c.FeatureGates), "feature-gates", "A set of key=value pairs that describe feature gates for alpha/experimental features. "+
"Options are:\n"+strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n"))

logf.AddFlags(&c.Logging, fs)
}