From 1a2e8cf6a1406a0d30156a9d406f6736138c94a3 Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Tue, 14 Jan 2025 18:47:07 +0100 Subject: [PATCH] Fail if streams-boostrap v3 model is instantiated with v2 attribute (#587) --- kpops/components/streams_bootstrap/model.py | 9 ++++++++ .../test_streams_bootstrap.py | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/kpops/components/streams_bootstrap/model.py b/kpops/components/streams_bootstrap/model.py index bc70e37e5..6a5cf4f66 100644 --- a/kpops/components/streams_bootstrap/model.py +++ b/kpops/components/streams_bootstrap/model.py @@ -228,6 +228,15 @@ class StreamsBootstrapValues(SerializeAsOptionalModel, HelmAppValues): description=describe_attr("tolerations", __doc__), ) + @pydantic.model_validator(mode="before") + @classmethod + def unsupported_attributes(cls, values: Any) -> Any: + for attr in ("streams",): + if attr in values: + msg = f"streams-bootstrap v3 no longer supports '{attr}' attribute." + raise ValueError(msg) + return values + class KafkaConfig(CamelCaseConfigModel, DescConfigModel): """Kafka Streams config. diff --git a/tests/components/streams_bootstrap/test_streams_bootstrap.py b/tests/components/streams_bootstrap/test_streams_bootstrap.py index b0b8f0f07..526f64ddc 100644 --- a/tests/components/streams_bootstrap/test_streams_bootstrap.py +++ b/tests/components/streams_bootstrap/test_streams_bootstrap.py @@ -133,6 +133,27 @@ async def test_should_raise_validation_error_for_invalid_helm_chart_version(self }, ) + def test_should_raise_validation_error_for_unsupported_attribute(self): + with pytest.raises( + ValueError, + match=re.escape( + "streams-bootstrap v3 no longer supports 'streams' attribute." + ), + ): + assert StreamsBootstrap.model_validate( + { + "name": "example-name", + "namespace": "test-namespace", + "values": { + "image": "streamsBootstrap", + "kafka": { + "bootstrapServers": "localhost:9092", + }, + "streams": {}, + }, + }, + ) + @pytest.mark.parametrize( ("input", "expectation"), [