in eksupdate/src/preflight_module.py [0:0]
def pod_disruption_budget(log_details,errors,cluster_name,region,report,customer_report,force_upgrade):
loading_config(cluster_name,region)
print('\n')
log_pusher(log_details,cluster_name,region,"Fetching Pod Disruption Budget Details....")
print("Fetching Pod Disruption Budget Details....")
try :
v1 = client.PolicyV1beta1Api()
ret = v1.list_pod_disruption_budget_for_all_namespaces()
if len(ret.items) == 0 :
customer_report['pod disruption budget'] = 'No Pod Disruption Budget exists in cluster'
log_pusher(log_details,cluster_name,region,'No Pod Disruption Budget exists in cluster')
print('No Pod Disruption Budget exists in cluster')
else:
print("Pod Disruption Budget exists in cluster therefore force upgrade is required to upgrade the cluster")
if not force_upgrade :
print("Pod Disruption Budget exists in cluster therefore force upgrade is required to upgrade the cluster, To upgrade please run the code with --force flag ")
errors.append("To upgrade please run the code with --force flag ")
report["preflight_status"] = False
for pdb in ret.items :
max_available = pdb.spec.max_unavailable
min_available = pdb.spec.min_available
#print(max_available,min_available)
report['pdb'] = {'max_unavailable':max_available,'min_available':min_available}
customer_report['pod disruption budget'] = 'Pod disruption budget exists in the cluster'
log_pusher(log_details,cluster_name,region,"Pod disruption budget exists with max unavailable as " + str(max_available) + " and min available as " + str(min_available))
print("Pod disruption budget exists with max unavailable as " + str(max_available) + " and min available as " + str(min_available))
v1 = client.CoreV1Api()
pods_and_nodes = []
ret = v1.list_pod_for_all_namespaces(watch=False)
#pprint(ret.items[0].spec.node_name)
for i in ret.items:
pods_and_nodes.append({'name':i.metadata.name,'namespace':i.metadata.namespace,'nodename':i.spec.node_name})
report['pdb']['pods'] = pods_and_nodes
pprint(pods_and_nodes)
#pprint(pods_and_nodes)
except Exception as e :
errors.append("Error ocurred while checking for pod disruption budget {err}".format(err=e))
customer_report['pod disruption budget'] = "Error ocurred while checking for pod disruption budget"
log_pusher(log_details,cluster_name,region,"Error ocurred while checking for pod disruption budget {err}".format(err=e))
print("Error ocurred while checking for pod disruption budget {err}".format(err=e))
report['preflight_status'] = False