Validators#

Collection of descriptors to verify types and conditions of the Machine attributes when loading.

And example of which is if the machine name is set to a value which isn’t a valid URL string, thus causing early failure before k8s itself discovers that the name isn’t valid. (See: gordo.machine.validators.ValidUrlString)

class gordo.machine.validators.BaseDescriptor[source]#

Bases: object

Base descriptor class

New object should override __set__(self, instance, value) method to check if ‘value’ meets required needs.

class gordo.machine.validators.ValidDataProvider[source]#

Bases: BaseDescriptor

Descriptor for DataProvider

class gordo.machine.validators.ValidDataset[source]#

Bases: BaseDescriptor

Descriptor for attributes requiring type gordo_core.time_series.TimeSeriesDataset

class gordo.machine.validators.ValidDatasetKwargs[source]#

Bases: BaseDescriptor

Descriptor for attributes requiring type gordo_core.time_series.TimeSeriesDataset

class gordo.machine.validators.ValidDatetime[source]#

Bases: BaseDescriptor

Descriptor for attributes requiring valid datetime.datetime attribute

class gordo.machine.validators.ValidMachineRuntime[source]#

Bases: BaseDescriptor

Descriptor for runtime dict in a machine object. Must be a valid runtime, but also must contain server.resources.limits/requests.memory/cpu to be valid.

class gordo.machine.validators.ValidMetadata[source]#

Bases: BaseDescriptor

Descriptor for attributes requiring type Optional[dict]

class gordo.machine.validators.ValidModel[source]#

Bases: BaseDescriptor

Descriptor for attributes requiring type Union[dict, str]

class gordo.machine.validators.ValidTagList[source]#

Bases: BaseDescriptor

Descriptor for attributes requiring a non-empty list of strings

class gordo.machine.validators.ValidUrlString[source]#

Bases: BaseDescriptor

Descriptor for use in objects which require valid URL values. Where ‘valid URL values’ is Gordo’s version: alphanumeric with dashes.

Use:

class MySpecialClass:

    url_attribute = ValidUrlString()

    ...

myspecialclass = MySpecialClass()

myspecialclass.url_attribute = 'this-is-ok'
myspecialclass.url_attribute = 'this will r@ise a ValueError'
static valid_url_string(string: str) bool[source]#

What we (Gordo) deem to be a suitable URL is the same as kubernetes lowercase alphanumeric with dashes but not ending or starting with a dash

Parameters:

string – String to check

gordo.machine.validators.fix_resource_limits(resources: dict) dict[source]#

Resource limitations must be higher or equal to resource requests, if they are both specified. This bumps any limits to the corresponding request if they are both set.

Parameters:

resources – Dictionary with possible requests/limits

Examples

>>> fix_resource_limits({"requests": {"cpu": 10}, "limits":{"cpu":9}})
{'requests': {'cpu': 10}, 'limits': {'cpu': 10}}
>>> fix_resource_limits({"requests": {"cpu": 10}})
{'requests': {'cpu': 10}}
Returns:

  • A copy of resource_dict with the any limits bumped to the corresponding request if

  • they are both set.

gordo.machine.validators.fix_runtime(runtime_dict)[source]#

A valid runtime description must satisfy that any resource description must have that limit >= requests. This function will bump any limits that is too low.