@@ -398,8 +398,9 @@ impl k8s_controller::Context for Context {
398398 ) ;
399399 let resources_hash = resources. generate_hash ( ) ;
400400
401- let mut result = if has_current_changes {
402- if mz. rollout_requested ( ) {
401+ let mut result = match ( has_current_changes, mz. rollout_requested ( ) ) {
402+ // There are changes pending, and we want to appy them.
403+ ( true , true ) => {
403404 // we remove the environment resources hash annotation here
404405 // because if we fail halfway through applying the resources,
405406 // things will be in an inconsistent state, and we don't want
@@ -454,6 +455,8 @@ impl k8s_controller::Context for Context {
454455 // do this last, so that we keep traffic pointing at
455456 // the previous environmentd until the new one is
456457 // fully ready
458+ // TODO add condition saying we're about to promote,
459+ // and check it before aborting anything.
457460 resources. promote_services ( & client, & mz. namespace ( ) ) . await ?;
458461 resources
459462 . teardown_generation ( & client, mz, active_generation)
@@ -520,7 +523,9 @@ impl k8s_controller::Context for Context {
520523 Err ( e)
521524 }
522525 }
523- } else {
526+ }
527+ // There are changes pending, but we don't want to apply them yet.
528+ ( true , false ) => {
524529 let mut needs_update = mz. conditions_need_update ( ) ;
525530 if mz. update_in_progress ( ) {
526531 resources
@@ -555,44 +560,46 @@ impl k8s_controller::Context for Context {
555560 debug ! ( "changes detected, waiting for approval" ) ;
556561 Ok ( None )
557562 }
558- } else {
559- // this can happen if we update the environment, but then revert
560- // that update before the update was deployed. in this case, we
561- // don't want the environment to still show up as
562- // WaitingForApproval.
563- let mut needs_update = mz. conditions_need_update ( ) || mz. rollout_requested ( ) ;
564- if mz. update_in_progress ( ) {
565- resources
566- . teardown_generation ( & client, mz, next_generation)
563+ // No changes pending, but we might need to clean up a partially applied rollout.
564+ ( false , _) => {
565+ // this can happen if we update the environment, but then revert
566+ // that update before the update was deployed. in this case, we
567+ // don't want the environment to still show up as
568+ // WaitingForApproval.
569+ let mut needs_update = mz. conditions_need_update ( ) || mz. rollout_requested ( ) ;
570+ if mz. update_in_progress ( ) {
571+ resources
572+ . teardown_generation ( & client, mz, next_generation)
573+ . await ?;
574+ needs_update = true ;
575+ }
576+ if needs_update {
577+ self . update_status (
578+ & mz_api,
579+ mz,
580+ MaterializeStatus {
581+ active_generation,
582+ last_completed_rollout_request : mz. requested_reconciliation_id ( ) ,
583+ resource_id : status. resource_id ,
584+ resources_hash : status. resources_hash ,
585+ conditions : vec ! [ Condition {
586+ type_: "UpToDate" . into( ) ,
587+ status: "True" . into( ) ,
588+ last_transition_time: Time ( chrono:: offset:: Utc :: now( ) ) ,
589+ message: format!(
590+ "No changes found from generation {active_generation}"
591+ ) ,
592+ observed_generation: mz. meta( ) . generation,
593+ reason: "Applied" . into( ) ,
594+ } ] ,
595+ } ,
596+ active_generation != desired_generation,
597+ )
567598 . await ?;
568- needs_update = true ;
569- }
570- if needs_update {
571- self . update_status (
572- & mz_api,
573- mz,
574- MaterializeStatus {
575- active_generation,
576- last_completed_rollout_request : mz. requested_reconciliation_id ( ) ,
577- resource_id : status. resource_id ,
578- resources_hash : status. resources_hash ,
579- conditions : vec ! [ Condition {
580- type_: "UpToDate" . into( ) ,
581- status: "True" . into( ) ,
582- last_transition_time: Time ( chrono:: offset:: Utc :: now( ) ) ,
583- message: format!(
584- "No changes found from generation {active_generation}"
585- ) ,
586- observed_generation: mz. meta( ) . generation,
587- reason: "Applied" . into( ) ,
588- } ] ,
589- } ,
590- active_generation != desired_generation,
591- )
592- . await ?;
599+ }
600+ debug ! ( "no changes" ) ;
601+ Ok ( None )
593602 }
594- debug ! ( "no changes" ) ;
595- Ok ( None )
596603 } ;
597604
598605 // balancers rely on the environmentd service existing, which is
0 commit comments