|
11 | 11 | package v1alpha2 |
12 | 12 |
|
13 | 13 | import ( |
14 | | - corev1 "k8s.io/api/core/v1" |
| 14 | + "time" |
| 15 | + |
15 | 16 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
16 | 17 | ) |
17 | 18 |
|
18 | | -// ClusterSpec defines the desired state of Cluster |
19 | | -type ClusterSpec struct { |
20 | | - // ApiURL is the URL of the PowerDNS API |
| 19 | +// ClusterTLSConfig defines TLS configuration for PowerDNS API connection |
| 20 | +type ClusterTLSConfig struct { |
| 21 | + // Insecure enables insecure connections to PowerDNS API (skip TLS verification) |
| 22 | + // +kubebuilder:default:=false |
| 23 | + // +optional |
| 24 | + Insecure *bool `json:"insecure,omitempty"` |
| 25 | + |
| 26 | + // CABundleRef is a reference to a ConfigMap or Secret containing a CA bundle |
| 27 | + // +optional |
| 28 | + CABundleRef *ClusterCABundleRef `json:"caBundleRef,omitempty"` |
| 29 | +} |
| 30 | + |
| 31 | +// ClusterCABundleRef defines a reference to a CA bundle in a ConfigMap or Secret |
| 32 | +type ClusterCABundleRef struct { |
| 33 | + // Name is the name of the ConfigMap or Secret |
21 | 34 | // +kubebuilder:validation:Required |
22 | | - // +kubebuilder:validation:Pattern=`^https?://.*` |
23 | | - ApiURL string `json:"apiUrl"` |
| 35 | + Name string `json:"name"` |
| 36 | + |
| 37 | + // Namespace is the namespace of the ConfigMap or Secret |
| 38 | + // If not specified, defaults to the operator namespace |
| 39 | + // +optional |
| 40 | + Namespace *string `json:"namespace,omitempty"` |
| 41 | + |
| 42 | + // Kind is the kind of resource (ConfigMap or Secret) |
| 43 | + // +kubebuilder:validation:Enum=ConfigMap;Secret |
| 44 | + // +kubebuilder:default:="ConfigMap" |
| 45 | + // +optional |
| 46 | + Kind *string `json:"kind,omitempty"` |
24 | 47 |
|
25 | | - // ApiSecretRef is a reference to a Kubernetes Secret containing the PowerDNS API key |
26 | | - // The secret must contain a key named "apiKey" |
| 48 | + // Key is the key in the ConfigMap or Secret containing the CA bundle |
| 49 | + // +kubebuilder:default:="ca.crt" |
| 50 | + // +optional |
| 51 | + Key *string `json:"key,omitempty"` |
| 52 | +} |
| 53 | + |
| 54 | +// ClusterCredentials defines credentials configuration for PowerDNS API |
| 55 | +type ClusterCredentials struct { |
| 56 | + // SecretRef is a reference to a Kubernetes Secret containing the PowerDNS API key |
27 | 57 | // +kubebuilder:validation:Required |
28 | | - ApiSecretRef corev1.SecretReference `json:"apiSecretRef"` |
| 58 | + SecretRef ClusterSecretRef `json:"secretRef"` |
| 59 | +} |
29 | 60 |
|
30 | | - // ApiVhost is the vhost of the PowerDNS API, defaults to "localhost" |
31 | | - // +kubebuilder:default:="localhost" |
| 61 | +// ClusterSecretRef defines a reference to a Secret containing API credentials |
| 62 | +type ClusterSecretRef struct { |
| 63 | + // Name is the name of the Secret |
| 64 | + // +kubebuilder:validation:Required |
| 65 | + Name string `json:"name"` |
| 66 | + |
| 67 | + // Namespace is the namespace of the Secret |
| 68 | + // If not specified, defaults to the cluster resource namespace |
32 | 69 | // +optional |
33 | | - ApiVhost *string `json:"apiVhost,omitempty"` |
| 70 | + Namespace *string `json:"namespace,omitempty"` |
34 | 71 |
|
35 | | - // ApiTimeout is the timeout for PowerDNS API requests in seconds, defaults to 10 |
36 | | - // +kubebuilder:default:=10 |
37 | | - // +kubebuilder:validation:Minimum=1 |
38 | | - // +kubebuilder:validation:Maximum=300 |
| 72 | + // Key is the key in the Secret containing the API key |
| 73 | + // +kubebuilder:default:="apiKey" |
39 | 74 | // +optional |
40 | | - ApiTimeout *int `json:"apiTimeout,omitempty"` |
| 75 | + Key *string `json:"key,omitempty"` |
| 76 | +} |
41 | 77 |
|
42 | | - // ApiInsecure enables insecure connections to PowerDNS API (skip TLS verification) |
43 | | - // +kubebuilder:default:=false |
| 78 | +// ClusterSpec defines the desired state of Cluster |
| 79 | +type ClusterSpec struct { |
| 80 | + // Interval is the reconciliation interval to check the connection to the PowerDNS API |
| 81 | + // +kubebuilder:default:="5m" |
44 | 82 | // +optional |
45 | | - ApiInsecure *bool `json:"apiInsecure,omitempty"` |
| 83 | + Interval *metav1.Duration `json:"interval,omitempty"` |
| 84 | + |
| 85 | + // URL is the URL of the PowerDNS API |
| 86 | + // +kubebuilder:validation:Required |
| 87 | + // +kubebuilder:validation:Pattern=`^https?://.*` |
| 88 | + URL string `json:"url"` |
46 | 89 |
|
47 | | - // ApiCAPath is the path to the certificate authority file for TLS verification |
48 | | - // This should be a path to a mounted secret or configmap in the operator pod |
| 90 | + // Vhost is the vhost/server ID of the PowerDNS API, defaults to "localhost" |
| 91 | + // +kubebuilder:default:="localhost" |
| 92 | + // +optional |
| 93 | + Vhost *string `json:"vhost,omitempty"` |
| 94 | + |
| 95 | + // Timeout is the timeout for PowerDNS API requests, defaults to 10s |
| 96 | + // +kubebuilder:default:="10s" |
49 | 97 | // +optional |
50 | | - ApiCAPath *string `json:"apiCAPath,omitempty"` |
| 98 | + Timeout *metav1.Duration `json:"timeout,omitempty"` |
51 | 99 |
|
52 | | - // ProxyURL is the URL of the HTTP/HTTPS proxy to use for connecting to PowerDNS API |
| 100 | + // Proxy is the URL of the HTTP/HTTPS proxy to use for connecting to PowerDNS API |
53 | 101 | // Format: http://proxy.example.com:8080 or https://proxy.example.com:8080 |
54 | 102 | // +optional |
55 | | - ProxyURL *string `json:"proxyUrl,omitempty"` |
| 103 | + Proxy *string `json:"proxy,omitempty"` |
| 104 | + |
| 105 | + // TLS defines TLS configuration for PowerDNS API connection |
| 106 | + // +optional |
| 107 | + TLS *ClusterTLSConfig `json:"tls,omitempty"` |
| 108 | + |
| 109 | + // Credentials defines credentials configuration for PowerDNS API |
| 110 | + // +kubebuilder:validation:Required |
| 111 | + Credentials ClusterCredentials `json:"credentials"` |
56 | 112 | } |
57 | 113 |
|
58 | 114 | // ClusterStatus defines the observed state of Cluster |
@@ -90,7 +146,7 @@ type ClusterStatus struct { |
90 | 146 | // +kubebuilder:subresource:status |
91 | 147 | // +kubebuilder:resource:scope=Cluster |
92 | 148 |
|
93 | | -// +kubebuilder:printcolumn:name="API URL",type="string",JSONPath=".spec.apiUrl" |
| 149 | +// +kubebuilder:printcolumn:name="URL",type="string",JSONPath=".spec.url" |
94 | 150 | // +kubebuilder:printcolumn:name="Connection Status",type="string",JSONPath=".status.connectionStatus" |
95 | 151 | // +kubebuilder:printcolumn:name="PowerDNS Version",type="string",JSONPath=".status.powerDNSVersion" |
96 | 152 | // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
@@ -129,26 +185,79 @@ func (c *Cluster) IsConnectionHealthy() bool { |
129 | 185 | return c.Status.ConnectionStatus != nil && *c.Status.ConnectionStatus == "Connected" |
130 | 186 | } |
131 | 187 |
|
132 | | -// GetApiVhost returns the API vhost, defaulting to "localhost" if not specified |
133 | | -func (c *Cluster) GetApiVhost() string { |
134 | | - if c.Spec.ApiVhost != nil { |
135 | | - return *c.Spec.ApiVhost |
| 188 | +// GetVhost returns the API vhost, defaulting to "localhost" if not specified |
| 189 | +func (c *Cluster) GetVhost() string { |
| 190 | + if c.Spec.Vhost != nil { |
| 191 | + return *c.Spec.Vhost |
136 | 192 | } |
137 | 193 | return "localhost" |
138 | 194 | } |
139 | 195 |
|
140 | | -// GetApiTimeout returns the API timeout, defaulting to 10 seconds if not specified |
141 | | -func (c *Cluster) GetApiTimeout() int { |
142 | | - if c.Spec.ApiTimeout != nil { |
143 | | - return *c.Spec.ApiTimeout |
| 196 | +// GetTimeout returns the API timeout, defaulting to 10 seconds if not specified |
| 197 | +func (c *Cluster) GetTimeout() time.Duration { |
| 198 | + if c.Spec.Timeout != nil { |
| 199 | + return c.Spec.Timeout.Duration |
144 | 200 | } |
145 | | - return 10 |
| 201 | + return 10 * time.Second |
146 | 202 | } |
147 | 203 |
|
148 | | -// GetApiInsecure returns the API insecure setting, defaulting to false if not specified |
149 | | -func (c *Cluster) GetApiInsecure() bool { |
150 | | - if c.Spec.ApiInsecure != nil { |
151 | | - return *c.Spec.ApiInsecure |
| 204 | +// GetInterval returns the reconciliation interval, defaulting to 5 minutes if not specified |
| 205 | +func (c *Cluster) GetInterval() time.Duration { |
| 206 | + if c.Spec.Interval != nil { |
| 207 | + return c.Spec.Interval.Duration |
| 208 | + } |
| 209 | + return 5 * time.Minute |
| 210 | +} |
| 211 | + |
| 212 | +// GetTLSInsecure returns the TLS insecure setting, defaulting to false if not specified |
| 213 | +func (c *Cluster) GetTLSInsecure() bool { |
| 214 | + if c.Spec.TLS != nil && c.Spec.TLS.Insecure != nil { |
| 215 | + return *c.Spec.TLS.Insecure |
152 | 216 | } |
153 | 217 | return false |
154 | 218 | } |
| 219 | + |
| 220 | +// GetCredentialsSecretName returns the credentials secret name |
| 221 | +func (c *Cluster) GetCredentialsSecretName() string { |
| 222 | + return c.Spec.Credentials.SecretRef.Name |
| 223 | +} |
| 224 | + |
| 225 | +// GetCredentialsSecretNamespace returns the credentials secret namespace, defaulting to cluster namespace if not specified |
| 226 | +func (c *Cluster) GetCredentialsSecretNamespace() string { |
| 227 | + if c.Spec.Credentials.SecretRef.Namespace != nil { |
| 228 | + return *c.Spec.Credentials.SecretRef.Namespace |
| 229 | + } |
| 230 | + return c.Namespace |
| 231 | +} |
| 232 | + |
| 233 | +// GetCredentialsSecretKey returns the credentials secret key, defaulting to "apiKey" if not specified |
| 234 | +func (c *Cluster) GetCredentialsSecretKey() string { |
| 235 | + if c.Spec.Credentials.SecretRef.Key != nil { |
| 236 | + return *c.Spec.Credentials.SecretRef.Key |
| 237 | + } |
| 238 | + return "apiKey" |
| 239 | +} |
| 240 | + |
| 241 | +// GetCABundleRefKind returns the CA bundle reference kind, defaulting to "ConfigMap" if not specified |
| 242 | +func (c *Cluster) GetCABundleRefKind() string { |
| 243 | + if c.Spec.TLS != nil && c.Spec.TLS.CABundleRef != nil && c.Spec.TLS.CABundleRef.Kind != nil { |
| 244 | + return *c.Spec.TLS.CABundleRef.Kind |
| 245 | + } |
| 246 | + return "ConfigMap" |
| 247 | +} |
| 248 | + |
| 249 | +// GetCABundleRefKey returns the CA bundle reference key, defaulting to "ca.crt" if not specified |
| 250 | +func (c *Cluster) GetCABundleRefKey() string { |
| 251 | + if c.Spec.TLS != nil && c.Spec.TLS.CABundleRef != nil && c.Spec.TLS.CABundleRef.Key != nil { |
| 252 | + return *c.Spec.TLS.CABundleRef.Key |
| 253 | + } |
| 254 | + return "ca.crt" |
| 255 | +} |
| 256 | + |
| 257 | +// GetCABundleRefNamespace returns the CA bundle reference namespace, defaulting to cluster namespace if not specified |
| 258 | +func (c *Cluster) GetCABundleRefNamespace() string { |
| 259 | + if c.Spec.TLS != nil && c.Spec.TLS.CABundleRef != nil && c.Spec.TLS.CABundleRef.Namespace != nil { |
| 260 | + return *c.Spec.TLS.CABundleRef.Namespace |
| 261 | + } |
| 262 | + return c.Namespace |
| 263 | +} |
0 commit comments