Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2017 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 options |
| 18 | |
| 19 | import ( |
| 20 | "github.com/spf13/pflag" |
| 21 | |
| 22 | "k8s.io/apimachinery/pkg/runtime/serializer" |
| 23 | "k8s.io/apiserver/pkg/server" |
| 24 | ) |
| 25 | |
| 26 | type FeatureOptions struct { |
| 27 | EnableProfiling bool |
| 28 | EnableContentionProfiling bool |
| 29 | EnableSwaggerUI bool |
| 30 | } |
| 31 | |
| 32 | func NewFeatureOptions() *FeatureOptions { |
| 33 | defaults := server.NewConfig(serializer.CodecFactory{}) |
| 34 | |
| 35 | return &FeatureOptions{ |
| 36 | EnableProfiling: defaults.EnableProfiling, |
| 37 | EnableContentionProfiling: defaults.EnableContentionProfiling, |
| 38 | EnableSwaggerUI: defaults.EnableSwaggerUI, |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet) { |
| 43 | if o == nil { |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | fs.BoolVar(&o.EnableProfiling, "profiling", o.EnableProfiling, |
| 48 | "Enable profiling via web interface host:port/debug/pprof/") |
| 49 | fs.BoolVar(&o.EnableContentionProfiling, "contention-profiling", o.EnableContentionProfiling, |
| 50 | "Enable lock contention profiling, if profiling is enabled") |
| 51 | fs.BoolVar(&o.EnableSwaggerUI, "enable-swagger-ui", o.EnableSwaggerUI, |
| 52 | "Enables swagger ui on the apiserver at /swagger-ui") |
| 53 | } |
| 54 | |
| 55 | func (o *FeatureOptions) ApplyTo(c *server.Config) error { |
| 56 | if o == nil { |
| 57 | return nil |
| 58 | } |
| 59 | |
| 60 | c.EnableProfiling = o.EnableProfiling |
| 61 | c.EnableContentionProfiling = o.EnableContentionProfiling |
| 62 | c.EnableSwaggerUI = o.EnableSwaggerUI |
| 63 | |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | func (o *FeatureOptions) Validate() []error { |
| 68 | if o == nil { |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | errs := []error{} |
| 73 | return errs |
| 74 | } |