Skip to content

Commit

Permalink
move fetching of image tag to clean
Browse files Browse the repository at this point in the history
  • Loading branch information
raminqaf committed Jul 9, 2024
1 parent 2b54163 commit b482f7f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
3 changes: 3 additions & 0 deletions kpops/components/base_components/kafka_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ async def clean(self, dry_run: bool) -> None:
log.info(f"Uninstall old cleanup job for {self.helm_release_name}")
await self.destroy(dry_run)

image_tag = self.fetch_image_tag()
self.app.image_tag = image_tag

log.info(f"Init cleanup job for {self.helm_release_name}")
await self.deploy(dry_run)

Expand Down
35 changes: 16 additions & 19 deletions kpops/components/streams_bootstrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,26 @@ class StreamsBootstrap(HelmApp, ABC):
)

@cached_property
def app_values(self) -> dict[str, Any]:
streams_bootstrap_app_values = self.model_dump(
by_alias=True, exclude={"_cleaner", "from_", "to"}
)
def cleaner_values(self) -> dict[str, Any]:
return self.model_dump(by_alias=True, exclude={"_cleaner", "from_", "to"})

def fetch_image_tag(self) -> str:
"""Fetch the image tag of the streams-bootstrap app using the 'helm get values' command.
If the release doesn't exist, it will fall back to the specified imageTag in the default.yaml/pipeline.yaml
:return: Image tag of the streams-bootstrap app
"""
cluster_values = self.helm.get_values(self.namespace, self.helm_release_name)
streams_bootstrap_app_values = StreamsBootstrapValues(
**self.model_dump(by_alias=True, exclude={"_cleaner", "from_", "to"})
)
return (
streams_bootstrap_app_values
if cluster_values is None
else self.replace_image_tag_with_cluster_image_tag(
cluster_values, streams_bootstrap_app_values
)
cluster_values["imageTag"]
if cluster_values
else streams_bootstrap_app_values.image_tag
)

@staticmethod
def replace_image_tag_with_cluster_image_tag(
cluster_values: dict[str, Any], streams_bootstrap_app_values: dict[str, Any]
) -> dict[str, Any]:
app_values = streams_bootstrap_app_values.get("app")
if app_values:
app_values["imageTag"] = cluster_values["imageTag"]

return streams_bootstrap_app_values

@pydantic.model_validator(mode="after")
def warning_for_latest_image_tag(self) -> Self:
if self.validate_ and self.app.image_tag == "latest":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ProducerApp(KafkaApp, StreamsBootstrap):
@cached_property
def _cleaner(self) -> ProducerAppCleaner:
return ProducerAppCleaner(
config=self.config, handlers=self.handlers, **self.app_values
config=self.config, handlers=self.handlers, **self.cleaner_values
)

@override
Expand Down
2 changes: 1 addition & 1 deletion kpops/components/streams_bootstrap/streams/streams_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class StreamsApp(KafkaApp, StreamsBootstrap):
@cached_property
def _cleaner(self) -> StreamsAppCleaner:
return StreamsAppCleaner(
config=self.config, handlers=self.handlers, **self.app_values
config=self.config, handlers=self.handlers, **self.cleaner_values
)

@property
Expand Down

0 comments on commit b482f7f

Please sign in to comment.