Skip to content

allow orchestratord to force a rollout to promote before it's ready #32177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cloud-resources/src/crd/materialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ pub mod v1alpha1 {
// generation rollout is automatically triggered.
#[serde(default = "Uuid::new_v4")]
pub request_rollout: Uuid,
// If force_promote is set to the same value as request_rollout, the
// current rollout will skip waiting for clusters in the new
// generation to rehydrate before promoting the new environmentd to
// leader.
#[serde(default)]
pub force_promote: Uuid,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be an Option<Uuid> to handle already existing CRs? What does K8S do in cases where a new CRD definition is incompatible with the old stored data?

The #[serde(default)] handles missing data on the controller side, but does K8S even allow you to upgrade the CRD in this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as i can tell from testing, this works as you would want it to

// This value will be written to an annotation in the generated
// environmentd statefulset, in order to force the controller to
// detect the generated resources as changed even if no other changes
Expand Down Expand Up @@ -320,6 +326,14 @@ pub mod v1alpha1 {
.map_or_else(Uuid::nil, |status| status.last_completed_rollout_request)
}

pub fn set_force_promote(&mut self) {
self.spec.force_promote = self.spec.request_rollout;
}

pub fn should_force_promote(&self) -> bool {
self.spec.force_promote == self.spec.request_rollout
}

pub fn conditions_need_update(&self) -> bool {
let Some(status) = self.status.as_ref() else {
return true;
Expand Down
8 changes: 7 additions & 1 deletion src/orchestratord/src/controller/materialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,13 @@ impl k8s_controller::Context for Context {

trace!("applying environment resources");
match resources
.apply(&client, &self.config, increment_generation, &mz.namespace())
.apply(
&client,
&self.config,
increment_generation,
mz.should_force_promote(),
&mz.namespace(),
)
.await
{
Ok(Some(action)) => {
Expand Down
21 changes: 20 additions & 1 deletion src/orchestratord/src/controller/materialize/environmentd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use k8s_openapi::{
use kube::{Api, Client, ResourceExt, api::ObjectMeta, runtime::controller::Action};
use maplit::btreemap;
use rand::{Rng, thread_rng};
use reqwest::StatusCode;
use semver::{BuildMetadata, Prerelease, Version};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -127,6 +128,7 @@ impl Resources {
client: &Client,
args: &super::MaterializeControllerArgs,
increment_generation: bool,
force_promote: bool,
namespace: &str,
) -> Result<Option<Action>, anyhow::Error> {
let environmentd_network_policy_api: Api<NetworkPolicy> =
Expand Down Expand Up @@ -215,7 +217,19 @@ impl Resources {
match http_client.get(status_url.clone()).send().await {
Ok(response) => {
let response: BTreeMap<String, DeploymentStatus> = response.json().await?;
if response["status"] == DeploymentStatus::Initializing {
if force_promote {
trace!("skipping cluster catchup");
let skip_catchup_url = reqwest::Url::parse(&format!(
"http://{}/api/leader/skip-catchup",
environmentd_url
))
.unwrap();
let response = http_client.post(skip_catchup_url).send().await?;
if response.status() == StatusCode::BAD_REQUEST {
let err: SkipCatchupError = response.json().await?;
bail!("failed to skip catchup: {}", err.message);
}
} else if response["status"] == DeploymentStatus::Initializing {
trace!("environmentd is still initializing, retrying...");
return Ok(Some(retry_action));
} else {
Expand Down Expand Up @@ -1392,6 +1406,11 @@ enum BecomeLeaderResult {
Failure { message: String },
}

#[derive(Debug, Deserialize, PartialEq, Eq)]
struct SkipCatchupError {
message: String,
}

fn environmentd_internal_http_address(
args: &super::MaterializeControllerArgs,
namespace: &str,
Expand Down