1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! Step-based controller building blocks.
//!
//! This module helps you build reconcilers that split one reconcile run into
//! ordered steps. Each step verifies one fix, applies at most one meaningful
//! modification, and then lets the next run observe fresh state.
mod plan;
mod reconciler;
mod run;
mod status;
mod step;
pub use plan::{BoxPlan, JoinSteps, Plan, PlanFuture, RunError, RunPlan, StepFailure};
pub use reconciler::{Reconciler, RunReconcilerConfig, run};
pub use run::{RunOutcome, RunStepConfig, run_plan};
pub use status::{KubeStatusUpdater, StatusUpdater};
pub use step::{
Immutable, ImmutableStep, Mutable, MutableStep, MutableStepOutcome, MutableStepResult, RunContext, Step, StepFn,
StepMode, StepOutcome, StepResult, immutable_step, mutable_step,
};
#[cfg(doctest)]
mod compile_fail_tests {
/// ```compile_fail
/// # use kube::CustomResource;
/// # use schemars::JsonSchema;
/// # use serde::{Deserialize, Serialize};
/// # use staircase::controller::{Immutable, MutableStepOutcome, MutableStepResult, RunContext, Step};
/// # #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
/// # #[kube(group = "tests.staircase.dev", version = "v1", kind = "BadResource", status = "BadStatus", namespaced)]
/// # struct BadSpec {}
/// # #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
/// # struct BadStatus {}
/// struct BadStep;
///
/// impl Step for BadStep {
/// type Error = ();
/// type InData = ();
/// type Mode = Immutable;
/// type OutData = ();
/// type Resource = BadResource;
///
/// async fn run(
/// &self,
/// _: &RunContext<Self::Resource>,
/// _: Self::InData,
/// ) -> MutableStepResult<Self::Resource, Self::OutData, Self::Error> {
/// Ok(MutableStepOutcome::Modified { status: None })
/// }
/// }
/// ```
struct ImmutableStepCannotReturnMutableOutcome;
/// ```compile_fail
/// # use kube::CustomResource;
/// # use schemars::JsonSchema;
/// # use serde::{Deserialize, Serialize};
/// # use staircase::controller::{
/// # Immutable, Mutable, MutableStepOutcome, MutableStepResult, Plan, RunContext, Step, StepOutcome, StepResult,
/// # };
/// # #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
/// # #[kube(group = "tests.staircase.dev", version = "v1", kind = "JoinResource", status = "JoinStatus", namespaced)]
/// # struct JoinSpec {}
/// # #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
/// # struct JoinStatus {}
/// struct Load;
/// struct Create;
///
/// impl Step for Load {
/// type Error = ();
/// type InData = ();
/// type Mode = Immutable;
/// type OutData = ();
/// type Resource = JoinResource;
///
/// async fn run(
/// &self,
/// _: &RunContext<Self::Resource>,
/// data: Self::InData,
/// ) -> StepResult<Self::OutData, Self::Error> {
/// Ok(StepOutcome::NoModification { data })
/// }
/// }
///
/// impl Step for Create {
/// type Error = ();
/// type InData = ();
/// type Mode = Mutable;
/// type OutData = ();
/// type Resource = JoinResource;
///
/// async fn run(
/// &self,
/// _: &RunContext<Self::Resource>,
/// data: Self::InData,
/// ) -> MutableStepResult<Self::Resource, Self::OutData, Self::Error> {
/// Ok(MutableStepOutcome::NoModification { data })
/// }
/// }
///
/// let _ = Plan::from(Load).join((Create, Load));
/// ```
struct JoinCannotAcceptMutableStep;
/// ```compile_fail
/// # use kube::CustomResource;
/// # use schemars::JsonSchema;
/// # use serde::{Deserialize, Serialize};
/// # use staircase::controller::{
/// # Immutable, Mutable, MutableStepOutcome, MutableStepResult, Plan, RunContext, Step, StepOutcome, StepResult,
/// # };
/// # #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
/// # #[kube(group = "tests.staircase.dev", version = "v1", kind = "JoinMapResource", status = "JoinMapStatus", namespaced)]
/// # struct JoinMapSpec {}
/// # #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
/// # struct JoinMapStatus {}
/// struct Load;
/// struct Create;
///
/// impl Step for Load {
/// type Error = ();
/// type InData = ();
/// type Mode = Immutable;
/// type OutData = ();
/// type Resource = JoinMapResource;
///
/// async fn run(
/// &self,
/// _: &RunContext<Self::Resource>,
/// data: Self::InData,
/// ) -> StepResult<Self::OutData, Self::Error> {
/// Ok(StepOutcome::NoModification { data })
/// }
/// }
///
/// impl Step for Create {
/// type Error = ();
/// type InData = ();
/// type Mode = Mutable;
/// type OutData = ();
/// type Resource = JoinMapResource;
///
/// async fn run(
/// &self,
/// _: &RunContext<Self::Resource>,
/// data: Self::InData,
/// ) -> MutableStepResult<Self::Resource, Self::OutData, Self::Error> {
/// Ok(MutableStepOutcome::NoModification { data })
/// }
/// }
///
/// let _ = Plan::from(Load).join_map((Create, Load), |(_, data)| data);
/// ```
struct JoinMapCannotAcceptMutableStep;
/// ```compile_fail
/// # use staircase::controller::{Plan, RunPlan};
/// # use kube::CustomResource;
/// # use schemars::JsonSchema;
/// # use serde::{Deserialize, Serialize};
/// # #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
/// # #[kube(group = "tests.staircase.dev", version = "v1", kind = "PlanNodeResource", status = "PlanNodeStatus", namespaced)]
/// # struct PlanNodeSpec {}
/// # #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
/// # struct PlanNodeStatus {}
/// let _ = staircase::controller::plan::Empty::<PlanNodeResource, (), ()> {
/// _marker: std::marker::PhantomData,
/// };
/// ```
struct PlanNodesCannotBeConstructedThroughPrivateModule;
/// ```compile_fail
/// # use staircase::controller::Plan;
/// # use kube::CustomResource;
/// # use schemars::JsonSchema;
/// # use serde::{Deserialize, Serialize};
/// # #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
/// # #[kube(group = "tests.staircase.dev", version = "v1", kind = "PlanEmptyResource", status = "PlanEmptyStatus", namespaced)]
/// # struct PlanEmptySpec {}
/// # #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
/// # struct PlanEmptyStatus {}
/// let plan = Plan::empty::<PlanEmptyResource, (), ()>();
/// let _inner = plan.inner;
/// ```
struct PlanInnerCannotBeAccessed;
}