pub fn rollout_iterations(&self, replicas: u32) -> u32 {
        let surge = if let Some(surge) = self.maxSurge.clone() {
            // surge is max number/percentage
            surge.to_replicas_ceil(replicas)
        } else {
            // default surge percentage is 25
            (f64::from(replicas * 25) / 100.0).ceil() as u32
        };
        let unavail = if let Some(unav) = self.maxUnavailable.clone() {
            // maxUnavailable is max number/percentage
            unav.to_replicas_floor(replicas)
        } else {
            (f64::from(replicas * 25) / 100.0).floor() as u32
        };
        // Work out how many iterations is needed assuming consistent rollout time
        // Often, this is not true, but it provides a good indication
        let mut newrs = 0;
        let mut oldrs = replicas; // keep track of for ease of following logic
        let mut iters = 0;
        trace!(
            "rollout iterations for {} replicas, surge={},unav={}",
            replicas,
            surge,
            unavail
        );
        while newrs < replicas {
            // kill from oldrs the difference in total if we are surging
            oldrs -= oldrs + newrs - replicas; // noop if surge == 0
                                               // terminate pods so we have at least maxUnavailable
            let total = newrs + oldrs;

            let unavail_safe = if total <= unavail { 0 } else { unavail };
            trace!(
                "oldrs{}, total is {}, unavail_safe: {}",
                oldrs,
                total,
                unavail_safe
            );
            oldrs -= std::cmp::min(oldrs, unavail_safe); // never integer overflow
                                                         // add new pods to cover and allow surging a little
            newrs += unavail_safe;
            newrs += surge;
            // after this iteration, assume we have rolled out newrs replicas
            // and we hve ~_oldrs remaining (ignoring <0 case)
            iters += 1;
            trace!("rollout iter {}: old={}, new={}", iters, oldrs, newrs);
        }
        trace!("rollout iters={}", iters);
        iters
    }
/// Estimate how many cycles is needed to roll out a new version
///
/// This is a bit arcane extrapolates from [rolling update documentation](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#max-unavailable)
/// It needs to keep into account both values.
Estimate how many cycles is needed to roll out a new version
This is a bit arcane extrapolates from [rolling update documentation]
It needs to keep into account both values.
Estimate how many cycles is needed to roll out a new version This is a bit arcane extrapolates from [ rolling update documentation ] It needs to keep into account both values .
pub fn rollout_iterations(&self, replicas: u32) -> u32 {
        let surge = if let Some(surge) = self.maxSurge.clone() {
            // surge is max number/percentage
            surge.to_replicas_ceil(replicas)
        } else {
            // default surge percentage is 25
            (f64::from(replicas * 25) / 100.0).ceil() as u32
        };
        let unavail = if let Some(unav) = self.maxUnavailable.clone() {
            // maxUnavailable is max number/percentage
            unav.to_replicas_floor(replicas)
        } else {
            (f64::from(replicas * 25) / 100.0).floor() as u32
        };
        // Work out how many iterations is needed assuming consistent rollout time
        // Often, this is not true, but it provides a good indication
        let mut newrs = 0;
        let mut oldrs = replicas; // keep track of for ease of following logic
        let mut iters = 0;
        trace!(
            "rollout iterations for {} replicas, surge={},unav={}",
            replicas,
            surge,
            unavail
        );
        while newrs < replicas {
            // kill from oldrs the difference in total if we are surging
            oldrs -= oldrs + newrs - replicas; // noop if surge == 0
                                               // terminate pods so we have at least maxUnavailable
            let total = newrs + oldrs;
            let unavail_safe = if total <= unavail { 0 } else { unavail };
            trace!(
                "oldrs{}, total is {}, unavail_safe: {}",
                oldrs,
                total,
                unavail_safe
            );
            oldrs -= std::cmp::min(oldrs, unavail_safe); // never integer overflow
                                                         // add new pods to cover and allow surging a little
            newrs += unavail_safe;
            newrs += surge;
            // after this iteration, assume we have rolled out newrs replicas
            // and we hve ~_oldrs remaining (ignoring <0 case)
            iters += 1;
            trace!("rollout iter {}: old={}, new={}", iters, oldrs, newrs);
        }
        trace!("rollout iters={}", iters);
        iters
    }
pub fn rollout_iterations ( & self , replicas : u32 ) -> u32 { let surge = if let Some ( surge ) = self . maxSurge . clone ( ) { // surge is max number/percentage surge . to_replicas_ceil ( replicas ) } else { // default surge percentage is 25 ( f64 :: from ( replicas * 25 ) / 100.0 ) . ceil ( ) as u32 } ; let unavail = if let Some ( unav ) = self . maxUnavailable . clone ( ) { // maxUnavailable is max number/percentage unav . to_replicas_floor ( replicas ) } else { ( f64 :: from ( replicas * 25 ) / 100.0 ) . floor ( ) as u32 } ; // Work out how many iterations is needed assuming consistent rollout time // Often, this is not true, but it provides a good indication let mut newrs = 0 ; let mut oldrs = replicas ; // keep track of for ease of following logic let mut iters = 0 ; trace ! ( " " replicas surge unavail ) ; while newrs < replicas { // kill from oldrs the difference in total if we are surging oldrs -= oldrs + newrs - replicas ; // noop if surge == 0 // terminate pods so we have at least maxUnavailable let total = newrs + oldrs ; let unavail_safe = if total <= unavail { 0 } else { unavail } ; trace ! ( " " oldrs total unavail_safe ) ; oldrs -= std :: cmp :: min ( oldrs , unavail_safe ) ; // never integer overflow // add new pods to cover and allow surging a little newrs += unavail_safe ; newrs += surge ; // after this iteration, assume we have rolled out newrs replicas // and we hve ~_oldrs remaining (ignoring <0 case) iters += 1 ; trace ! ( " " iters oldrs newrs ) ; } trace ! ( " " iters ) ; iters }
Estimate how many cycles is needed to roll out a new version
This is a bit arcane extrapolates from [rolling update documentation](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#max-unavailable)
It needs to keep into account both values.
Estimate how many cycles is needed to roll out a new version This is a bit arcane extrapolates from [ rolling update documentation ] ( https : // kubernetes . io / docs / concepts / workloads / controllers / deployment / #max - unavailable ) It needs to keep into account both values .
&self
replicas
u32
&self
replicas
u32