Skip to content

Comments

feat: add python script to translate pod health summary#503

Draft
Elsie4ever wants to merge 4 commits intoAzure:devfrom
Elsie4ever:user/jiacju/pod_status_investigate
Draft

feat: add python script to translate pod health summary#503
Elsie4ever wants to merge 4 commits intoAzure:devfrom
Elsie4ever:user/jiacju/pod_status_investigate

Conversation

@Elsie4ever
Copy link
Contributor

@Elsie4ever Elsie4ever commented Mar 5, 2025

As discussed, creating a python script to translate pod health summary from all the pod .yaml files
the input will be:

  1. support bundle zip file path
  2. output format: json or txt

json format
image

txt format
image

Has validated the output with multiple support bundle instances by comparing output with kubectl get pods
the logic of this translation are from Kubernetes git hub repos and official documentations


This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Thank you for contributing to Azure IoT Operations tooling!

This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

Intent for Production

  • It is expected that pull requests made to default or core branches such as dev or main are of production grade. Corollary to this, any merged contributions to these branches may be deployed in a public release at any given time. By checking this box, you agree and commit to the expected production quality of code.

Basic expectations

  • If introducing new functionality or modified behavior, are they backed by unit and/or integration tests?
  • In the same context as above are command names and their parameter definitions accurate? Do help docs have sufficient content?
  • Have all the relevant unit and integration tests pass? i.e. pytest <project root> -vv. Please provide evidence in the form of a screenshot showing a succesful run of tests locally OR a link to a test pipeline that has been run against the change-set.
  • Have linter checks passed using the .pylintrc and .flake8 rules? Look at the CI scripts for example usage.
  • Have extraneous print or debug statements, commented out code-blocks or code-statements (if any) been removed from the surface area of changes?
  • Have you made an entry in HISTORY.rst which concisely explains your user-facing feature or change?

Azure IoT Operations CLI maintainers reserve the right to enforce any of the outlined expectations.

A PR is considered ready for review when all basic expectations have been met (or do not apply).


# get current time
current_time = datetime.fromisoformat(get_timestamp_now_utc()).replace(tzinfo=timezone.utc)
translated["age"] = str(current_time - created_at)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not do this - it will provide invalid data based on how old the support bundle is.

Is there a way to get the time the support bundle is created (ex: the support bundle name, assuming it is not changed - you can prob throw an error if the name has changed)


if is_pod_terminated:
# status is the reason for termination
translated["status"] = [
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can use next here and in the next if branch

console = Console(file=write_file)
console.print(table)

# Test serialized content
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe have a flag to do test the script?

TestCase().assertEqual(data, payload_to_integrate)
elif output_format == "txt":
payload_to_integrate = content
test_file_path = "./test_file.txt"
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be an issue if the test_file.txt is already there (and has data)

import sys
from unittest import TestCase
from zipfile import ZipFile
from rich.console import Console
Copy link
Contributor

Choose a reason for hiding this comment

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

see if you can avoid using rich (to avoid having dependencies). If needed, make sure you note that this is a dependency (you can make a long comment at the top after the header)


import yaml

from azext_edge.edge.util.common import get_timestamp_now_utc
Copy link
Contributor

@vilit1 vilit1 Mar 5, 2025

Choose a reason for hiding this comment

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

same thing here as for rich - see if you can still use the script if you install the whl

(basically try to see if you can make this a script others can run without setting up the azure-iot-ops extension for development)

from azext_edge.edge.util.common import get_timestamp_now_utc


def process_supportbundle(bundle_path: str, output_format: str = "json"):
Copy link
Contributor

Choose a reason for hiding this comment

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

add docstrings (it is obvious for us but would be useful for others)

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