Skip to content

Commit cf7ef62

Browse files
committed
dpc: specify the branch of preview explicitly
1 parent be1988e commit cf7ef62

File tree

5 files changed

+1042
-17
lines changed

5 files changed

+1042
-17
lines changed

crates/data-plane-controller/src/controller.rs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ pub struct Controller {
4747
pub run_cmd_fn: RunCmdFn,
4848
}
4949

50+
#[derive(Debug, serde::Deserialize, serde::Serialize)]
51+
#[serde(rename_all = "camelCase")]
52+
pub struct Preview {
53+
pub branch: String,
54+
}
55+
5056
#[derive(Debug, serde::Deserialize, serde::Serialize)]
5157
#[serde(rename_all = "camelCase")]
5258
pub enum Message {
5359
Start(models::Id),
5460
Disable,
5561
Enable,
56-
Preview,
62+
Preview(Preview),
5763
Refresh,
5864
Converge,
5965
}
@@ -146,7 +152,7 @@ impl Controller {
146152
// Validate the state before operating on it, to ensure the data-plane-controller
147153
// never operates on an invalid state
148154
let ops_checkout = self
149-
.git_checkout(state, &self.ops_remote, checkouts)
155+
.git_checkout(state, &self.ops_remote, checkouts, "master")
150156
.await?;
151157
self.validate_state(ops_checkout, state).await?;
152158
}
@@ -170,7 +176,7 @@ impl Controller {
170176
// Validate the state after operating on it, to prevent writing a bad state into the
171177
// database which would lead to manual recovery being required
172178
let ops_checkout = self
173-
.git_checkout(state, &self.ops_remote, checkouts)
179+
.git_checkout(state, &self.ops_remote, checkouts, "master")
174180
.await?;
175181
self.validate_state(ops_checkout, state).await?;
176182
}
@@ -231,7 +237,10 @@ impl Controller {
231237
match message {
232238
Some(Message::Disable) => state.disabled = true,
233239
Some(Message::Enable) => state.disabled = false,
234-
Some(Message::Preview) => state.pending_preview = true,
240+
Some(Message::Preview(Preview { branch })) => {
241+
state.pending_preview = true;
242+
state.preview_branch = branch;
243+
}
235244
Some(Message::Refresh) => state.pending_refresh = true,
236245
Some(Message::Converge) => state.pending_converge = true,
237246

@@ -308,7 +317,9 @@ impl Controller {
308317
state: &mut State,
309318
checkouts: &mut HashMap<String, tempfile::TempDir>,
310319
) -> anyhow::Result<std::time::Duration> {
311-
let checkout = self.dry_dock_checkout(state, checkouts).await?;
320+
let checkout = self
321+
.dry_dock_checkout(state, checkouts, &state.deploy_branch)
322+
.await?;
312323

313324
() = self
314325
.run_cmd(
@@ -358,7 +369,9 @@ impl Controller {
358369
state: &mut State,
359370
checkouts: &mut HashMap<String, tempfile::TempDir>,
360371
) -> anyhow::Result<std::time::Duration> {
361-
let checkout = self.dry_dock_checkout(state, checkouts).await?;
372+
let checkout = self
373+
.dry_dock_checkout(state, checkouts, &state.preview_branch)
374+
.await?;
362375

363376
() = self
364377
.run_cmd(
@@ -390,7 +403,9 @@ impl Controller {
390403
state: &mut State,
391404
checkouts: &mut HashMap<String, tempfile::TempDir>,
392405
) -> anyhow::Result<std::time::Duration> {
393-
let checkout = self.dry_dock_checkout(state, checkouts).await?;
406+
let checkout = self
407+
.dry_dock_checkout(state, checkouts, &state.deploy_branch)
408+
.await?;
394409

395410
// Refresh, expecting to see no changes. We'll check exit status to see if there were.
396411
let result = self
@@ -436,7 +451,9 @@ impl Controller {
436451
state: &mut State,
437452
checkouts: &mut HashMap<String, tempfile::TempDir>,
438453
) -> anyhow::Result<std::time::Duration> {
439-
let checkout = self.dry_dock_checkout(state, checkouts).await?;
454+
let checkout = self
455+
.dry_dock_checkout(state, checkouts, &state.deploy_branch)
456+
.await?;
440457

441458
() = self
442459
.run_cmd(
@@ -502,7 +519,9 @@ impl Controller {
502519
state: &mut State,
503520
checkouts: &mut HashMap<String, tempfile::TempDir>,
504521
) -> anyhow::Result<std::time::Duration> {
505-
let checkout = self.dry_dock_checkout(state, checkouts).await?;
522+
let checkout = self
523+
.dry_dock_checkout(state, checkouts, &state.deploy_branch)
524+
.await?;
506525

507526
// Load exported Pulumi state.
508527
let output = self
@@ -601,7 +620,9 @@ impl Controller {
601620
state: &mut State,
602621
checkouts: &mut HashMap<String, tempfile::TempDir>,
603622
) -> anyhow::Result<std::time::Duration> {
604-
let checkout = self.dry_dock_checkout(state, checkouts).await?;
623+
let checkout = self
624+
.dry_dock_checkout(state, checkouts, &state.deploy_branch)
625+
.await?;
605626

606627
() = self
607628
.run_cmd(
@@ -663,6 +684,7 @@ impl Controller {
663684
state: &State,
664685
remote: &str,
665686
checkouts: &'c mut HashMap<String, tempfile::TempDir>,
687+
branch: &str,
666688
) -> anyhow::Result<&'c tempfile::TempDir> {
667689
let checkout = match checkouts.entry(remote.to_string()) {
668690
Entry::Occupied(e) => {
@@ -693,12 +715,6 @@ impl Controller {
693715
)
694716
.await?;
695717

696-
let branch = if remote == self.dry_dock_remote {
697-
&state.deploy_branch
698-
} else {
699-
"master"
700-
};
701-
702718
() = self
703719
.run_cmd(
704720
async_process::Command::new("git")
@@ -722,9 +738,10 @@ impl Controller {
722738
&self,
723739
state: &State,
724740
checkouts: &'c mut HashMap<String, tempfile::TempDir>,
741+
branch: &str,
725742
) -> anyhow::Result<&'c tempfile::TempDir> {
726743
let checkout = self
727-
.git_checkout(state, &self.dry_dock_remote, checkouts)
744+
.git_checkout(state, &self.dry_dock_remote, checkouts, branch)
728745
.await?;
729746

730747
() = self
@@ -932,6 +949,7 @@ async fn fetch_row_state(
932949

933950
disabled: true,
934951
pending_preview: false,
952+
preview_branch: String::new(),
935953
pending_refresh: false,
936954
pending_converge: false,
937955
publish_exports: None,

crates/data-plane-controller/src/stack.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub struct State {
5555
// Is there a pending preview for this data-plane?
5656
#[serde(default, skip_serializing_if = "is_false")]
5757
pub pending_preview: bool,
58+
// If pending a preview, on which branch should the preview run?
59+
#[serde(default, skip_serializing_if = "String::is_empty")]
60+
pub preview_branch: String,
5861
// Is there a pending refresh for this data-plane?
5962
#[serde(default, skip_serializing_if = "is_false")]
6063
pub pending_refresh: bool,

0 commit comments

Comments
 (0)