Skip to content

Conversation

@anson627
Copy link
Collaborator

This pull request improves the robustness and correctness of Kubernetes manifest handling by introducing a new method to validate and expand manifest documents, especially those using kind: List or containing non-dictionary YAML documents. The update ensures only valid manifest dictionaries are processed, and includes comprehensive tests for these scenarios.

Manifest validation and expansion improvements:

  • Added a new _expand_and_validate_manifests method to kubernetes_client.py to recursively expand kind: List manifests and skip invalid or non-dictionary documents, logging appropriate warnings.
  • Updated apply_manifest_from_url, delete_manifest_from_url, apply_manifest_from_file, and delete_manifest_from_file to use _expand_and_validate_manifests before applying or deleting manifests, ensuring only valid manifests are processed and all kind: List items are handled correctly. [1] [2] [3] [4]

Testing enhancements:

  • Added extensive tests in test_kubernetes_client.py to cover various scenarios for _expand_and_validate_manifests, including valid manifests, kind: List (including nested lists), non-dict/scalar/empty/None manifests, and invalid or missing items fields. Also added integration tests for manifest application from URLs with these edge cases.…ents

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enhances Kubernetes manifest handling by adding validation and expansion capabilities for kind: List manifests and non-dictionary YAML documents. The changes ensure that only valid manifest dictionaries are processed while expanding nested list structures.

Changes:

  • Added a new _expand_and_validate_manifests method that recursively expands kind: List manifests, validates manifest types, and logs warnings for invalid documents
  • Updated four manifest processing methods (apply_manifest_from_url, delete_manifest_from_url, apply_manifest_from_file, delete_manifest_from_file) to use the new validation and expansion logic
  • Added comprehensive unit tests covering valid manifests, kind: List (including nested lists), non-dict/scalar/empty/None manifests, and invalid items fields

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
modules/python/clients/kubernetes_client.py Added _expand_and_validate_manifests method and integrated it into manifest processing methods to ensure only valid dictionaries are processed and kind: List manifests are properly expanded
modules/python/tests/clients/test_kubernetes_client.py Added 9 comprehensive test cases covering various scenarios for the new manifest validation and expansion functionality

type(items).__name__
)
continue
logger.info("Expanding List manifest containing %d items", len(items))
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

This info-level log message for expanding List manifests may create excessive noise in logs, especially for large deployments or frequent manifest operations. Consider using debug level instead: logger.debug(...) to keep info logs focused on significant operations.

Suggested change
logger.info("Expanding List manifest containing %d items", len(items))
logger.debug("Expanding List manifest containing %d items", len(items))

Copilot uses AI. Check for mistakes.
}
]

result = self.client._expand_and_validate_manifests(manifests)
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

Testing private methods (prefixed with _) directly is generally discouraged as it couples tests to implementation details. While the extensive testing here is valuable, consider also adding tests that exercise this functionality through the public API methods (apply_manifest_from_url, etc.) to ensure the integration works correctly end-to-end.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants