Skip to content

Commit

Permalink
Make webhook Logging options configurable using configfile.
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Aug 17, 2023
1 parent 240d3fc commit 6d31ed2
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 8 deletions.
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
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"
"k8s.io/component-base/logs"
)

// +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 logs.Options

// 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"`

// 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.

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

0 comments on commit 6d31ed2

Please sign in to comment.