Beispiel #1
0
    def create(self, namespace: str, body: MockV1Service, **kwargs):
        if not body:
            raise ValueError("Missing the required parameter `body` "
                             "when calling `create_namespaced_service`")

        body = copy.copy(body)
        body.spec = V1ServiceSpec(**body.spec)
        body.status = V1ServiceStatus(**body.status)
        try:
            return super().create(namespace, body, **kwargs)
        except ValueError:
            raise ValueError("Missing the required parameter `body` "
                             "when calling `create_namespaced_service`")
 def test_expected_remove_service_event(self, mock_remove_host):  #pylint: disable=invalid-name
     ''' test recieving a normal deleted event for the service we are expecting '''
     event = {
         'type':
         'DELETED',
         'object':
         V1Service(
             api_version='v1',
             kind='Service',
             metadata=V1ObjectMeta(
                 name='myregistry',
                 namespace='testnamespace',
             ),
             spec=V1ServiceSpec(cluster_ip='10.0.0.1'),
         ),
     }
     watcher = hostess.Watcher(env=self.envvars)
     watcher.handle_service_event(event)
     mock_remove_host.assert_called_with(self=watcher,
                                         fqdn=self.envvars['SHADOW_FQDN'])
 def test_unexpected_service_event(self):
     ''' test recieving an abnormal event for the service we are expecting '''
     event = {
         'type':
         'UNKNOWN',
         'object':
         V1Service(
             api_version='v1',
             kind='Service',
             metadata=V1ObjectMeta(
                 name='myregistry',
                 namespace='testnamespace',
             ),
             spec=V1ServiceSpec(cluster_ip='10.0.0.1'),
         ),
     }
     watcher = hostess.Watcher(env=self.envvars)
     log = logging.getLogger()
     log.setLevel(logging.INFO)
     with self.assertLogs(log, level='INFO') as context_manager:
         watcher.handle_service_event(event)
         self.assertIn(
             'WARNING:hostess.watcher:Unexpected event type {}'.format(
                 'UNKNOWN'), context_manager.output)
 def test_unexpected_add_service_event(self):  #pylint: disable=invalid-name
     ''' test recieving a normal added event for a service we are not expecting '''
     event = {
         'type':
         'ADDED',
         'object':
         V1Service(
             api_version='v1',
             kind='Service',
             metadata=V1ObjectMeta(
                 name='someservice',
                 namespace='othernamespace',
             ),
             spec=V1ServiceSpec(cluster_ip='10.0.0.5'),
         ),
     }
     watcher = hostess.Watcher(env=self.envvars)
     log = logging.getLogger()
     log.setLevel(logging.INFO)
     with self.assertLogs(log, level='DEBUG') as context_manager:
         watcher.handle_service_event(event)
         self.assertIn(
             'DEBUG:hostess.watcher:Ignoring event for {} in {}'.format(
                 'someservice', 'othernamespace'), context_manager.output)
Beispiel #5
0
complex_job = Job(
    configuration_cls=AppConfiguration,
    objects=[
        AppsV1beta1Deployment(
            metadata=V1ObjectMeta(name=AppConfiguration.name, ),
            spec=AppsV1beta1DeploymentSpec(
                replicas=2,
                template=V1PodTemplateSpec(
                    metadata=V1ObjectMeta(
                        name='pod-name',
                        labels={
                            'app': 'foo-app',
                        },
                    ),
                    spec=V1PodSpec(containers=[
                        V1Container(
                            name='container-name',
                            command=[
                                'sh', '-c', 'while date; do sleep 1; done'
                            ],
                            image='busybox',
                        ),
                    ], ),
                ),
            ),
        ),
        V1Service(metadata=V1ObjectMeta(name=AppConfiguration.service_name, ),
                  spec=V1ServiceSpec(selector={'app': 'foo-app'}))
    ])