@@ -14,31 +14,39 @@ 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
40
46
}
41
47
48
+ // NewCustomMetricsAdapterServerOptions creates a new instance of
49
+ // CustomMetricsAdapterServerOptions with its default values.
42
50
func NewCustomMetricsAdapterServerOptions () * CustomMetricsAdapterServerOptions {
43
51
o := & CustomMetricsAdapterServerOptions {
44
52
SecureServing : genericoptions .NewSecureServingOptions ().WithLoopback (),
@@ -51,14 +59,27 @@ func NewCustomMetricsAdapterServerOptions() *CustomMetricsAdapterServerOptions {
51
59
return o
52
60
}
53
61
54
- func (o CustomMetricsAdapterServerOptions ) Validate (args []string ) error {
55
- return nil
62
+ // Validate validates CustomMetricsAdapterServerOptions
63
+ func (o CustomMetricsAdapterServerOptions ) Validate () error {
64
+ errors := []error {}
65
+ errors = append (errors , o .SecureServing .Validate ()... )
66
+ errors = append (errors , o .Authentication .Validate ()... )
67
+ errors = append (errors , o .Authorization .Validate ()... )
68
+ errors = append (errors , o .Audit .Validate ()... )
69
+ errors = append (errors , o .Features .Validate ()... )
70
+ return utilerrors .NewAggregate (errors )
56
71
}
57
72
58
- func (o * CustomMetricsAdapterServerOptions ) Complete () error {
59
- return nil
73
+ // AddFlags adds the flags defined for the options, to the given flagset.
74
+ func (o * CustomMetricsAdapterServerOptions ) AddFlags (fs * pflag.FlagSet ) {
75
+ o .SecureServing .AddFlags (fs )
76
+ o .Authentication .AddFlags (fs )
77
+ o .Authorization .AddFlags (fs )
78
+ o .Audit .AddFlags (fs )
79
+ o .Features .AddFlags (fs )
60
80
}
61
81
82
+ // Config returns configuration for the API server given CustomMetricsAdapterServerOptions
62
83
func (o CustomMetricsAdapterServerOptions ) Config () (* apiserver.Config , error ) {
63
84
// TODO have a "real" external address (have an AdvertiseAddress?)
64
85
if err := o .SecureServing .MaybeDefaultWithSelfSignedCerts ("localhost" , nil , []net.IP {net .ParseIP ("127.0.0.1" )}); err != nil {
@@ -69,14 +90,12 @@ func (o CustomMetricsAdapterServerOptions) Config() (*apiserver.Config, error) {
69
90
if err := o .SecureServing .ApplyTo (& serverConfig .SecureServing , & serverConfig .LoopbackClientConfig ); err != nil {
70
91
return nil , err
71
92
}
72
-
73
93
if err := o .Authentication .ApplyTo (& serverConfig .Authentication , serverConfig .SecureServing , nil ); err != nil {
74
94
return nil , err
75
95
}
76
96
if err := o .Authorization .ApplyTo (& serverConfig .Authorization ); err != nil {
77
97
return nil , err
78
98
}
79
-
80
99
if err := o .Audit .ApplyTo (serverConfig ); err != nil {
81
100
return nil , err
82
101
}
0 commit comments