def scale_down(self, new_rc, old_rc, desired, min_available, max_surge):
        # already scaled down; do nothing.
        if old_rc.replicas == 0:
            return old_rc
        # block until there are any pods ready
        _, new_available = self.poll_for_ready_pods(old_rc, new_rc)
        # the old controller is considered as part of the total because we want
        # to maintain minimum availability even with a volatile old controller.
        # scale down as much as possible while maintaining minimum availability.
        decrement = old_rc.replicas + new_available - min_available
        # the decrement normally shouldn't drop below zero because the available
        # count always start below the old replica count, but the old replica
        # count can decrement due to externalities like pods death in the replica
        # set. this will be considered a transient condition; do nothing and try
        # again later with new readiness values.
        #
        # if the most we can scale is zero, it means we can't scale down without
        # violating the minimum. do nothing and try again later when conditions
        # may have changed.
        if decrement <= 0:
            return old_rc
        # reduce the replica count, and deal with fenceposts
        old_rc.replicas = max(0, old_rc.replicas - decrement)
        # if the new is already fully scaled and available up to the desired size,
        # go ahead and scale old all the way down
        if new_rc.replicas == desired and new_available == desired:
            old_rc.replicas = 0
        # perform scale down
        logger.info("scaling {} down to {}".format(old_rc.name, old_rc.replicas))
        old_rc.scale()
        return old_rc
dataset/ETHPy150Open eldarion-gondor/pykube/pykube/rolling_updater.py/RollingUpdater.scale_down/original