blob: 7e02a183b7a8bdcf6b1bc57291cd3bac42c51bec [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2017 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package options
18
19import (
20 "github.com/spf13/pflag"
21
22 "k8s.io/apimachinery/pkg/runtime/serializer"
23 "k8s.io/apiserver/pkg/server"
24)
25
26type FeatureOptions struct {
27 EnableProfiling bool
28 EnableContentionProfiling bool
29 EnableSwaggerUI bool
30}
31
32func 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
42func (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
55func (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
67func (o *FeatureOptions) Validate() []error {
68 if o == nil {
69 return nil
70 }
71
72 errs := []error{}
73 return errs
74}