def test_if_multiple_volumes_are_set(self):
        definition = {
            'kind': 'Deployment',
            'spec': {
                'template': {
                    'spec': {
                        'containers': [
                            {
                                'name': 'nginx-container',
                                'image': 'nginx',
                            },
                        ],
                    },
                },
            },
        }
        host_volumes = {
            'dev-volume': '/home',
            'tmp-volume': '/tmp',
        }

        new_definition = definition_transformers.add_host_volumes(definition, host_volumes=host_volumes)

        new_volumes = new_definition['spec']['template']['spec']['volumes']
        assert len(new_volumes) == 2
        assert {
            'name': 'dev-volume',
            'hostPath': {'path': '/home'},
        } in new_volumes
        assert {
            'name': 'tmp-volume',
            'hostPath': {'path': '/tmp'},
        } in new_volumes
    def test_if_volume_is_set(self):
        definition = {
            'kind': 'Deployment',
            'spec': {
                'template': {
                    'spec': {
                        'containers': [
                            {
                                'name': 'nginx-container',
                                'image': 'nginx',
                            },
                        ],
                    },
                },
            },
        }
        host_volumes = {
            'dev-volume': '/home',
        }

        new_definition = definition_transformers.add_host_volumes(definition, host_volumes=host_volumes)

        new_container_spec = new_definition['spec']['template']['spec']
        assert 'volumes' in new_container_spec
        assert new_container_spec['volumes'] == [{
            'name': 'dev-volume',
            'hostPath': {'path': '/home'},
        }]
Beispiel #3
0
def transform_pod_definition(definition, options):
    new_definition = copy.deepcopy(definition)
    new_definition = definition_transformers.tag_untaged_images(
        new_definition, options.build_tag)
    new_definition = definition_transformers.set_environment(
        new_definition, options.environment)
    new_definition = definition_transformers.add_host_volumes(
        new_definition, options.host_volumes)
    return new_definition