Exemplo n.º 1
0
 def test_add_external_load_balancer_definition_to_ui_service(self):
     external_load_balancer_factory = K8sDescriptorFactory(
         self.TEMPLATE_PATH, self.PROPERTIES_FOR_UI_SERVICE,
         self.AWS_CONNECTOR)
     no_external_load_balancer_factory = K8sDescriptorFactory(
         self.TEMPLATE_PATH, {
             'serviceColor': 'green',
             'serviceType': Recipe.SERVICE_TYPE_API
         }, self.AWS_CONNECTOR)
     assert self.__assert_external_lb_in_annotations(
         external_load_balancer_factory.service()) is True
     assert self.__assert_external_lb_in_annotations(
         no_external_load_balancer_factory.service()) is False
Exemplo n.º 2
0
 def test_add_internal_load_balancer_definition_to_service(self):
     internal_load_balancer_factory = K8sDescriptorFactory(
         self.TEMPLATE_PATH, {
             'serviceColor': 'green',
             'serviceType': Recipe.SERVICE_TYPE_INTERNAL_UI
         }, self.AWS_CONNECTOR)
     no_internal_load_balancer_factory = K8sDescriptorFactory(
         self.TEMPLATE_PATH, {
             'serviceColor': 'green',
             'serviceType': Recipe.SERVICE_TYPE_API
         }, self.AWS_CONNECTOR)
     assert self.__assert_internal_LB_in_annotations(
         internal_load_balancer_factory.service()) is True
     assert self.__assert_internal_LB_in_annotations(
         no_internal_load_balancer_factory.service()) is False
Exemplo n.º 3
0
 def test_metrics_should_be_disabled(self):
     service_path = K8sDescriptorFactory(
         self.TEMPLATE_PATH, {
             'serviceColor': 'green',
             'serviceType': Recipe.SERVICE_TYPE_INTERNAL_UI
         }, self.AWS_CONNECTOR).service()
     assert self.__assert_prometheus_enabled(service_path) is False
Exemplo n.º 4
0
 def test_add_port_definition_to_service(self):
     factory = K8sDescriptorFactory(self.TEMPLATE_PATH, {
         'serviceColor': 'green',
         'serviceType': Recipe.SERVICE_TYPE_API
     }, self.AWS_CONNECTOR)
     with open(factory.service(), 'r') as f:
         ports = yaml.load(f)['spec']['ports']
         assert {'targetPort': 8080, 'port': 80, 'name': 'tcp-80'} in ports
Exemplo n.º 5
0
 def test_add_port_definition_to_deployment(self):
     factory = K8sDescriptorFactory(self.TEMPLATE_PATH, {
         'ports': ['50:5000'],
         'name': 'kuku'
     }, self.AWS_CONNECTOR)
     with open(factory.deployment(), 'r') as f:
         deployment = yaml.load(f)
         ports = deployment['spec']['template']['spec']['containers'][0][
             'ports']
         assert {'containerPort': 5000} in ports
Exemplo n.º 6
0
 def test_metrics_should_be_enabled(self):
     service_path = K8sDescriptorFactory(
         self.TEMPLATE_PATH, {
             'serviceColor': 'green',
             'serviceType': Recipe.SERVICE_TYPE_API,
             'metrics': {
                 'enabled': True
             }
         }, self.AWS_CONNECTOR).service()
     assert self.__assert_prometheus_enabled(service_path) is True
Exemplo n.º 7
0
    def test_certificate_was_set_to_ui_service(self):
        external_load_balancer_factory = K8sDescriptorFactory(
            self.TEMPLATE_PATH, self.PROPERTIES_FOR_UI_SERVICE,
            self.AWS_CONNECTOR)

        service_path = external_load_balancer_factory.service()
        assert self.AWS_CONNECTOR._called_with_domain() == (
            '*.%s' % self.PROPERTIES_FOR_UI_SERVICE['domain'])
        assert self.__assert_external_lb_has_certificate(
            service_path, self.AWS_CONNECTOR.CERTIFICATE)
Exemplo n.º 8
0
    def test_should_add_admin_privelege_to_deployment_when_admin_privileges_set(
            self):
        factory = K8sDescriptorFactory(self.TEMPLATE_PATH, {
            'adminPrivileges': True,
            'name': 'kuku'
        }, self.AWS_CONNECTOR)
        with open(factory.deployment(), 'r') as f:
            deployment = yaml.load(f)

            assert self.docker_volume_mount() in self.deployment_volume_mounts(
                deployment)
            assert self.docker_socket_volume() in self.spec_volumes(deployment)
Exemplo n.º 9
0
    def test_should_create_ingress(self):
        factory = K8sDescriptorFactory(
            self.TEMPLATE_PATH, {
                'ingressInfo': {
                    'enabled': True,
                    'host': 'mich.dev.io'
                },
                'serviceName': 'kuku'
            }, self.AWS_CONNECTOR)

        with open(factory.ingress(), 'r') as f:
            assert yaml.load(f)['spec']['rules'] == \
                   [{'host': 'mich.dev.io',
                     'http': {'paths': [{'path': '/', 'backend': {'serviceName': 'kuku', 'servicePort': 8080}}]}}]
Exemplo n.º 10
0
    def test_should_create_autoscale(self):
        factory = K8sDescriptorFactory(
            self.TEMPLATE_PATH, {
                'autoScaleInfo': {
                    'minPods': 1,
                    'enabled': True,
                    'cpu': 'low',
                    'maxPods': 3
                },
                'name': 'kuku'
            }, self.AWS_CONNECTOR)

        with open(factory.autoscale(), 'r') as f:
            autoscale = yaml.load(f)
            assert autoscale['metadata']['name'] == 'kuku'
            assert autoscale['spec']['scaleTargetRef']['name'] == 'kuku'
            assert autoscale['spec']['minReplicas'] == 1
            assert autoscale['spec']['maxReplicas'] == 3
            assert autoscale['spec']['targetCPUUtilizationPercentage'] == 90
Exemplo n.º 11
0
 def __create_service(self, configuration):
     factory = K8sDescriptorFactory(self.TEMPLATE_PATH, configuration,
                                    self.AWS_CONNECTOR)
     return factory.service()
Exemplo n.º 12
0
 def test_add_80_port_definition_to_ui_service(self):
     factory = K8sDescriptorFactory(self.TEMPLATE_PATH,
                                    self.PROPERTIES_FOR_UI_SERVICE,
                                    self.AWS_CONNECTOR)
     assert self.__assert_port_with_number(80, factory.service()) is True