-
Notifications
You must be signed in to change notification settings - Fork 485
feat: add upgrade window check for environmentd image ref #34327
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
SangJunBak
merged 2 commits into
MaterializeInc:main
from
SangJunBak:jun/unskippable-release
Dec 4, 2025
+205
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -479,6 +479,71 @@ pub mod v1alpha1 { | |
| } | ||
| } | ||
|
|
||
| /// This check isn't strictly required since environmentd will still be able to determine | ||
| /// if the upgrade is allowed or not. However, doing this check allows us to provide | ||
| /// the error as soon as possible and in a more user friendly way. | ||
| pub fn is_valid_upgrade_version(active_version: &Version, next_version: &Version) -> bool { | ||
| // Don't allow rolling back | ||
| // Note: semver comparison handles RC versions correctly: | ||
| // v26.0.0-rc.1 < v26.0.0-rc.2 < v26.0.0 | ||
| if next_version < active_version { | ||
| return false; | ||
| } | ||
|
|
||
| if active_version.major == 0 { | ||
| // Self managed 25.2 to 26.0 | ||
| if next_version.major != active_version.major { | ||
| if next_version.major == 26 | ||
| && active_version.major == 0 | ||
| && active_version.minor == 164 | ||
| { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| // Self managed 25.1 to 25.2 | ||
| if next_version.minor == 147 && active_version.minor == 130 { | ||
| return true; | ||
| } | ||
| // only allow upgrading a single minor version at a time | ||
| return next_version.minor <= active_version.minor + 1; | ||
| } else if active_version.major >= 26 { | ||
| // For versions 26.X.X and onwards, we deny upgrades past 1 major version of the active version | ||
| return next_version.major <= active_version.major + 1; | ||
| } | ||
|
|
||
| true | ||
| } | ||
|
|
||
| /// Checks if the current environmentd image ref is within the upgrade window of the last | ||
| /// successful rollout. | ||
| pub fn within_upgrade_window(&self) -> bool { | ||
| let active_environmentd_version = self | ||
| .status | ||
| .as_ref() | ||
| .and_then(|status| { | ||
| status | ||
| .last_completed_rollout_environmentd_image_ref | ||
| .as_ref() | ||
| }) | ||
| .and_then(|image_ref| parse_image_ref(image_ref)); | ||
|
|
||
| if let (Some(next_environmentd_version), Some(active_environmentd_version)) = ( | ||
| parse_image_ref(&self.spec.environmentd_image_ref), | ||
| active_environmentd_version, | ||
| ) { | ||
| Self::is_valid_upgrade_version( | ||
| &active_environmentd_version, | ||
| &next_environmentd_version, | ||
| ) | ||
| } else { | ||
| // If we fail to parse either version, | ||
| // we still allow the upgrade since environmentd will still error if the upgrade is not allowed. | ||
| true | ||
| } | ||
| } | ||
|
|
||
| pub fn managed_resource_meta(&self, name: String) -> ObjectMeta { | ||
| ObjectMeta { | ||
| namespace: Some(self.namespace()), | ||
|
|
@@ -516,6 +581,11 @@ pub mod v1alpha1 { | |
| .expect("valid int generation"); | ||
| } | ||
|
|
||
| // Initialize the last completed rollout environmentd image ref to | ||
| // the current image ref if not already set. | ||
| status.last_completed_rollout_environmentd_image_ref = | ||
| Some(self.spec.environmentd_image_ref.clone()); | ||
|
|
||
| status | ||
| }) | ||
| } | ||
|
|
@@ -530,6 +600,10 @@ pub mod v1alpha1 { | |
| pub active_generation: u64, | ||
| /// The UUID of the last successfully completed rollout. | ||
| pub last_completed_rollout_request: Uuid, | ||
| /// The image ref of the environmentd image that was last successfully rolled out. | ||
| /// Used to deny upgrades past 1 major version from the last successful rollout. | ||
| /// When None, we upgrade anyways. | ||
| pub last_completed_rollout_environmentd_image_ref: Option<String>, | ||
| /// A hash calculated from the spec of resources to be created based on this Materialize | ||
| /// spec. This is used for detecting when the existing resources are up to date. | ||
| /// If you want to trigger a rollout without making other changes that would cause this | ||
|
|
@@ -630,4 +704,89 @@ mod tests { | |
| mz.spec.environmentd_image_ref = "my.private.registry:5000:v0.33.3".to_owned(); | ||
| assert!(!mz.meets_minimum_version(&Version::parse("0.34.0").unwrap())); | ||
| } | ||
|
|
||
| #[mz_ore::test] | ||
| fn within_upgrade_window() { | ||
| use super::v1alpha1::MaterializeStatus; | ||
|
|
||
| let mut mz = Materialize { | ||
| spec: MaterializeSpec { | ||
| environmentd_image_ref: "materialize/environmentd:v26.0.0".to_owned(), | ||
| ..Default::default() | ||
| }, | ||
| metadata: ObjectMeta { | ||
| ..Default::default() | ||
| }, | ||
| status: Some(MaterializeStatus { | ||
| last_completed_rollout_environmentd_image_ref: Some( | ||
| "materialize/environmentd:v26.0.0".to_owned(), | ||
| ), | ||
| ..Default::default() | ||
| }), | ||
| }; | ||
|
|
||
| // Pass: upgrading from 26.0.0 to 27.7.3 (within 1 major version) | ||
| mz.spec.environmentd_image_ref = "materialize/environmentd:v27.7.3".to_owned(); | ||
| assert!(mz.within_upgrade_window()); | ||
|
|
||
| // Pass: upgrading from 26.0.0 to 27.7.8-dev.0 (within 1 major version, pre-release) | ||
| mz.spec.environmentd_image_ref = "materialize/environmentd:v27.7.8-dev.0".to_owned(); | ||
| assert!(mz.within_upgrade_window()); | ||
|
|
||
| // Fail: upgrading from 26.0.0 to 28.0.1 (more than 1 major version) | ||
| mz.spec.environmentd_image_ref = "materialize/environmentd:v28.0.1".to_owned(); | ||
| assert!(!mz.within_upgrade_window()); | ||
|
|
||
| // Pass: upgrading from 26.0.0 to 28.0.1.not_a_valid_version (invalid version, defaults to true) | ||
| mz.spec.environmentd_image_ref = | ||
| "materialize/environmentd:v28.0.1.not_a_valid_version".to_owned(); | ||
| assert!(mz.within_upgrade_window()); | ||
|
|
||
| // Pass: upgrading from 0.164.0 to 26.1.0 (self managed 25.2 to 26.0) | ||
| mz.status | ||
| .as_mut() | ||
| .unwrap() | ||
| .last_completed_rollout_environmentd_image_ref = | ||
| Some("materialize/environmentd:v0.164.0".to_owned()); | ||
| mz.spec.environmentd_image_ref = "materialize/environmentd:v26.1.0".to_owned(); | ||
| assert!(mz.within_upgrade_window()); | ||
| } | ||
|
|
||
| #[mz_ore::test] | ||
| fn is_valid_upgrade_version() { | ||
| let success_tests = [ | ||
| (Version::new(0, 83, 0), Version::new(0, 83, 0)), | ||
| (Version::new(0, 83, 0), Version::new(0, 84, 0)), | ||
| (Version::new(0, 9, 0), Version::new(0, 10, 0)), | ||
| (Version::new(0, 99, 0), Version::new(0, 100, 0)), | ||
| (Version::new(0, 83, 0), Version::new(0, 83, 1)), | ||
| (Version::new(0, 83, 0), Version::new(0, 83, 2)), | ||
| (Version::new(0, 83, 2), Version::new(0, 83, 10)), | ||
| (Version::new(0, 164, 0), Version::new(26, 0, 0)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also 147 I think |
||
| (Version::new(26, 0, 0), Version::new(26, 1, 0)), | ||
| (Version::new(26, 5, 3), Version::new(26, 10, 0)), | ||
| (Version::new(0, 130, 0), Version::new(0, 147, 0)), | ||
| ]; | ||
| for (active_version, next_version) in success_tests { | ||
| assert!( | ||
| Materialize::is_valid_upgrade_version(&active_version, &next_version), | ||
| "v{active_version} can upgrade to v{next_version}" | ||
| ); | ||
| } | ||
|
|
||
| let failure_tests = [ | ||
| (Version::new(0, 83, 0), Version::new(0, 82, 0)), | ||
| (Version::new(0, 83, 3), Version::new(0, 83, 2)), | ||
| (Version::new(0, 83, 3), Version::new(1, 83, 3)), | ||
| (Version::new(0, 83, 0), Version::new(0, 85, 0)), | ||
| (Version::new(26, 0, 0), Version::new(28, 0, 0)), | ||
| (Version::new(0, 130, 0), Version::new(26, 1, 0)), | ||
| ]; | ||
| for (active_version, next_version) in failure_tests { | ||
| assert!( | ||
| !Materialize::is_valid_upgrade_version(&active_version, &next_version), | ||
| "v{active_version} can't upgrade to v{next_version}" | ||
| ); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be 147
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(with a specific patch version)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, right, it should be both (i forgot about that since we weren't deploying those versions to cloud)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jun is fixing it: #34371