...

Source file src/k8s.io/component-base/logs/klogflags/klogflags.go

Documentation: k8s.io/component-base/logs/klogflags

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package klogflags
    18  
    19  import (
    20  	"flag"
    21  
    22  	"k8s.io/klog/v2"
    23  )
    24  
    25  // Init is a replacement for klog.InitFlags which only adds those flags
    26  // that are still supported for Kubernetes components (i.e. -v and -vmodule).
    27  // See
    28  // https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/2845-deprecate-klog-specific-flags-in-k8s-components.
    29  func Init(fs *flag.FlagSet) {
    30  	var allFlags flag.FlagSet
    31  	klog.InitFlags(&allFlags)
    32  	if fs == nil {
    33  		fs = flag.CommandLine
    34  	}
    35  	allFlags.VisitAll(func(f *flag.Flag) {
    36  		switch f.Name {
    37  		case "v", "vmodule":
    38  			fs.Var(f.Value, f.Name, f.Usage)
    39  		}
    40  	})
    41  }
    42  

View as plain text