Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connector resetter offset topic #497

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions kpops/components/base_components/kafka_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import cached_property
from typing import Any, NoReturn

import pydantic
from pydantic import Field, PrivateAttr, ValidationInfo, computed_field, field_validator
from typing_extensions import override

Expand All @@ -25,6 +26,11 @@
from kpops.utils.colorify import magentaify
from kpops.utils.docstring import describe_attr

try:
from typing import Self # pyright: ignore[reportAttributeAccessIssue]
except ImportError:
from typing_extensions import Self

log = logging.getLogger("KafkaConnector")


Expand Down Expand Up @@ -205,6 +211,12 @@ class KafkaSourceConnector(KafkaConnector):

_connector_type: KafkaConnectorType = PrivateAttr(KafkaConnectorType.SOURCE)

@pydantic.model_validator(mode="after")
def populate_offset_topic(self) -> Self:
if self.offset_topic:
self._resetter.app.config.offset_topic = self.offset_topic
return self

@computed_field
@cached_property
def _resetter(self) -> KafkaConnectorResetter:
Expand All @@ -217,13 +229,11 @@ def apply_from_inputs(self, name: str, topic: FromTopic) -> NoReturn:

@override
async def reset(self, dry_run: bool) -> None:
self._resetter.app.config.offset_topic = self.offset_topic
await self._resetter.reset(dry_run)

@override
async def clean(self, dry_run: bool) -> None:
await super().clean(dry_run)
self._resetter.app.config.offset_topic = self.offset_topic
await self._resetter.clean(dry_run)


Expand Down
6 changes: 4 additions & 2 deletions kpops/utils/gen_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ def gen_pipeline_schema(
default=component.type,
)
core_schema: DefinitionsSchema = component.__pydantic_core_schema__ # pyright:ignore[reportAssignmentType]

model_schema: ModelFieldsSchema = core_schema["schema"]["schema"]["schema"] # pyright:ignore[reportGeneralTypeIssues,reportTypedDictNotRequiredAccess,reportAssignmentType]
schema = core_schema
while "schema" in schema:
schema = schema["schema"]
model_schema: ModelFieldsSchema = schema # pyright:ignore[reportAssignmentType]
model_schema["fields"]["type"] = ModelField(
type="model-field",
schema=LiteralSchema(
Expand Down
3 changes: 3 additions & 0 deletions tests/components/test_kafka_source_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def test_resetter_release_name(self, connector: KafkaSourceConnector):
assert isinstance(resetter, KafkaConnectorResetter)
assert connector._resetter.helm_release_name == CONNECTOR_CLEAN_RELEASE_NAME

def test_resetter_offset_topic(self, connector: KafkaSourceConnector):
assert connector._resetter.app.config.offset_topic == OFFSETS_TOPIC

def test_from_section_raises_exception(
self,
config: KpopsConfig,
Expand Down
Loading