Repository: apache/airflow
File: helm-tests/tests/helm_tests/airflow_core/test_worker.py (Python)

Code before:
            {"persistence": {"storageClassName": "{{ .Release.Name }}-storage-class"}},
            {"celery": {"persistence": {"storageClassName": "{{ .Release.Name }}-storage-class"}}},
            {
                "persistence": {"storageClassName": "{{ .Release.Name }}"},
                "celery": {"persistence": {"storageClassName": "{{ .Release.Name }}-storage-class"}},
            },
        ],
    )
    def test_worker_template_storage_class_name(self, workers_values):
        docs = render_chart(
            values={"workers": workers_values},
            show_only=["templates/workers/worker-deployment.yaml"],
        )
        assert (
            jmespath.search("spec.volumeClaimTemplates[0].spec.storageClassName", docs[0])
            == "release-name-storage-class"
        )

    @pytest.mark.parametrize(
        ("workers_values", "expected"),
        [
            ({"replicas": 2}, 1),
            ({"celery": {"replicas": 2}}, 2),
            ({"celery": {"replicas": None}}, 1),
            ({"replicas": 2, "celery": {"replicas": 3}}, 3),
            ({"replicas": 2, "celery": {"replicas": None}}, 2),
        ],
    )
    def test_workers_replicas(self, workers_values, expected):
        docs = render_chart(
            values={"workers": workers_values},
            show_only=["templates/workers/worker-deployment.yaml"],
        )

        assert expected == jmespath.search("spec.replicas", docs[0])

    @pytest.mark.parametrize(
        "workers_values",
        [
            {"persistence": {"size": "50Gi"}, "celery": {"persistence": {"size": None}}},
            {"celery": {"persistence": {"size": "50Gi"}}},
            {"persistence": {"size": "10Gi"}, "celery": {"persistence": {"size": "50Gi"}}},
        ],
    )
    def test_template_storage_size(self, workers_values):
        docs = render_chart(
            values={
                "workers": workers_values,
                "logs": {"persistence": {"enabled": False}},
            },
            show_only=["templates/workers/worker-deployment.yaml"],

Review comment (suggestion):
With moving from `workers.replicas` to `workers.celery.replicas`, we want to make sure that when users unset the `workers.celery.replicas` field, the behaviour will be as in previous releases (because we changed how chart behaves in replicas handling). Why was this change made?

I see now locally that this was changed as the default behaviour was changed. `workers.replicas`, if `workers.celery.replicas` is unset, does't change the value of replicas. I think it should be fixed in the template logic, not in the test case itself

Code after:
            {"persistence": {"storageClassName": "{{ .Release.Name }}-storage-class"}},
            {"celery": {"persistence": {"storageClassName": "{{ .Release.Name }}-storage-class"}}},
            {
                "persistence": {"storageClassName": "{{ .Release.Name }}"},
                "celery": {"persistence": {"storageClassName": "{{ .Release.Name }}-storage-class"}},
            },
        ],
    )
    def test_worker_template_storage_class_name(self, workers_values):
        docs = render_chart(
            values={"workers": workers_values},
            show_only=["templates/workers/worker-deployment.yaml"],
        )
        assert (
            jmespath.search("spec.volumeClaimTemplates[0].spec.storageClassName", docs[0])
            == "release-name-storage-class"
        )

    @pytest.mark.parametrize(
        ("workers_values", "expected"),
        [
            ({"replicas": 2}, 1),
            ({"celery": {"replicas": 2}}, 2),
            ({"celery": {"replicas": None}}, 1),
            ({"replicas": 2, "celery": {"replicas": 3}}, 3),
            ({"replicas": 2, "celery": {"replicas": 2}}, 2),
        ],
    )
    def test_workers_replicas(self, workers_values, expected):
        docs = render_chart(
            values={"workers": workers_values},
            show_only=["templates/workers/worker-deployment.yaml"],
        )

        assert expected == jmespath.search("spec.replicas", docs[0])

    @pytest.mark.parametrize(
        "workers_values",
        [
            {"persistence": {"size": "50Gi"}, "celery": {"persistence": {"size": None}}},
            {"celery": {"persistence": {"size": "50Gi"}}},
            {"persistence": {"size": "10Gi"}, "celery": {"persistence": {"size": "50Gi"}}},
        ],
    )
    def test_template_storage_size(self, workers_values):
        docs = render_chart(
            values={
                "workers": workers_values,
                "logs": {"persistence": {"enabled": False}},
            },
            show_only=["templates/workers/worker-deployment.yaml"],