Commit 6b7db270 authored by Santhosh Kumar's avatar Santhosh Kumar

cleanup code

parent 58116833
......@@ -175,6 +175,17 @@ def scale_deployment():
except ApiException as e:
print(f"Error occurred while creating/updating HorizontalPodAutoscaler: {e}")
def get_cluster_ip(function_name, namespace):
try:
# Get cluster IP
service = core_api.read_namespaced_service(name=function_name, namespace=namespace)
destination_ports = [port.target_port for port in service.spec.ports]
cluster_ip = f"{service.spec.cluster_ip}:{destination_ports}"
return cluster_ip
except Exception as e:
print("Error retrieving cluster IP:", e)
return None
def expose_service():
function_name = input("Enter the function name: ")
......@@ -225,6 +236,8 @@ def expose_service():
print("Creating service...")
core_api.create_namespaced_service(namespace=namespace, body=service)
print("Cluster IP address = %s\n" % get_cluster_ip())
except ApiException as e:
print("Exception when updating deployment: %s\n" % e)
......@@ -286,8 +299,8 @@ def get_deployment_info():
# Get resource usage
usage = {
"num_pods": num_pods,
"avg_cpu_usage": avg_cpu_usage,
"avg_memory_usage": avg_memory_usage
"avg_cpu_usage (m)": avg_cpu_usage/1e6,
"avg_memory_usage (Mi)": avg_memory_usage/(1024*1024)
}
# Get exposed URL (if service is exposed)
......@@ -417,6 +430,78 @@ def delete_resources_by_label():
except Exception as e:
print(f"Error occurred while deleting resources: {e}")
def describe_pods_events(deployment_name, namespace="default"):
try:
# Get pods associated with the deployment
pods = core_api.list_namespaced_pod(namespace=namespace, label_selector=f"function={deployment_name}").items
# Describe events for each pod
for pod in pods:
print(f"Name: {pod.metadata.name}")
print(f"Namespace: {pod.metadata.namespace}")
print(f"Status: {pod.status.phase}")
print("Pod IP:", pod.status.pod_ip)
print("Node Name:", pod.spec.node_name)
print("Containers:")
for container in pod.spec.containers:
print(f" - Name: {container.name}")
print(f" Image: {container.image}")
print(f" Image Pull Policy: {container.image_pull_policy}")
print(" Resources:")
if container.resources:
print(f" Requests: {container.resources.requests}")
print(f" Limits: {container.resources.limits}")
else:
print(" Not specified")
print("-----container----")
print("Events:")
events = core_api.list_namespaced_event(namespace=pod.metadata.namespace, field_selector=f"involvedObject.name={pod.metadata.name}").items
if events:
for event in events:
print(f" - {event.metadata.creation_timestamp}: {event.message}")
else:
print(" No events found")
print("------------------")
except Exception as e:
print("Error describing pods and events:", e)
def select_misc_operation():
print("Select the miscellaneous operation:")
print("1. Get Cluster IP")
print("2. Show Additional Pods Information")
print("3. Exit")
while True:
try:
choice = int(input("Enter your choice (1-3): "))
if 1 <= choice <= 3:
return choice
else:
print(choice)
print("Invalid choice. Please enter a number between 1 and 3.")
except ValueError:
print("Invalid input. Please enter a number.")
def misc_info():
while True:
choice = select_misc_operation()
if choice == 1:
print("Get Cluster IP...")
function_name = input("Enter the function name: ")
namespace="default"
# Call function to build Docker
print("Cluster IP address for use : %s\n" % get_cluster_ip(function_name, namespace))
elif choice == 2:
print("Additional Information of Pods ...")
function_name = input("Enter the function name: ")
namespace="default"
# Call function to deploy function
describe_pods_events(function_name, namespace)
elif choice == 3:
print("Exiting...")
break
def select_operation():
print("Select an operation:")
print("1. Build Docker")
......@@ -427,16 +512,17 @@ def select_operation():
print("6. Expose Service")
print("7. Get Function Logs")
print("8. Get resource usage")
print("9. Exit")
print("9. Misc functions")
print("10. Exit")
while True:
try:
choice = int(input("Enter your choice (1-9): "))
if 1 <= choice <= 9:
choice = int(input("Enter your choice (1-10): "))
if 1 <= choice <= 10:
return choice
else:
print(choice)
print("Invalid choice. Please enter a number between 1 and 9.")
print("Invalid choice. Please enter a number between 1 and 10.")
except ValueError:
print("Invalid input. Please enter a number.")
......@@ -477,5 +563,9 @@ if __name__ == "__main__":
# Call function to expose service
get_deployment_info()
elif choice == 9:
print("Resource Information ...")
# Call function to expose service
misc_info()
elif choice == 10:
print("Exiting...")
break
This command prints configurations for subcommands provided.
For details, see: https://pkg.go.dev/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm#section-directories
Usage:
kubeadm config print [flags]
kubeadm config print [command]
Available Commands:
init-defaults Print default init configuration, that can be used for 'kubeadm init'
join-defaults Print default join configuration, that can be used for 'kubeadm join'
reset-defaults Print default reset configuration, that can be used for 'kubeadm reset'
Flags:
-h, --help help for print
Global Flags:
--add-dir-header If true, adds the file directory to the header of the log messages
--kubeconfig string The kubeconfig file to use when talking to the cluster. If the flag is not set, a set of standard locations can be searched for an existing kubeconfig file. (default "/etc/kubernetes/admin.conf")
--log-file string If non-empty, use this log file (no effect when -logtostderr=true)
--log-file-max-size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
--one-output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
--rootfs string [EXPERIMENTAL] The path to the 'real' host root filesystem.
--skip-headers If true, avoid header prefixes in the log messages
--skip-log-headers If true, avoid headers when opening log files (no effect when -logtostderr=true)
-v, --v Level number for the log level verbosity
Use "kubeadm config print [command] --help" for more information about a command.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment