Esempio n. 1
0
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
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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))
Esempio n. 11
0
 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))
Esempio n. 12
0
 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))
Esempio n. 13
0
 def loop():
     while not stopped.wait(parse_duration(interval).seconds):
         cycle(context)
Esempio n. 14
0
 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))
Esempio n. 15
0
 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))
Esempio n. 16
0
 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))
Esempio n. 17
0
 def wait(params):
     template = re.compile('([0-9.]+[dhms]?)+\)')
     duration = template.search(params).groups()[0]
     return Wait(parse_duration(duration))
Esempio n. 18
0
 def ramp(params):
     template = re.compile('(\d+),\s*([0-9.]+[dhms]?)+\)')
     instances, interval = template.search(params).groups()
     return Ramp(int(instances), parse_duration(interval))
Esempio n. 19
0
 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))
Esempio n. 20
0
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'])