kaniop_operator/kanidm/crd.rs
1use crate::crd::is_default;
2
3use std::collections::BTreeMap;
4
5use k8s_openapi::api::apps::v1::StatefulSetPersistentVolumeClaimRetentionPolicy;
6use k8s_openapi::api::core::v1::{
7 Affinity, Container, EmptyDirVolumeSource, EnvVar, EphemeralVolumeSource, HostAlias,
8 PersistentVolumeClaim, PersistentVolumeClaimSpec, PodDNSConfig, PodSecurityContext,
9 ResourceRequirements, SecretKeySelector, Toleration, TopologySpreadConstraint, Volume,
10 VolumeMount,
11};
12use k8s_openapi::apimachinery::pkg::apis::meta::v1::{Condition, LabelSelector};
13use kube::CustomResource;
14use kube::api::ObjectMeta;
15#[cfg(feature = "schemars")]
16use schemars::JsonSchema;
17use serde::{Deserialize, Serialize};
18
19/// Specification of the desired behavior of the Kanidm cluster. More info:
20/// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
21#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default)]
22#[cfg_attr(feature = "schemars", derive(JsonSchema))]
23// workaround: '`' character is not allowed in the kube `doc` attribute during doctests
24#[cfg_attr(
25 not(doctest),
26 kube(
27 doc = r#"The `Kanidm` custom resource definition (CRD) defines a desired [Kanidm](https://kanidm.com)
28 setup to run in a Kubernetes cluster. It allows to specify many options such as the number of replicas,
29 persistent storage, and many more.
30
31 For each `Kanidm` resource, the Operator deploys one or several `StatefulSet` objects in the same namespace. The number of StatefulSets is equal to the number of replicas.
32 "#
33 )
34)]
35#[kube(
36 category = "kaniop",
37 group = "kaniop.rs",
38 version = "v1beta1",
39 kind = "Kanidm",
40 plural = "kanidms",
41 singular = "kanidm",
42 shortname = "idm",
43 namespaced,
44 status = "KanidmStatus",
45 printcolumn = r#"{"name":"Replicas","type":"string","description":"The number of replicas: ready/desired","jsonPath":".status.replicaColumn"}"#,
46 printcolumn = r#"{"name":"Domain","type":"string","jsonPath":".spec.domain"}"#,
47 printcolumn = r#"{"name":"Secret","type":"string","jsonPath":".status.secretName"}"#,
48 printcolumn = r#"{"name":"Age","type":"date","jsonPath":".metadata.creationTimestamp"}"#,
49 derive = "Default"
50)]
51#[serde(rename_all = "camelCase")]
52pub struct KanidmSpec {
53 /// The DNS domain name of the server. This is used in a number of security-critical
54 /// contexts such as webauthn, so it *must* match your DNS hostname. It is used to
55 /// create security principal names such as `william@idm.example.com` so that in a
56 /// (future) trust configuration it is possible to have unique Security Principal
57 /// Names (spns) throughout the topology.
58 ///
59 /// This cannot be changed after creation.
60 #[schemars(extend("x-kubernetes-validations" = [{"message": "Domain cannot be changed.", "rule": "self == oldSelf"}]))]
61 #[schemars(regex(
62 pattern = r"^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)*[a-z0-9]([-a-z0-9]*[a-z0-9])?$"
63 ))]
64 pub domain: String,
65
66 /// Different group of replicas with specific configuration as role, resources, affinity rules, and more.
67 /// Each group will be deployed as a separate StatefulSet.
68 #[schemars(extend("x-kubernetes-validations" = [{"message": "At least one ReplicaGroup is required", "rule": "self.size() > 0"}]))]
69 // max is defined for allowing CEL expression in validation admission policy estimate
70 // expression costs
71 #[validate(length(min = 1, max = 100))]
72 pub replica_groups: Vec<ReplicaGroup>,
73
74 /// List of external replication nodes. This is used to configure replication between
75 /// different Kanidm clusters.
76 ///
77 /// **WARNING**: `admin` and `idm_admin` passwords are going to be reset.
78 // max is defined for allowing CEL expression in validation admission policy estimate
79 // expression costs
80 #[validate(length(max = 100))]
81 #[serde(default, skip_serializing_if = "is_default")]
82 pub external_replication_nodes: Vec<ExternalReplicationNode>,
83
84 /// Container image name. More info: https://kubernetes.io/docs/concepts/containers/images
85 /// This field is optional to allow higher level config management to default or override
86 /// container images in workload controllers like StatefulSets.
87 #[serde(default = "default_image", skip_serializing_if = "is_default")]
88 pub image: String,
89
90 /// Log level for Kanidm.
91 #[serde(default, skip_serializing_if = "is_default")]
92 pub log_level: KanidmLogLevel,
93
94 /// Port name used for the pods and governing service. Default: "https"
95 #[serde(default = "default_port_name", skip_serializing_if = "is_default")]
96 pub port_name: String,
97
98 /// Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always if :latest tag
99 /// is specified, or IfNotPresent otherwise. Cannot be updated.
100 /// More info: https://kubernetes.io/docs/concepts/containers/images#updating-images
101 #[serde(skip_serializing_if = "Option::is_none")]
102 pub image_pull_policy: Option<String>,
103
104 /// List of environment variables to set in the `kanidm` container.
105 /// This can be used to set Kanidm configuration options.
106 /// More info: https://kanidm.github.io/kanidm/master/server_configuration.html
107 #[serde(skip_serializing_if = "Option::is_none")]
108 pub env: Option<Vec<EnvVar>>,
109
110 /// Namespaces to match for KanidmOAuth2Clients discovery.
111 ///
112 /// An empty label selector matches all namespaces.
113 /// A null label selector (default value) matches the current namespace only.
114 #[serde(skip_serializing_if = "Option::is_none")]
115 pub oauth2_client_namespace_selector: Option<LabelSelector>,
116
117 /// Namespaces to match for KanidmGroups discovery.
118 ///
119 /// An empty label selector matches all namespaces.
120 /// A null label selector (default value) matches the current namespace only.
121 #[serde(skip_serializing_if = "Option::is_none")]
122 pub group_namespace_selector: Option<LabelSelector>,
123
124 /// Namespaces to match for KanidmPersonAccounts discovery.
125 ///
126 /// An empty label selector matches all namespaces.
127 /// A null label selector (default value) matches the current namespace only.
128 #[serde(skip_serializing_if = "Option::is_none")]
129 pub person_namespace_selector: Option<LabelSelector>,
130
131 /// StorageSpec defines the configured storage for a group Kanidm servers.
132 /// If no storage option is specified, then by default an
133 /// [EmptyDir](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir) will be used.
134 ///
135 /// If multiple storage options are specified, priority will be given as follows:
136 /// 1. emptyDir
137 /// 2. ephemeral
138 /// 3. volumeClaimTemplate
139 ///
140 /// Note: Kaniop does not resize PVCs until Kubernetes fix
141 /// [KEP-4650](https://github.com/kubernetes/enhancements/pull/4651).
142 /// Although, StatefulSet will be recreated if the PVC is resized.
143 #[serde(skip_serializing_if = "Option::is_none")]
144 pub storage: Option<KanidmStorage>,
145
146 /// Defines the port name used for the LDAP service. If not defined, LDAP service will not be
147 /// configured. Service port will be `3636`.
148 ///
149 /// StartTLS is not supported due to security risks such as credential leakage and MITM attacks
150 /// that are fundamental in how StartTLS works. StartTLS can not be repaired to prevent this.
151 /// LDAPS is the only secure method of communicating to any LDAP server. Kanidm will use its
152 /// certificates for both HTTPS and LDAPS.
153 #[serde(skip_serializing_if = "Option::is_none")]
154 pub ldap_port_name: Option<String>,
155
156 /// Specifies the name of the secret holding the TLS private key and certificate for the server.
157 /// If not provided, the ingress secret will be used. The server will not start if the secret
158 /// is missing.
159 #[serde(skip_serializing_if = "Option::is_none")]
160 pub tls_secret_name: Option<String>,
161
162 /// Service defines the service configuration for the Kanidm server.
163 #[serde(skip_serializing_if = "Option::is_none")]
164 pub service: Option<KanidmService>,
165
166 /// Ingress defines the ingress configuration for the Kanidm server. Domain will be the host
167 /// for the ingress. TLS is required.
168 #[serde(skip_serializing_if = "Option::is_none")]
169 pub ingress: Option<KanidmIngress>,
170
171 /// Volumes allows the configuration of additional volumes on the output StatefulSet
172 /// definition. Volumes specified will be appended to other volumes that are generated as a
173 /// result of StorageSpec objects.
174 #[serde(skip_serializing_if = "Option::is_none")]
175 pub volumes: Option<Vec<Volume>>,
176
177 /// VolumeMounts allows the configuration of additional VolumeMounts.
178 ///
179 /// VolumeMounts will be appended to other VolumeMounts in the kanidm’ container, that are
180 /// generated as a result of StorageSpec objects.
181 #[serde(skip_serializing_if = "Option::is_none")]
182 pub volume_mounts: Option<Vec<VolumeMount>>,
183
184 /// The field controls if and how PVCs are deleted during the lifecycle of a StatefulSet.
185 /// The default behavior is all PVCs are retained.
186 /// This is a beta field from 1.27. It requires enabling the StatefulSetAutoDeletePVC feature
187 /// gate.
188 #[serde(skip_serializing_if = "Option::is_none")]
189 pub persistent_volume_claim_retention_policy:
190 Option<StatefulSetPersistentVolumeClaimRetentionPolicy>,
191
192 /// SecurityContext holds pod-level security attributes and common container settings.
193 /// This defaults to the default PodSecurityContext.
194 #[serde(skip_serializing_if = "Option::is_none")]
195 pub security_context: Option<PodSecurityContext>,
196
197 /// Defines the DNS policy for the pods.
198 #[serde(skip_serializing_if = "Option::is_none")]
199 pub dns_policy: Option<String>,
200
201 /// Defines the DNS configuration for the pods.
202 #[serde(skip_serializing_if = "Option::is_none")]
203 pub dns_config: Option<PodDNSConfig>,
204
205 /// Containers allows injecting additional containers or modifying operator generated
206 /// containers. This can be used to allow adding an authentication proxy to the Pods or to
207 /// change the behavior of an operator generated container. Containers described here modify
208 /// an operator generated container if they share the same name and modifications are done
209 /// via a strategic merge patch.
210 ///
211 /// The name of container managed by the operator is: kanidm
212 ///
213 /// Overriding containers is entirely outside the scope of what the maintainers will support
214 /// and by doing so, you accept that this behaviour may break at any time without notice.
215 #[serde(skip_serializing_if = "Option::is_none")]
216 pub containers: Option<Vec<Container>>,
217
218 /// InitContainers allows injecting initContainers to the Pod definition. Those can be used to
219 /// e.g. fetch secrets for injection into the Kanidm configuration from external sources.
220 /// Any errors during the execution of an initContainer will lead to a restart of the Pod.
221 /// More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
222 /// InitContainers described here modify an operator generated init containers if they share
223 /// the same name and modifications are done via a strategic merge patch.
224 ///
225 /// The names of init container name managed by the operator are: * init-config-reloader.
226 ///
227 /// Overriding init containers is entirely outside the scope of what the maintainers will
228 /// support and by doing so, you accept that this behaviour may break at any time without notice.
229 #[serde(skip_serializing_if = "Option::is_none")]
230 pub init_containers: Option<Vec<Container>>,
231
232 /// Minimum number of seconds for which a newly created Pod should be ready without any of its
233 /// container crashing for it to be considered available. Defaults to 0 (pod will be considered
234 /// available as soon as it is ready)
235 #[serde(skip_serializing_if = "Option::is_none")]
236 pub min_ready_seconds: Option<i32>,
237
238 /// Optional list of hosts and IPs that will be injected into the Pod’s hosts file if specified.
239 #[serde(skip_serializing_if = "Option::is_none")]
240 pub host_aliases: Option<Vec<HostAlias>>,
241
242 /// Use the host’s network namespace if true.
243 ///
244 /// Make sure to understand the security implications if you want to enable it
245 /// (https://kubernetes.io/docs/concepts/configuration/overview/).
246 ///
247 /// When hostNetwork is enabled, this will set the DNS policy to ClusterFirstWithHostNet
248 /// automatically.
249 #[serde(skip_serializing_if = "Option::is_none")]
250 pub host_network: Option<bool>,
251}
252
253#[derive(Serialize, Deserialize, Clone, Debug, Default)]
254#[cfg_attr(feature = "schemars", derive(JsonSchema))]
255#[serde(rename_all = "camelCase")]
256pub struct ReplicaGroup {
257 /// The name of the replica group.
258 pub name: String,
259
260 /// Number of replicas to deploy for a Kanidm replica group.
261 pub replicas: i32,
262
263 /// The Kanidm role of each node in the replica group.
264 #[serde(default)]
265 pub role: KanidmServerRole,
266
267 /// If true, the first pod of the StatefulSet will be considered as the primary node.
268 /// The rest of the nodes are considered as secondary nodes.
269 /// This means that if database issues occur the content of the primary will take precedence
270 /// over the rest of the nodes.
271 /// This is only valid for the WriteReplica role and can only be set to true for one
272 /// replica group or external replication node.
273 /// Defaults to false.
274 #[serde(default)]
275 pub primary_node: bool,
276
277 /// Defines the resources requests and limits of the kanidm’ container.
278 #[serde(skip_serializing_if = "Option::is_none")]
279 pub resources: Option<ResourceRequirements>,
280
281 /// Defines on which Nodes the Pods are scheduled.
282 #[serde(skip_serializing_if = "Option::is_none")]
283 pub node_selector: Option<BTreeMap<String, String>>,
284
285 /// Defines the Pods’ affinity scheduling rules if specified.
286 #[serde(skip_serializing_if = "Option::is_none")]
287 pub affinity: Option<Affinity>,
288
289 /// Defines the Pods’ tolerations if specified.
290 #[serde(skip_serializing_if = "Option::is_none")]
291 pub tolerations: Option<Vec<Toleration>>,
292
293 /// Defines the pod’s topology spread constraints if specified.
294 #[serde(skip_serializing_if = "Option::is_none")]
295 pub topology_spread_constraints: Option<Vec<TopologySpreadConstraint>>,
296}
297
298// re-implementation of kanidmd_core::config::ServerRole because it is not Serialize
299#[derive(Serialize, Deserialize, Clone, Debug, Default)]
300#[cfg_attr(feature = "schemars", derive(JsonSchema))]
301#[serde(rename_all = "snake_case")]
302pub enum KanidmServerRole {
303 /// Full read-write replica with web UI
304 #[default]
305 WriteReplica,
306 /// Read-write replica without the web UI
307 WriteReplicaNoUI,
308 /// Read-only replica for load balancing read operations
309 ReadOnlyReplica,
310}
311
312#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
313#[cfg_attr(feature = "schemars", derive(JsonSchema))]
314#[serde(rename_all = "camelCase")]
315pub struct ExternalReplicationNode {
316 /// Name of the external replication node. This just have internal use.
317 pub name: String,
318
319 /// The hostname of the external replication node.
320 pub hostname: String,
321
322 /// The replication port of the external replication node.
323 pub port: i32,
324
325 /// Defines the secret that contains the identity certificate of the external replication node.
326 pub certificate: SecretKeySelector,
327
328 /// Defines the type of replication to use. Defaults to MutualPull.
329 #[serde(default)]
330 pub _type: ReplicationType,
331
332 /// Select external replication node as the primary node. This means that if database conflicts
333 /// occur the content of the primary will take precedence over the rest of the nodes.
334 /// Note: just one external replication node or replication group can be selected as primary.
335 /// Defaults to false.
336 #[serde(default)]
337 pub automatic_refresh: bool,
338}
339
340// re-implementation of kanidmd_core::repl::config::RepNodeConfig because it is not Serialize and
341// attributes changed
342#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
343#[cfg_attr(feature = "schemars", derive(JsonSchema))]
344#[serde(rename_all = "kebab-case")]
345pub enum ReplicationType {
346 /// Both nodes can initiate replication with each other
347 #[default]
348 MutualPull,
349 /// This node allows the external node to pull changes, but won't initiate
350 AllowPull,
351 /// This node will pull changes from the external node
352 Pull,
353}
354
355fn default_image() -> String {
356 "kanidm/server:latest".to_string()
357}
358
359// re-implementation of sketching::LogLevel because it is not Serialize
360#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
361#[cfg_attr(feature = "schemars", derive(JsonSchema))]
362#[serde(rename_all = "snake_case")]
363pub enum KanidmLogLevel {
364 /// Most verbose logging level, includes all debug and info messages
365 Trace,
366 /// Debug level logging, useful for troubleshooting
367 Debug,
368 /// Standard informational logging level
369 #[default]
370 Info,
371}
372
373fn default_port_name() -> String {
374 "https".to_string()
375}
376
377/// PersistentVolumeClaimTemplate defines a PVC template with optional metadata.
378/// This allows users to specify a PVC template without requiring metadata to be explicitly set.
379#[derive(Serialize, Deserialize, Clone, Debug, Default)]
380#[cfg_attr(feature = "schemars", derive(JsonSchema))]
381#[serde(rename_all = "camelCase")]
382pub struct PersistentVolumeClaimTemplate {
383 /// Standard object's metadata. More info:
384 /// https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
385 #[serde(skip_serializing_if = "Option::is_none")]
386 pub metadata: Option<ObjectMeta>,
387
388 /// spec defines the desired characteristics of a volume requested by a pod author. More info:
389 /// https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
390 pub spec: Option<PersistentVolumeClaimSpec>,
391}
392
393impl PersistentVolumeClaimTemplate {
394 /// Convert this template into a k8s-openapi PersistentVolumeClaim
395 pub fn to_persistent_volume_claim(&self) -> PersistentVolumeClaim {
396 PersistentVolumeClaim {
397 metadata: self.metadata.clone().unwrap_or_default(),
398 spec: self.spec.clone(),
399 ..Default::default()
400 }
401 }
402}
403
404#[derive(Serialize, Deserialize, Clone, Debug, Default)]
405#[cfg_attr(feature = "schemars", derive(JsonSchema))]
406#[serde(rename_all = "camelCase")]
407pub struct KanidmStorage {
408 /// EmptyDirVolumeSource to be used by the StatefulSet. If specified, it takes precedence over
409 /// `ephemeral` and `volumeClaimTemplate`.
410 /// More info: https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
411 #[serde(skip_serializing_if = "Option::is_none")]
412 pub empty_dir: Option<EmptyDirVolumeSource>,
413
414 /// EphemeralVolumeSource to be used by the StatefulSet.
415 /// More info: https://kubernetes.io/docs/concepts/storage/ephemeral-volumes/#generic-ephemeral-volumes
416 #[serde(skip_serializing_if = "Option::is_none")]
417 pub ephemeral: Option<EphemeralVolumeSource>,
418
419 /// Defines the PVC spec to be used by the Kanidm StatefulSets. The easiest way to use a volume
420 /// that cannot be automatically provisioned is to use a label selector alongside manually
421 /// created PersistentVolumes.
422 #[serde(skip_serializing_if = "Option::is_none")]
423 pub volume_claim_template: Option<PersistentVolumeClaimTemplate>,
424}
425
426#[derive(Serialize, Deserialize, Clone, Debug, Default)]
427#[cfg_attr(feature = "schemars", derive(JsonSchema))]
428#[serde(rename_all = "camelCase")]
429pub struct KanidmService {
430 /// Annotations is an unstructured key value map stored with a resource that may be set by
431 /// external tools to store and retrieve arbitrary metadata. They are not queryable and should
432 /// be preserved when modifying objects.
433 /// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations
434 #[serde(skip_serializing_if = "Option::is_none")]
435 pub annotations: Option<BTreeMap<String, String>>,
436
437 /// Specify the Service's type where the Kanidm Service is exposed
438 /// Please note that some Ingress controllers like https://github.com/kubernetes/ingress-gce
439 /// forces you to expose your Service on a NodePort
440 /// Defaults to ClusterIP. Valid options are ExternalName, ClusterIP, NodePort, and
441 /// LoadBalancer. "ClusterIP" allocates a cluster-internal IP address for load-balancing to
442 /// endpoints. Endpoints are determined by the selector or if that is not specified, by manual
443 /// construction of an Endpoints object or EndpointSlice objects. If clusterIP is "None",
444 /// no virtual IP is allocated and the endpoints are published as a set of endpoints rather
445 /// than a virtual IP. "NodePort" builds on ClusterIP and allocates a port on every node which
446 /// routes to the same endpoints as the clusterIP. "LoadBalancer" builds on NodePort and creates
447 /// an external load-balancer (if supported in the current cloud) which routes to the same
448 /// endpoints as the clusterIP. "ExternalName" aliases this service to the specified
449 /// externalName. Several other fields do not apply to ExternalName services.
450 /// More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
451 #[serde(skip_serializing_if = "Option::is_none")]
452 pub type_: Option<String>,
453}
454
455#[derive(Serialize, Deserialize, Clone, Debug, Default)]
456#[cfg_attr(feature = "schemars", derive(JsonSchema))]
457#[serde(rename_all = "camelCase")]
458pub struct KanidmIngress {
459 /// Annotations is an unstructured key value map stored with a resource that may be set by
460 /// external tools to store and retrieve arbitrary metadata. They are not queryable and should
461 /// be preserved when modifying objects.
462 /// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations
463 #[serde(skip_serializing_if = "Option::is_none")]
464 pub annotations: Option<BTreeMap<String, String>>,
465
466 /// ingressClassName is the name of an IngressClass cluster resource. Ingress controller
467 /// implementations use this field to know whether they should be serving this Ingress resource,
468 /// by a transitive connection (controller -\> IngressClass -\> Ingress resource). Although the
469 /// `kubernetes.io/ingress.class` annotation (simple constant name) was never formally defined,
470 /// it was widely supported by Ingress controllers to create a direct binding between Ingress
471 /// controller and Ingress resources. Newly created Ingress resources should prefer using the
472 /// field. However, even though the annotation is officially deprecated, for backwards
473 /// compatibility reasons, ingress controllers should still honor that annotation if present.
474 #[serde(skip_serializing_if = "Option::is_none")]
475 pub ingress_class_name: Option<String>,
476 /// Defines the name of the secret that contains the TLS private key and certificate for the
477 /// server. If not defined, the default will be the Kanidm name appended with `-tls`.
478 #[serde(skip_serializing_if = "Option::is_none")]
479 pub tls_secret_name: Option<String>,
480}
481
482/// Most recent observed status of the Kanidm cluster. Read-only.
483/// More info:
484/// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
485#[derive(Serialize, Deserialize, Clone, Debug, Default)]
486#[cfg_attr(feature = "schemars", derive(JsonSchema))]
487#[serde(rename_all = "camelCase")]
488pub struct KanidmStatus {
489 /// Total number of available pods (ready for at least minReadySeconds) targeted by this Kanidm
490 /// deployment.
491 pub available_replicas: i32,
492
493 #[serde(skip_serializing_if = "Option::is_none")]
494 pub conditions: Option<Vec<Condition>>,
495
496 /// Total number of non-terminated pods targeted by this Kanidm cluster.
497 pub replicas: i32,
498
499 /// Total number of unavailable pods targeted by this Kanidm cluster.
500 pub unavailable_replicas: i32,
501
502 /// Total number of non-terminated pods targeted by this Kanidm cluster that have the
503 /// desired version spec.
504 pub updated_replicas: i32,
505
506 /// Status per replica in the Kanidm cluster.
507 pub replica_statuses: Vec<KanidmReplicaStatus>,
508
509 /// Ready vs desired replicas.
510 pub replica_column: String,
511
512 /// Admin users secret name.
513 pub secret_name: Option<String>,
514}
515
516#[derive(Serialize, Deserialize, Clone, Debug)]
517#[cfg_attr(feature = "schemars", derive(JsonSchema))]
518#[serde(rename_all = "camelCase")]
519pub struct KanidmReplicaStatus {
520 /// Pod name: replica group StatefulSet name plus the pod index.
521 pub pod_name: String,
522
523 /// StatefulSet name: Kanidm name plus the replica group name.
524 pub statefulset_name: String,
525
526 /// The current state of the replica.
527 pub state: KanidmReplicaState,
528}
529
530#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
531#[cfg_attr(feature = "schemars", derive(JsonSchema))]
532#[serde(rename_all = "snake_case")]
533pub enum KanidmReplicaState {
534 Initialized,
535 Pending,
536}
537
538#[cfg(test)]
539mod tests {
540 use super::*;
541 use k8s_openapi::api::core::v1::PersistentVolumeClaimSpec;
542
543 #[test]
544 fn test_pvc_template_optional_metadata() {
545 // Test that we can create a PVC template without metadata
546 let pvc_template = PersistentVolumeClaimTemplate {
547 metadata: None,
548 spec: Some(PersistentVolumeClaimSpec::default()),
549 };
550
551 // Test that it can be converted to a k8s PVC
552 let k8s_pvc = pvc_template.to_persistent_volume_claim();
553 assert_eq!(k8s_pvc.metadata, ObjectMeta::default());
554 assert_eq!(k8s_pvc.spec, pvc_template.spec);
555 }
556
557 #[test]
558 fn test_pvc_template_with_metadata() {
559 let custom_metadata = ObjectMeta {
560 name: Some("test-pvc".to_string()),
561 labels: Some([("app".to_string(), "test".to_string())].into()),
562 ..ObjectMeta::default()
563 };
564
565 // Test that we can create a PVC template with metadata
566 let pvc_template = PersistentVolumeClaimTemplate {
567 metadata: Some(custom_metadata.clone()),
568 spec: Some(PersistentVolumeClaimSpec::default()),
569 };
570
571 // Test that it can be converted to a k8s PVC
572 let k8s_pvc = pvc_template.to_persistent_volume_claim();
573 assert_eq!(k8s_pvc.metadata, custom_metadata);
574 assert_eq!(k8s_pvc.spec, pvc_template.spec);
575 }
576}