예제 #1
0
 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')
예제 #2
0
파일: nullable.py 프로젝트: enamrik/krogon
 def to_maybe(self):
     if len(self.keys()) == 0:
         return M.nothing()
     else:
         return M.just(self.to_map())
예제 #3
0
 def with_init_containers(self, init_containers: List[K8sContainer]):
     self.init_containers = M.just(init_containers)
     return self
예제 #4
0
 def with_command(self, command_args: List[str]):
     self.command = M.just(command_args)
     return self
예제 #5
0
def test_from_maybe_can_return_on_value():
    assert M.just(1) \
           | M.from_maybe | dict(
        if_just=lambda x: x + 1,
        if_nothing=lambda: "nothing") == 2
예제 #6
0
def test_can_ignore_catch_nothing_if_value():
    assert M.just(2) | M.catch_nothing | (lambda: 1) == M.just(2)
예제 #7
0
def test_can_catch_nothing_and_return_value():
    assert M.nothing() | M.catch_nothing | (lambda: 1) == M.just(1)
예제 #8
0
def test_can_make_just_maybe():
    assert M.just(1) == ("just", 1)
예제 #9
0
def test_can_chain_maybe():
    assert M.just(1) | M.then | (lambda _: M.nothing()) == M.nothing()
예제 #10
0
def test_can_chain_just_maybe_and_wrap_non_maybe_result():
    assert M.just(1) | M.then | (lambda x: x + 1) == M.just(2)
예제 #11
0
def test_can_chain_just_maybe():
    assert M.just(1) | M.then | (lambda x: M.just(x + 1)) == M.just(2)
예제 #12
0
def test_can_map_just_maybe():
    assert M.just(1) | M.map | (lambda x: x + 1) == M.just(2)
예제 #13
0
 def with_command(self, command: str):
     self.command = M.just(command)
     return self
예제 #14
0
def test_will_append_to_list_if_value():
    assert nlist([1]).append_if_value(M.just(2)) == [1, 2]
예제 #15
0
def test_will_append_to_map_if_value():
    assert nmap({'a': 1}).append_if_value('b', M.just(2)) == {'a': 1, 'b': 2}
예제 #16
0
def test_will_concat_list_if_value():
    assert nlist([1, 2]).append_if_list(M.just([3, 4])) == [1, 2, 3, 4]