def should_backoff(ctx, managed_object: typing.Union[client.V1Deployment, client.V1DaemonSet]) -> bool: if ctx.obj['restart_label'] in managed_object.metadata.annotations.keys(): last_restarted = parse_time(managed_object.metadata.annotations[ctx.obj['restart_label']]) backoff_period = parse_duration(ctx.obj['backoff_period']) if datetime.utcnow() < last_restarted + backoff_period: return True return False
def parse_wait(params): template = re.compile('([0-9.]+[dhms]?)+\)') s_res = template.search(params) if s_res: duration = s_res.groups()[0] self.wait(parse_duration(duration)) else: self.log.info("Wait step format: 'wait(<step_duration>)'") raise StepperConfigurationError( "Error in step configuration: 'wait(%s'" % params)
def parse_const(params): template = re.compile('(\d+),\s*([0-9.]+[dhms]?)+\)') s_res = template.search(params) if s_res: instances, interval = s_res.groups() self.const(int(instances), parse_duration(interval)) else: self.log.info( "Const step format: 'const(<instances_count>, <step_duration>)'") raise StepperConfigurationError( "Error in step configuration: 'const(%s'" % params)
def parse_const(params): template = re.compile('(\d+),\s*([0-9.]+[dhms]?)+\)') s_res = template.search(params) if s_res: instances, interval = s_res.groups() self.const(int(instances), parse_duration(interval)) else: self.log.info( "Const step format: 'const(<instances_count>, <step_duration>)'" ) raise StepperConfigurationError( "Error in step configuration: 'const(%s'" % params)
def parse_line(params): template = re.compile('(\d+),\s*(\d+),\s*([0-9.]+[dhms]?)+\)') s_res = template.search(params) if s_res: initial_instances, final_instances, interval = s_res.groups() self.line(int(initial_instances), int(final_instances), parse_duration(interval)) else: self.log.info( "Line step format: 'line(<initial_instances>, <final_instances>, <step_duration>)'" ) raise StepperConfigurationError( "Error in step configuration: 'line(%s'" % params)
def parse_stairway(params): template = re.compile( '(\d+),\s*(\d+),\s*(\d+),\s*([0-9.]+[dhms]?)+\)') s_res = template.search(params) if s_res: initial_instances, final_instances, step_size, step_duration = s_res.groups( ) self.stairway(int(initial_instances), int(final_instances), int( step_size), parse_duration(step_duration)) else: self.log.info( "Stairway step format: 'step(<initial_instances>, <final_instances>, <step_size>, <step_duration>)'") raise StepperConfigurationError( "Error in step configuration: 'step(%s'" % params)
def parse_line(params): template = re.compile('(\d+),\s*(\d+),\s*([0-9.]+[dhms]?)+\)') s_res = template.search(params) if s_res: initial_instances, final_instances, interval = s_res.groups() self.line( int(initial_instances), int(final_instances), parse_duration(interval) ) else: self.log.info( "Line step format: 'line(<initial_instances>, <final_instances>, <step_duration>)'") raise StepperConfigurationError( "Error in step configuration: 'line(%s'" % params)
def parse_stairway(params): template = re.compile( '(\d+),\s*(\d+),\s*(\d+),\s*([0-9.]+[dhms]?)+\)') s_res = template.search(params) if s_res: initial_instances, final_instances, step_size, step_duration = s_res.groups( ) self.stairway(int(initial_instances), int(final_instances), int(step_size), parse_duration(step_duration)) else: self.log.info( "Stairway step format: 'step(<initial_instances>, <final_instances>, <step_size>, <step_duration>)'" ) raise StepperConfigurationError( "Error in step configuration: 'step(%s'" % params)
def line(params): template = re.compile('([0-9.]+),\s*([0-9.]+),\s*([0-9.]+[dhms]?)+\)') minrps, maxrps, duration = template.search(params).groups() return Line(float(minrps), float(maxrps), parse_duration(duration))
def line(params): template = re.compile('(\d+),\s*(\d+),\s*([0-9.]+[dhms]?)+\)') minrps, maxrps, duration = template.search(params).groups() # note that we don't use minrps at all and use maxrps # as the number of instances we gonna start return Line(int(maxrps) - int(minrps), parse_duration(duration))
def stairway(params): template = re.compile('([0-9.]+),\s*([0-9.]+),\s*([0-9.]+),\s*([0-9.]+[dhms]?)+\)') minrps, maxrps, increment, duration = template.search(params).groups() return Stairway(float(minrps), float(maxrps), float(increment), parse_duration(duration))
def loop(): while not stopped.wait(parse_duration(interval).seconds): cycle(context)
def stairway(params): template = re.compile( '([0-9.]+),\s*([0-9.]+),\s*([0-9.]+),\s*([0-9.]+[dhms]?)+\)') minrps, maxrps, increment, duration = template.search(params).groups() return Stairway(float(minrps), float(maxrps), float(increment), parse_duration(duration))
def const(params): template = re.compile('([0-9.]+),\s*([0-9.]+[dhms]?)+\)') rps, duration = template.search(params).groups() return Const(float(rps), parse_duration(duration))
def wait(params): template = re.compile('([0-9.]+[dhms]?)+\)') duration = template.search(params).groups()[0] return Wait(parse_duration(duration))
def ramp(params): template = re.compile('(\d+),\s*([0-9.]+[dhms]?)+\)') instances, interval = template.search(params).groups() return Ramp(int(instances), parse_duration(interval))
def objects_max_age(ctx, obj: typing.Union[client.V1Deployment, client.V1DaemonSet]): if ctx.obj['max_age_label'] in obj.metadata.labels: return parse_duration(obj.metadata.labels[ctx.obj['max_age_label']]) return parse_duration(ctx.obj['default_max_age'])