Repository: apache/airflow
File: helm-tests/tests/helm_tests/airflow_aux/test_pod_template_file.py (Python)

Code before:
                {
                    "kerberosInitContainer": {
                        "enabled": True,
                        "containerLifecycleHooks": {"postStart": {"exec": {"command": ["echo", "base"]}}},
                    }
                },
                {"postStart": {"exec": {"command": ["echo", "base"]}}},
            ),
            (
                {
                    "kubernetes": {
                        "kerberosInitContainer": {
                            "enabled": True,
                            "containerLifecycleHooks": {
                                "postStart": {"exec": {"command": ["echo", "kubernetes"]}}
                            },
                        }
                    }
                },
                {"postStart": {"exec": {"command": ["echo", "kubernetes"]}}},
            ),
            (
                {
                    "kerberosInitContainer": {
                        "enabled": True,
                        "containerLifecycleHooks": {"postStart": {"exec": {"command": ["echo", "base"]}}},
                    },
                    "kubernetes": {
                        "kerberosInitContainer": {
                            "enabled": True,
                            "containerLifecycleHooks": {
                                "postStart": {"exec": {"command": ["echo", "kubernetes"]}}
                            },
                        }
                    },
                },
                {"postStart": {"exec": {"command": ["echo", "kubernetes"]}}},
            ),
        ],
    )
    def test_kerberos_init_container_lifecycle_hooks(self, workers_values, expected):
        docs = render_chart(
            values={
                "workers": workers_values,
            },
            show_only=["templates/pod-template-file.yaml"],
            chart_dir=self.temp_chart_dir,
        )

        assert (
            jmespath.search("spec.initContainers[?name=='kerberos-init'] | [0].lifecycle", docs[0])

Review comment (suggestion):
```suggestion
                        "containerLifecycleHooks": {"preStop": {"exec": {"command": ["echo", "base"]}}},
```
`preStop` because we want to be sure that the overwrite and fallback logic works fully correct (there will be no `preStop` and `postStart` defined at the same time looking at the new test conf)

Code after:
                    "kubernetes": {
                        "kerberosInitContainer": {
                            "enabled": True,
                            "containerLifecycleHooks": {
                                "postStart": {"exec": {"command": ["echo", "kubernetes"]}}
                            },
                        }
                    }
                },
                {"postStart": {"exec": {"command": ["echo", "kubernetes"]}}},
            ),
            (
                {
                    "kerberosInitContainer": {
                        "enabled": True,
                        "containerLifecycleHooks": {"preStop": {"exec": {"command": ["echo", "base"]}}},
                    },
                    "kubernetes": {
                        "kerberosInitContainer": {
                            "enabled": True,
                            "containerLifecycleHooks": {
                                "postStart": {"exec": {"command": ["echo", "kubernetes"]}}
                            },
                        }
                    },
                },
                {"postStart": {"exec": {"command": ["echo", "kubernetes"]}}},
            ),
        ],
    )
    def test_kerberos_init_container_lifecycle_hooks(self, workers_values, expected):
        docs = render_chart(
            values={
                "workers": workers_values,
            },
            show_only=["templates/pod-template-file.yaml"],
            chart_dir=self.temp_chart_dir,
        )

        assert (
            jmespath.search("spec.initContainers[?name=='kerberos-init'] | [0].lifecycle", docs[0])
            == expected
        )