def test_if_environment_is_set(self):
        definition = {
            'kind': 'Deployment',
            'spec': {
                'template': {
                    'spec': {
                        'containers': [
                            {
                                'name': 'nginx-container',
                                'image': 'nginx',
                            },
                        ],
                    },
                },
            },
        }
        new_environment = {
            'DEBUG': 'true',
        }

        new_definition = definition_transformers.set_environment(definition, new_environment=new_environment)

        new_container_spec = new_definition['spec']['template']['spec']['containers'][0]
        assert 'env' in new_container_spec
        assert new_container_spec['env'] == [{
            'name': 'DEBUG',
            'value': 'true',
        }]
    def test_if_multiple_environment_values_are_set(self):
        definition = {
            'kind': 'Deployment',
            'spec': {
                'template': {
                    'spec': {
                        'containers': [
                            {
                                'name': 'nginx-container',
                                'image': 'nginx',
                            },
                        ],
                    },
                },
            },
        }
        new_environment = {
            'DEBUG': 'true',
            'CONFIGURATION': 'development',
        }

        new_definition = definition_transformers.set_environment(definition, new_environment=new_environment)

        new_container_environment = new_definition['spec']['template']['spec']['containers'][0]['env']
        assert len(new_container_environment) == 2
        assert {
            'name': 'DEBUG',
            'value': 'true',
        } in new_container_environment
        assert {
            'name': 'CONFIGURATION',
            'value': 'development',
        } in new_container_environment
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
Beispiel #4
0
    def test_if_existing_environment_is_updated(self):
        definition = {
            'kind': 'Deployment',
            'spec': {
                'template': {
                    'spec': {
                        'containers': [
                            {
                                'name': 'nginx-container',
                                'image': 'nginx',
                                'env': [{
                                    'name': 'DEBUG',
                                    'value': 'false',
                                }],
                            },
                        ],
                    },
                },
            },
        }
        new_environment = {
            'DEBUG': 'true',
        }

        new_definition = definition_transformers.set_environment(
            definition, new_environment=new_environment)

        old_environment = definition['spec']['template']['spec']['containers'][
            0]['env']
        assert old_environment == [{
            'name': 'DEBUG',
            'value': 'false',
        }]
        environment = new_definition['spec']['template']['spec']['containers'][
            0]['env']
        assert environment == [{
            'name': 'DEBUG',
            'value': 'true',
        }]
Beispiel #5
0
    def test_if_every_container_has_environment_set(self):
        definition = {
            'kind': 'Deployment',
            'spec': {
                'template': {
                    'spec': {
                        'containers': [
                            {
                                'name': 'nginx-container',
                                'image': 'nginx',
                            },
                            {
                                'name': 'redis-container',
                                'image': 'redis',
                            },
                        ],
                    },
                },
            },
        }
        environment = {
            'DEBUG': 'true',
        }

        new_definition = definition_transformers.set_environment(
            definition, new_environment=environment)

        new_nginx_environment = new_definition['spec']['template']['spec'][
            'containers'][0]['env']
        new_redis_environment = new_definition['spec']['template']['spec'][
            'containers'][1]['env']
        assert new_nginx_environment == [{
            'name': 'DEBUG',
            'value': 'true',
        }]
        assert new_redis_environment == [{
            'name': 'DEBUG',
            'value': 'true',
        }]
Beispiel #6
0
    def test_if_existing_environment_is_preserved(self):
        definition = {
            'kind': 'Deployment',
            'spec': {
                'template': {
                    'spec': {
                        'containers': [
                            {
                                'name': 'nginx-container',
                                'image': 'nginx',
                                'env': [{
                                    'name': 'DEBUG',
                                    'value': 'false',
                                }],
                            },
                        ],
                    },
                },
            },
        }
        new_environment = {
            'CONFIGURATION': 'development',
        }

        new_definition = definition_transformers.set_environment(
            definition, new_environment=new_environment)

        environment = new_definition['spec']['template']['spec']['containers'][
            0]['env']
        assert len(environment) == 2
        assert {
            'name': 'DEBUG',
            'value': 'false',
        } in environment
        assert {
            'name': 'CONFIGURATION',
            'value': 'development',
        } in environment