def __init__(self, name: str, image: str): self.name = name self.image = image self.containers = [] self.environment_vars = [] self.environment_vars_from_context = [] self.command = M.nothing() self.resources = M.nothing() self.volumes = [] self.app_ports = []
def __init__(self, name: str, image: str): super().__init__() self.name = name self.image = image self.command = M.nothing() self.environment_vars = [] self.schedule = '* * * * *' self.suspend = True
def map_context(self, context: TemplateContext) -> TemplateContext: if self._is_ambassador(context): context.append_templates([{ 'apiVersion': 'getambassador.io/v1', 'kind': 'Mapping', 'metadata': { 'name': self.name + '-mapping' }, 'spec': nmap({ 'prefix': '/', 'service': self.service + str( M.map(self.port, (lambda x: ':' + str(x))) | M.value_or_default | '') }).append_if_value( 'host', M.nothing() if self.host == '*' else M.just(self.host)).to_map() }]) return context if self._is_istio(context): context.append_templates([{ 'apiVersion': 'networking.istio.io/v1alpha3', 'kind': 'VirtualService', 'metadata': { 'name': self.name + '-vs' }, 'spec': { 'hosts': [self.host], 'gateways': [self.gateway_name], 'http': nlist([ nmap({ 'route': [{ 'destination': nmap({ 'host': self.service }).append_if_value( 'port', M.map(self.port, (lambda x: { 'number': x }))).to_map() }] }).to_map(), ]).to_list() } }]) return context raise AssertionError('Unsupported gateway')
def __init__(self, name: str): self.name = name self.replicas = 1 self.containers = [] self.init_containers: M.Maybe[List[K8sContainer]] = M.nothing() self.volumes = [] self.strategy = { 'type': 'RollingUpdate', 'rollingUpdate': { 'maxSurge': '25%', 'maxUnavailable': '25%' } }
def __init__(self, name: str, image: str, app_port: int): self.name = name self.image = image self.app_port = app_port self.service_port = 80 self.environment_vars = [] self.command = M.nothing() self.resources = M.nothing() self.sidecars: List[K8sContainer] = [] self.init_containers: M.Maybe[List[K8sContainer]] = M.nothing() self.volumes = [] self.min_replicas: int = 1 self.max_replicas: int = 3 self.cpu_threshold_percentage: int = 50 self.service_type: str = 'ClusterIP' self.annotations: dict = {} self.strategy = { 'type': 'RollingUpdate', 'rollingUpdate': { 'maxSurge': '25%', 'maxUnavailable': '25%' } }
def to_maybe(self): if len(self.keys()) == 0: return M.nothing() else: return M.just(self.to_map())
def test_can_make_nothing_maybe(): assert M.nothing() == ("nothing", None)
def test_from_maybe_can_return_on_nothing(): assert M.nothing() \ | M.from_maybe | dict( if_just=lambda _: None, if_nothing=lambda: "defaultValue") == "defaultValue"
def test_can_catch_nothing_and_return_value(): assert M.nothing() | M.catch_nothing | (lambda: 1) == M.just(1)
def test_can_chain_maybe(): assert M.just(1) | M.then | (lambda _: M.nothing()) == M.nothing()
def test_can_map_nothing_maybe(): assert M.nothing() | M.map | (lambda x: x + 1) == M.nothing()
def test_will_ignore_append_list_if_nothing(): assert nlist([1]).append_if_value(M.nothing()) == [1]
def test_will_ignore_append_to_map_if_nothing(): assert nmap({'a': 1}).append_if_value('b', M.nothing()) == {'a': 1}
def test_will_ignore_list_if_nothing(): assert nlist([1, 2]).append_if_list(M.nothing()) == [1, 2]