@@ -14,51 +14,75 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
+ // Package server provides configuration options for the metrics API server.
17
18
package server
18
19
19
20
import (
20
21
"fmt"
21
22
"net"
22
23
24
+ "github.com/spf13/pflag"
25
+
26
+ utilerrors "k8s.io/apimachinery/pkg/util/errors"
23
27
genericapiserver "k8s.io/apiserver/pkg/server"
24
28
genericoptions "k8s.io/apiserver/pkg/server/options"
25
29
openapicommon "k8s.io/kube-openapi/pkg/common"
26
30
27
31
"sigs.k8s.io/custom-metrics-apiserver/pkg/apiserver"
28
32
)
29
33
34
+ // CustomMetricsAdapterServerOptions contains the of options used to configure
35
+ // the metrics API server.
36
+ //
37
+ // It is based on a subset of [genericoptions.RecommendedOptions].
30
38
type CustomMetricsAdapterServerOptions struct {
31
- // genericoptions.ReccomendedOptions - EtcdOptions
32
39
SecureServing * genericoptions.SecureServingOptionsWithLoopback
33
40
Authentication * genericoptions.DelegatingAuthenticationOptions
34
41
Authorization * genericoptions.DelegatingAuthorizationOptions
35
42
Audit * genericoptions.AuditOptions
36
43
Features * genericoptions.FeatureOptions
37
44
38
- // OpenAPIConfig
39
45
OpenAPIConfig * openapicommon.Config
46
+ EnableMetrics bool
40
47
}
41
48
49
+ // NewCustomMetricsAdapterServerOptions creates a new instance of
50
+ // CustomMetricsAdapterServerOptions with its default values.
42
51
func NewCustomMetricsAdapterServerOptions () * CustomMetricsAdapterServerOptions {
43
52
o := & CustomMetricsAdapterServerOptions {
44
53
SecureServing : genericoptions .NewSecureServingOptions ().WithLoopback (),
45
54
Authentication : genericoptions .NewDelegatingAuthenticationOptions (),
46
55
Authorization : genericoptions .NewDelegatingAuthorizationOptions (),
47
56
Audit : genericoptions .NewAuditOptions (),
48
57
Features : genericoptions .NewFeatureOptions (),
58
+
59
+ EnableMetrics : true ,
49
60
}
50
61
51
62
return o
52
63
}
53
64
54
- func (o CustomMetricsAdapterServerOptions ) Validate (args []string ) error {
55
- return nil
65
+ // Validate validates CustomMetricsAdapterServerOptions
66
+ func (o CustomMetricsAdapterServerOptions ) Validate () error {
67
+ errors := []error {}
68
+ errors = append (errors , o .SecureServing .Validate ()... )
69
+ errors = append (errors , o .Authentication .Validate ()... )
70
+ errors = append (errors , o .Authorization .Validate ()... )
71
+ errors = append (errors , o .Audit .Validate ()... )
72
+ errors = append (errors , o .Features .Validate ()... )
73
+ return utilerrors .NewAggregate (errors )
56
74
}
57
75
58
- func (o * CustomMetricsAdapterServerOptions ) Complete () error {
59
- return nil
76
+ // AddFlags adds the flags defined for the options, to the given flagset.
77
+ func (o * CustomMetricsAdapterServerOptions ) AddFlags (fs * pflag.FlagSet ) {
78
+ o .SecureServing .AddFlags (fs )
79
+ o .Authentication .AddFlags (fs )
80
+ o .Authorization .AddFlags (fs )
81
+ o .Audit .AddFlags (fs )
82
+ o .Features .AddFlags (fs )
60
83
}
61
84
85
+ // Config returns configuration for the API server given CustomMetricsAdapterServerOptions
62
86
func (o CustomMetricsAdapterServerOptions ) Config () (* apiserver.Config , error ) {
63
87
// TODO have a "real" external address (have an AdvertiseAddress?)
64
88
if err := o .SecureServing .MaybeDefaultWithSelfSignedCerts ("localhost" , nil , []net.IP {net .ParseIP ("127.0.0.1" )}); err != nil {
@@ -69,23 +93,26 @@ func (o CustomMetricsAdapterServerOptions) Config() (*apiserver.Config, error) {
69
93
if err := o .SecureServing .ApplyTo (& serverConfig .SecureServing , & serverConfig .LoopbackClientConfig ); err != nil {
70
94
return nil , err
71
95
}
72
-
73
96
if err := o .Authentication .ApplyTo (& serverConfig .Authentication , serverConfig .SecureServing , nil ); err != nil {
74
97
return nil , err
75
98
}
76
99
if err := o .Authorization .ApplyTo (& serverConfig .Authorization ); err != nil {
77
100
return nil , err
78
101
}
79
-
80
102
if err := o .Audit .ApplyTo (serverConfig ); err != nil {
81
103
return nil , err
82
104
}
105
+ if err := o .Features .ApplyTo (serverConfig ); err != nil {
106
+ return nil , err
107
+ }
83
108
84
109
// enable OpenAPI schemas
85
110
if o .OpenAPIConfig != nil {
86
111
serverConfig .OpenAPIConfig = o .OpenAPIConfig
87
112
}
88
113
114
+ serverConfig .EnableMetrics = o .EnableMetrics
115
+
89
116
config := & apiserver.Config {
90
117
GenericConfig : serverConfig ,
91
118
}
0 commit comments