k8_metadata_client/
diff.rs1use serde::Serialize;
2
3use k8_types::{Crd, K8Obj, Spec};
4
5#[derive(Debug)]
6pub enum ApplyResult<S>
7where
8 S: Spec,
9{
10 None,
11 Created(K8Obj<S>),
12 Patched(K8Obj<S>),
13}
14
15#[derive(Debug, Serialize)]
16#[serde(rename_all = "camelCase")]
17pub struct ApplyOptions {
18 pub force: bool,
19 pub field_manager: Option<String>,
20}
21
22#[allow(dead_code)]
23pub enum PatchMergeType {
24 Json,
25 JsonMerge,
26 StrategicMerge, Apply(ApplyOptions),
28}
29
30impl PatchMergeType {
31 pub fn for_spec(crd: &Crd) -> Self {
32 match crd.group {
33 "core" => PatchMergeType::StrategicMerge,
34 "apps" => PatchMergeType::StrategicMerge,
35 _ => PatchMergeType::JsonMerge,
36 }
37 }
38
39 pub fn content_type(&self) -> &'static str {
40 match self {
41 PatchMergeType::Json => "application/json-patch+json",
42 PatchMergeType::JsonMerge => "application/merge-patch+json",
43 PatchMergeType::StrategicMerge => "application/strategic-merge-patch+json",
44 PatchMergeType::Apply { .. } => "application/apply-patch+yaml",
45 }
46 }
47}
48
49#[derive(Serialize, Debug, Clone)]
51pub struct DiffableK8Obj<M, S, H> {
52 metadata: M,
53 spec: S,
54 #[serde(flatten)]
55 header: H,
56}
57
58impl<M, S, H> DiffableK8Obj<M, S, H>
59where
60 M: Serialize,
61 S: Serialize,
62 H: Serialize,
63{
64 pub fn new(metadata: M, spec: S, header: H) -> Self {
65 Self {
66 metadata,
67 spec,
68 header,
69 }
70 }
71}