mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
rebase: update kubernetes to 1.28.0 in main
updating kubernetes to 1.28.0 in the main repo. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
b2fdc269c3
commit
ff3e84ad67
101
vendor/k8s.io/component-base/logs/api/v1/options.go
generated
vendored
101
vendor/k8s.io/component-base/logs/api/v1/options.go
generated
vendored
@ -17,14 +17,17 @@ limitations under the License.
|
||||
package v1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
@ -57,6 +60,24 @@ func NewLoggingConfiguration() *LoggingConfiguration {
|
||||
return &c
|
||||
}
|
||||
|
||||
// Applying configurations multiple times is not safe unless it's guaranteed that there
|
||||
// are no goroutines which might call logging functions. The default for ValidateAndApply
|
||||
// and ValidateAndApplyWithOptions is to return an error when called more than once.
|
||||
// Binaries and unit tests can override that behavior.
|
||||
var ReapplyHandling = ReapplyHandlingError
|
||||
|
||||
type ReapplyHandlingType int
|
||||
|
||||
const (
|
||||
// ReapplyHandlingError is the default: calling ValidateAndApply or
|
||||
// ValidateAndApplyWithOptions again returns an error.
|
||||
ReapplyHandlingError ReapplyHandlingType = iota
|
||||
// ReapplyHandlingIgnoreUnchanged silently ignores any additional calls of
|
||||
// ValidateAndApply or ValidateAndApplyWithOptions if the configuration
|
||||
// is unchanged, otherwise they return an error.
|
||||
ReapplyHandlingIgnoreUnchanged
|
||||
)
|
||||
|
||||
// ValidateAndApply combines validation and application of the logging configuration.
|
||||
// This should be invoked as early as possible because then the rest of the program
|
||||
// startup (including validation of other options) will already run with the final
|
||||
@ -64,6 +85,10 @@ func NewLoggingConfiguration() *LoggingConfiguration {
|
||||
//
|
||||
// The optional FeatureGate controls logging features. If nil, the default for
|
||||
// these features is used.
|
||||
//
|
||||
// Logging options must be applied as early as possible during the program
|
||||
// startup. Some changes are global and cannot be done safely when there are
|
||||
// already goroutines running.
|
||||
func ValidateAndApply(c *LoggingConfiguration, featureGate featuregate.FeatureGate) error {
|
||||
return validateAndApply(c, nil, featureGate, nil)
|
||||
}
|
||||
@ -71,6 +96,10 @@ func ValidateAndApply(c *LoggingConfiguration, featureGate featuregate.FeatureGa
|
||||
// ValidateAndApplyWithOptions is a variant of ValidateAndApply which accepts
|
||||
// additional options beyond those that can be configured through the API. This
|
||||
// is meant for testing.
|
||||
//
|
||||
// Logging options must be applied as early as possible during the program
|
||||
// startup. Some changes are global and cannot be done safely when there are
|
||||
// already goroutines running.
|
||||
func ValidateAndApplyWithOptions(c *LoggingConfiguration, options *LoggingOptions, featureGate featuregate.FeatureGate) error {
|
||||
return validateAndApply(c, options, featureGate, nil)
|
||||
}
|
||||
@ -183,10 +212,30 @@ func featureEnabled(featureGate featuregate.FeatureGate, feature featuregate.Fea
|
||||
}
|
||||
|
||||
func apply(c *LoggingConfiguration, options *LoggingOptions, featureGate featuregate.FeatureGate) error {
|
||||
contextualLoggingEnabled := contextualLoggingDefault
|
||||
if featureGate != nil {
|
||||
contextualLoggingEnabled = featureGate.Enabled(ContextualLogging)
|
||||
p := ¶meters{
|
||||
C: c,
|
||||
Options: options,
|
||||
ContextualLoggingEnabled: contextualLoggingDefault,
|
||||
}
|
||||
if featureGate != nil {
|
||||
p.ContextualLoggingEnabled = featureGate.Enabled(ContextualLogging)
|
||||
}
|
||||
|
||||
oldP := applyParameters.Load()
|
||||
if oldP != nil {
|
||||
switch ReapplyHandling {
|
||||
case ReapplyHandlingError:
|
||||
return errors.New("logging configuration was already applied earlier, changing it is not allowed")
|
||||
case ReapplyHandlingIgnoreUnchanged:
|
||||
if diff := cmp.Diff(oldP, p); diff != "" {
|
||||
return fmt.Errorf("the logging configuration should not be changed after setting it once (- old setting, + new setting):\n%s", diff)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("invalid value %d for ReapplyHandling", ReapplyHandling)
|
||||
}
|
||||
}
|
||||
applyParameters.Store(p)
|
||||
|
||||
// if log format not exists, use nil loggr
|
||||
format, _ := logRegistry.get(c.Format)
|
||||
@ -205,7 +254,7 @@ func apply(c *LoggingConfiguration, options *LoggingOptions, featureGate feature
|
||||
defer setverbositylevel.Mutex.Unlock()
|
||||
setverbositylevel.Callbacks = append(setverbositylevel.Callbacks, control.SetVerbosityLevel)
|
||||
}
|
||||
klog.SetLoggerWithOptions(log, klog.ContextualLogger(contextualLoggingEnabled), klog.FlushLogger(control.Flush))
|
||||
klog.SetLoggerWithOptions(log, klog.ContextualLogger(p.ContextualLoggingEnabled), klog.FlushLogger(control.Flush))
|
||||
}
|
||||
if err := loggingFlags.Lookup("v").Value.Set(VerbosityLevelPflag(&c.Verbosity).String()); err != nil {
|
||||
return fmt.Errorf("internal error while setting klog verbosity: %v", err)
|
||||
@ -213,8 +262,41 @@ func apply(c *LoggingConfiguration, options *LoggingOptions, featureGate feature
|
||||
if err := loggingFlags.Lookup("vmodule").Value.Set(VModuleConfigurationPflag(&c.VModule).String()); err != nil {
|
||||
return fmt.Errorf("internal error while setting klog vmodule: %v", err)
|
||||
}
|
||||
klog.StartFlushDaemon(c.FlushFrequency)
|
||||
klog.EnableContextualLogging(contextualLoggingEnabled)
|
||||
klog.StartFlushDaemon(c.FlushFrequency.Duration.Duration)
|
||||
klog.EnableContextualLogging(p.ContextualLoggingEnabled)
|
||||
return nil
|
||||
}
|
||||
|
||||
type parameters struct {
|
||||
C *LoggingConfiguration
|
||||
Options *LoggingOptions
|
||||
ContextualLoggingEnabled bool
|
||||
}
|
||||
|
||||
var applyParameters atomic.Pointer[parameters]
|
||||
|
||||
// ResetForTest restores the default settings. This is not thread-safe and should only
|
||||
// be used when there are no goroutines running. The intended users are unit
|
||||
// tests in other packages.
|
||||
func ResetForTest(featureGate featuregate.FeatureGate) error {
|
||||
oldP := applyParameters.Load()
|
||||
if oldP == nil {
|
||||
// Nothing to do.
|
||||
return nil
|
||||
}
|
||||
|
||||
// This makes it possible to call apply again without triggering errors.
|
||||
applyParameters.Store(nil)
|
||||
|
||||
// Restore defaults. Shouldn't fail, but check anyway.
|
||||
config := NewLoggingConfiguration()
|
||||
if err := ValidateAndApply(config, featureGate); err != nil {
|
||||
return fmt.Errorf("apply default configuration: %v", err)
|
||||
}
|
||||
|
||||
// And again...
|
||||
applyParameters.Store(nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -260,7 +342,7 @@ func addFlags(c *LoggingConfiguration, fs flagSet) {
|
||||
// No new log formats should be added after generation is of flag options
|
||||
logRegistry.freeze()
|
||||
|
||||
fs.DurationVar(&c.FlushFrequency, LogFlushFreqFlagName, c.FlushFrequency, "Maximum number of seconds between log flushes")
|
||||
fs.DurationVar(&c.FlushFrequency.Duration.Duration, LogFlushFreqFlagName, c.FlushFrequency.Duration.Duration, "Maximum number of seconds between log flushes")
|
||||
fs.VarP(VerbosityLevelPflag(&c.Verbosity), "v", "v", "number for the log level verbosity")
|
||||
fs.Var(VModuleConfigurationPflag(&c.VModule), "vmodule", "comma-separated list of pattern=N settings for file-filtered logging (only works for text log format)")
|
||||
|
||||
@ -282,8 +364,9 @@ func SetRecommendedLoggingConfiguration(c *LoggingConfiguration) {
|
||||
if c.Format == "" {
|
||||
c.Format = "text"
|
||||
}
|
||||
if c.FlushFrequency == 0 {
|
||||
c.FlushFrequency = LogFlushFreqDefault
|
||||
if c.FlushFrequency.Duration.Duration == 0 {
|
||||
c.FlushFrequency.Duration.Duration = LogFlushFreqDefault
|
||||
c.FlushFrequency.SerializeAsString = true
|
||||
}
|
||||
var empty resource.QuantityValue
|
||||
if c.Options.JSON.InfoBufferSize == empty {
|
||||
|
10
vendor/k8s.io/component-base/logs/api/v1/registry.go
generated
vendored
10
vendor/k8s.io/component-base/logs/api/v1/registry.go
generated
vendored
@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
|
||||
@ -30,6 +31,7 @@ var logRegistry = newLogFormatRegistry()
|
||||
|
||||
// logFormatRegistry stores factories for all supported logging formats.
|
||||
type logFormatRegistry struct {
|
||||
mutex sync.Mutex
|
||||
registry map[string]logFormat
|
||||
frozen bool
|
||||
}
|
||||
@ -83,6 +85,8 @@ func newLogFormatRegistry() *logFormatRegistry {
|
||||
|
||||
// register adds a new log format. It's an error to modify an existing one.
|
||||
func (lfr *logFormatRegistry) register(name string, format logFormat) error {
|
||||
lfr.mutex.Lock()
|
||||
defer lfr.mutex.Unlock()
|
||||
if lfr.frozen {
|
||||
return fmt.Errorf("log format registry is frozen, unable to register log format %s", name)
|
||||
}
|
||||
@ -98,6 +102,8 @@ func (lfr *logFormatRegistry) register(name string, format logFormat) error {
|
||||
|
||||
// get specified log format factory
|
||||
func (lfr *logFormatRegistry) get(name string) (*logFormat, error) {
|
||||
lfr.mutex.Lock()
|
||||
defer lfr.mutex.Unlock()
|
||||
format, ok := lfr.registry[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("log format: %s does not exists", name)
|
||||
@ -107,6 +113,8 @@ func (lfr *logFormatRegistry) get(name string) (*logFormat, error) {
|
||||
|
||||
// list names of registered log formats, including feature gates (sorted)
|
||||
func (lfr *logFormatRegistry) list() string {
|
||||
lfr.mutex.Lock()
|
||||
defer lfr.mutex.Unlock()
|
||||
formats := make([]string, 0, len(lfr.registry))
|
||||
for name, format := range lfr.registry {
|
||||
item := fmt.Sprintf(`"%s"`, name)
|
||||
@ -121,5 +129,7 @@ func (lfr *logFormatRegistry) list() string {
|
||||
|
||||
// freeze prevents further modifications of the registered log formats.
|
||||
func (lfr *logFormatRegistry) freeze() {
|
||||
lfr.mutex.Lock()
|
||||
defer lfr.mutex.Unlock()
|
||||
lfr.frozen = true
|
||||
}
|
||||
|
44
vendor/k8s.io/component-base/logs/api/v1/types.go
generated
vendored
44
vendor/k8s.io/component-base/logs/api/v1/types.go
generated
vendored
@ -17,9 +17,11 @@ limitations under the License.
|
||||
package v1
|
||||
|
||||
import (
|
||||
"time"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// Supported output formats.
|
||||
@ -39,10 +41,11 @@ type LoggingConfiguration struct {
|
||||
// Format Flag specifies the structure of log messages.
|
||||
// default value of format is `text`
|
||||
Format string `json:"format,omitempty"`
|
||||
// Maximum number of nanoseconds (i.e. 1s = 1000000000) between log
|
||||
// flushes. Ignored if the selected logging backend writes log
|
||||
// messages without buffering.
|
||||
FlushFrequency time.Duration `json:"flushFrequency"`
|
||||
// Maximum time between log flushes.
|
||||
// If a string, parsed as a duration (i.e. "1s")
|
||||
// If an int, the maximum number of nanoseconds (i.e. 1s = 1000000000).
|
||||
// Ignored if the selected logging backend writes log messages without buffering.
|
||||
FlushFrequency TimeOrMetaDuration `json:"flushFrequency"`
|
||||
// Verbosity is the threshold that determines which log messages are
|
||||
// logged. Default is zero which logs only the most important
|
||||
// messages. Higher values enable additional messages. Error messages
|
||||
@ -58,6 +61,37 @@ type LoggingConfiguration struct {
|
||||
Options FormatOptions `json:"options,omitempty"`
|
||||
}
|
||||
|
||||
// TimeOrMetaDuration is present only for backwards compatibility for the
|
||||
// flushFrequency field, and new fields should use metav1.Duration.
|
||||
type TimeOrMetaDuration struct {
|
||||
// Duration holds the duration
|
||||
Duration metav1.Duration
|
||||
// SerializeAsString controls whether the value is serialized as a string or an integer
|
||||
SerializeAsString bool `json:"-"`
|
||||
}
|
||||
|
||||
func (t TimeOrMetaDuration) MarshalJSON() ([]byte, error) {
|
||||
if t.SerializeAsString {
|
||||
return t.Duration.MarshalJSON()
|
||||
} else {
|
||||
// Marshal as integer for backwards compatibility
|
||||
return json.Marshal(t.Duration.Duration)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TimeOrMetaDuration) UnmarshalJSON(b []byte) error {
|
||||
if len(b) > 0 && b[0] == '"' {
|
||||
// string values unmarshal as metav1.Duration
|
||||
t.SerializeAsString = true
|
||||
return json.Unmarshal(b, &t.Duration)
|
||||
}
|
||||
t.SerializeAsString = false
|
||||
if err := json.Unmarshal(b, &t.Duration.Duration); err != nil {
|
||||
return fmt.Errorf("invalid duration %q: %w", string(b), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FormatOptions contains options for the different logging formats.
|
||||
type FormatOptions struct {
|
||||
// [Alpha] JSON contains options for logging format "json".
|
||||
|
18
vendor/k8s.io/component-base/logs/api/v1/zz_generated.deepcopy.go
generated
vendored
18
vendor/k8s.io/component-base/logs/api/v1/zz_generated.deepcopy.go
generated
vendored
@ -58,6 +58,7 @@ func (in *JSONOptions) DeepCopy() *JSONOptions {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *LoggingConfiguration) DeepCopyInto(out *LoggingConfiguration) {
|
||||
*out = *in
|
||||
out.FlushFrequency = in.FlushFrequency
|
||||
if in.VModule != nil {
|
||||
in, out := &in.VModule, &out.VModule
|
||||
*out = make(VModuleConfiguration, len(*in))
|
||||
@ -77,6 +78,23 @@ func (in *LoggingConfiguration) DeepCopy() *LoggingConfiguration {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *TimeOrMetaDuration) DeepCopyInto(out *TimeOrMetaDuration) {
|
||||
*out = *in
|
||||
out.Duration = in.Duration
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TimeOrMetaDuration.
|
||||
func (in *TimeOrMetaDuration) DeepCopy() *TimeOrMetaDuration {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(TimeOrMetaDuration)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in VModuleConfiguration) DeepCopyInto(out *VModuleConfiguration) {
|
||||
{
|
||||
|
Reference in New Issue
Block a user