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

Define Pydantic model to representing Kubernetes manifest #546

Merged
merged 42 commits into from
Dec 5, 2024

Conversation

raminqaf
Copy link
Contributor

@raminqaf raminqaf commented Dec 4, 2024

Closes #548

@raminqaf raminqaf self-assigned this Dec 4, 2024
@raminqaf raminqaf marked this pull request as ready for review December 4, 2024 16:00
@raminqaf raminqaf requested a review from disrupted as a code owner December 4, 2024 16:00
kpops/components/common/kubernetes_model.py Outdated Show resolved Hide resolved
kpops/components/common/kubernetes_model.py Outdated Show resolved Hide resolved
kpops/component_handlers/helm_wrapper/helm.py Outdated Show resolved Hide resolved
kpops/component_handlers/helm_wrapper/helm_diff.py Outdated Show resolved Hide resolved
kpops/component_handlers/helm_wrapper/helm.py Outdated Show resolved Hide resolved
kpops/components/common/kubernetes_model.py Outdated Show resolved Hide resolved
Comment on lines 35 to 56
annotations: dict[str, str] | None = None
creation_timestamp: str | None = Field(
default=None, description="Timestamp in RFC3339 format"
)
deletion_grace_period_seconds: int | None = None
deletion_timestamp: str | None = Field(
default=None, description="Timestamp in RFC3339 format"
)
finalizers: list[str] | None = None
generate_name: str | None = None
generation: int | None = None
labels: dict[str, str] | None = None
managed_fields: list[ManagedFieldsEntry] | None = None
name: str | None = None
namespace: str | None = None
owner_references: list[OwnerReference] | None = None
resource_version: str | None = None
self_link: str | None = Field(
default=None,
description="Deprecated field, not populated by Kubernetes in modern versions",
)
uid: str | None = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need all of those? I feel like many have no meaning to KPOps

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are a representation of the lightkube ObjectMeta. They are documented here:

https://gtsystem.github.io/lightkube-models/1.19/models/meta_v1/#objectmeta

We can have them removed and allow extra fields.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think I would prefer a reduction to those fields that are most likely to be needed in KPOps

@raminqaf raminqaf added the type/enhancement New feature or request label Dec 5, 2024
@raminqaf raminqaf requested a review from disrupted December 5, 2024 14:21
generator = kpops.manifest_deploy(
RESOURCE_PATH / "manifest-pipeline" / PIPELINE_YAML,
environment="development",
)
assert isinstance(generator, Iterator)
resources = list(generator)
assert len(resources) == 2
snapshot.assert_match(yaml.dump_all(resources), "resources")
Copy link
Member

@disrupted disrupted Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new isinstance check is great, but I think we would still need some sort of snapshot testing as well. how about we just save the output of print_yaml(manifest.model_dump())?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that a bit overkill for this test. The test should check if the KPOps manifest api works as expected or not. Printing the YAML would be done by the CLI, and that is tested in the other test cases. But if you think it make sense I would capture the stdout and add a snapshot :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you. we should probably split that up into two separate tests. In the API test we run assertions on the returned KubernetesManifest models and in the CLI test we do the snapshot test of the output. Let's do it in a followup then

@raminqaf raminqaf merged commit ec6858a into v9 Dec 5, 2024
9 checks passed
@raminqaf raminqaf deleted the feat/add-kubernetes-manifest branch December 5, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants