@@ -14,7 +14,6 @@ import (
1414 "k8s.io/client-go/rest"
1515 "k8s.io/client-go/tools/clientcmd"
1616 clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
17- "k8s.io/utils/ptr"
1817 ctrl "sigs.k8s.io/controller-runtime"
1918 "sigs.k8s.io/controller-runtime/pkg/client"
2019 "sigs.k8s.io/controller-runtime/pkg/metrics/filters"
@@ -39,20 +38,14 @@ type GCPProvider struct {
3938 DownstreamResourceManagement DownstreamResourceManagementConfig `json:"downstreamResourceManagement"`
4039
4140 // LocationClassName configures the operator to only consider resources
42- // attached to locations with the specified location class. Defaults to
43- // "self-managed".
41+ // attached to locations with the specified location class.
4442 //
4543 // TODO(jreese) move to an approach similar to GatewayClass, where a controller
4644 // manager is associated with each class, and this will define the controller.
45+ // +default="self-managed"
4746 LocationClassName string `json:"locationClassName"`
4847}
4948
50- func SetDefaults_GCPProvider (obj * GCPProvider ) {
51- if obj .LocationClassName == "" {
52- obj .LocationClassName = "self-managed"
53- }
54- }
55-
5649// +k8s:deepcopy-gen=true
5750
5851type WebhookServerConfig struct {
@@ -61,18 +54,26 @@ type WebhookServerConfig struct {
6154 Host string `json:"host"`
6255
6356 // Port is the port number that the server will serve.
64- // It will be defaulted to 9443 if unspecified.
57+ // +default= 9443
6558 Port int `json:"port"`
6659
6760 // TLS is the TLS configuration for the webhook server, allowing configuration
6861 // of what path to find a certificate and key in, and what file names to use.
62+ //
63+ // The CertDir field will be defaulted to <temp-dir>/k8s-webhook-server/serving-certs.
6964 TLS TLSConfig `json:"tls"`
7065
7166 // ClientCAName is the CA certificate name which server used to verify remote(client)'s certificate.
7267 // Defaults to "", which means server does not verify client's certificate.
7368 ClientCAName string `json:"clientCAName"`
7469}
7570
71+ func SetDefaults_WebhookServerConfig (obj * WebhookServerConfig ) {
72+ if obj .TLS .CertDir == "" {
73+ obj .TLS .CertDir = filepath .Join (os .TempDir (), "k8s-webhook-server" , "serving-certs" )
74+ }
75+ }
76+
7677func (c * WebhookServerConfig ) Options (ctx context.Context , secretsClient client.Client ) webhook.Options {
7778 opts := webhook.Options {
7879 Host : c .Host ,
@@ -93,28 +94,26 @@ func (c *WebhookServerConfig) Options(ctx context.Context, secretsClient client.
9394
9495type MetricsServerConfig struct {
9596 // SecureServing enables serving metrics via https.
96- // Per default metrics will be served via http.
97+ // + default=true
9798 SecureServing * bool `json:"secureServing,omitempty"`
9899
99100 // BindAddress is the bind address for the metrics server.
100- // It will be defaulted to "0" if unspecified.
101101 // Use :8443 for HTTPS or :8080 for HTTP
102102 //
103103 // Set this to "0" to disable the metrics server.
104+ // +default="0"
104105 BindAddress string `json:"bindAddress"`
105106
106107 // TLS is the TLS configuration for the metrics server, allowing configuration
107108 // of what path to find a certificate and key in, and what file names to use.
109+ //
110+ // The CertDir field will be defaulted to <temp-dir>/k8s-metrics-server/serving-certs.
108111 TLS TLSConfig `json:"tls"`
109112}
110113
111114func SetDefaults_MetricsServerConfig (obj * MetricsServerConfig ) {
112- if obj .SecureServing == nil {
113- obj .SecureServing = ptr .To (true )
114- }
115-
116- if obj .BindAddress == "" {
117- obj .BindAddress = "0"
115+ if len (obj .TLS .CertDir ) == 0 {
116+ obj .TLS .CertDir = filepath .Join (os .TempDir (), "k8s-metrics-server" , "serving-certs" )
118117 }
119118}
120119
@@ -153,18 +152,20 @@ type TLSConfig struct {
153152 // will be read from the API on every request.
154153 SecretRef * corev1.ObjectReference `json:"secretRef,omitempty"`
155154
156- // CertDir is the directory that contains the server key and certificate. Defaults to
157- // <temp-dir>/k8s-webhook-server/serving-certs .
155+ // CertDir is the directory that contains the server key and certificate.
156+ // Default depends on the parent config these settings are contained in .
158157 CertDir string `json:"certDir"`
159158
160- // CertName is the server certificate name. Defaults to tls.crt.
159+ // CertName is the server certificate name.
161160 //
162161 // Note: This option is only used when TLSOpts does not set GetCertificate.
162+ // +default="tls.crt"
163163 CertName string `json:"certName"`
164164
165- // KeyName is the server key name. Defaults to tls.key.
165+ // KeyName is the server key name.
166166 //
167167 // Note: This option is only used when TLSOpts does not set GetCertificate.
168+ // +default="tls.key"
168169 KeyName string `json:"keyName"`
169170}
170171
@@ -203,20 +204,6 @@ func (c *TLSConfig) Options(ctx context.Context, secretsClient client.Client) []
203204 return tlsOpts
204205}
205206
206- func SetDefaults_TLSConfig (obj * TLSConfig ) {
207- if len (obj .CertDir ) == 0 {
208- obj .CertDir = filepath .Join (os .TempDir (), "k8s-metrics-server" , "serving-certs" )
209- }
210-
211- if len (obj .CertName ) == 0 {
212- obj .CertName = "tls.crt"
213- }
214-
215- if len (obj .KeyName ) == 0 {
216- obj .KeyName = "tls.key"
217- }
218- }
219-
220207// +k8s:deepcopy-gen=true
221208
222209type DownstreamResourceManagementConfig struct {
@@ -284,7 +271,7 @@ func (c *DownstreamResourceManagementConfig) RestConfig() (*rest.Config, error)
284271type DiscoveryConfig struct {
285272 // Mode is the mode that the operator should use to discover clusters.
286273 //
287- // Defaults to "single"
274+ // +default= "single"
288275 Mode providers.Provider `json:"mode"`
289276
290277 // InternalServiceDiscovery will result in the operator to connect to internal
@@ -310,12 +297,6 @@ type DiscoveryConfig struct {
310297 LabelSelector * metav1.LabelSelector `json:"labelSelector,omitempty"`
311298}
312299
313- func SetDefaults_DiscoveryConfig (obj * DiscoveryConfig ) {
314- if obj .Mode == "" {
315- obj .Mode = providers .ProviderSingle
316- }
317- }
318-
319300func (c * DiscoveryConfig ) DiscoveryRestConfig () (* rest.Config , error ) {
320301 if c .DiscoveryKubeconfigPath == "" {
321302 return ctrl .GetConfig ()
0 commit comments