Skip to content

Commit

Permalink
print exception in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dignajar committed Oct 5, 2021
1 parent 8cf1011 commit 273e61f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions files/aautoscaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __start__(self, namespace:str, deploy:dict, currentTime:datetime):
startReplicas = 1
startReplicasAnnotation = 'another-autoscaler/start-replicas'
if startReplicasAnnotation in deployAnnotations:
self.logs.debug({'message': 'Replicas defined by the user for start.', 'namespace': namespace, 'deployment': deployName, 'startReplicas': deployAnnotations[startReplicasAnnotation]})
self.logs.debug({'message': 'Number of replicas.', 'namespace': namespace, 'deployment': deployName, 'startReplicas': deployAnnotations[startReplicasAnnotation]})
startReplicas = int(deployAnnotations[startReplicasAnnotation])

if deployReplicas != startReplicas:
Expand All @@ -72,7 +72,7 @@ def __stop__(self, namespace:str, deploy:dict, currentTime:datetime):
stopReplicas = 0
stopReplicasAnnotation = 'another-autoscaler/stop-replicas'
if stopReplicasAnnotation in deployAnnotations:
self.logs.debug({'message': 'Replicas defined by the user for stop.', 'namespace': namespace, 'deployment': deployName, 'stopReplicas': deployAnnotations[stopReplicasAnnotation]})
self.logs.debug({'message': 'Number of replicas.', 'namespace': namespace, 'deployment': deployName, 'stopReplicas': deployAnnotations[stopReplicasAnnotation]})
stopReplicas = int(deployAnnotations[stopReplicasAnnotation])

if deployReplicas != stopReplicas:
Expand Down
7 changes: 7 additions & 0 deletions files/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def getNamespaces(self) -> list:
response = self.CoreV1Api.list_namespace()
return response.items
except ApiException as e:
print(e)
self.logs.error({'message': 'Exception when calling CoreV1Api.list_namespace'})
return []

Expand All @@ -51,6 +52,7 @@ def getDeployments(self, namespace:str, labelSelector:str=False) -> list:
response = self.AppsV1Api.list_namespaced_deployment(namespace=namespace)
return response.items
except ApiException as e:
print(e)
self.logs.error({'message': 'Exception when calling AppsV1Api.list_namespaced_deployment'})
return []

Expand All @@ -61,6 +63,7 @@ def getDeployment(self, namespace:str, deploymentName:str):
try:
return self.AppsV1Api.read_namespaced_deployment(namespace=namespace, name=deploymentName)
except ApiException as e:
print(e)
self.logs.error({'message': 'Exception when calling AppsV1Api.read_namespaced_deployment'})
return []

Expand All @@ -73,6 +76,7 @@ def getPods(self, namespace:str, labelSelector:str, limit:int=1) -> list:
response = self.CoreV1Api.list_namespaced_pod(namespace=namespace, label_selector=labelSelector, limit=limit)
return response.items
except ApiException as e:
print(e)
self.logs.error({'message': 'Exception when calling CoreV1Api.list_namespaced_pod'})
return []

Expand Down Expand Up @@ -116,6 +120,7 @@ def setReplicas(self, namespace:str, deploymentName:str, replicas:int) -> bool:
self.AppsV1Api.replace_namespaced_deployment_scale(namespace=namespace, name=deploymentName, body=currentScale)
return True
except ApiException as e:
print(e)
self.logs.error({'message': 'Exception when calling AppsV1Api.read_namespaced_deployment_scale'})
return False

Expand All @@ -126,6 +131,7 @@ def getReplicas(self, namespace:str, deploymentName:str):
try:
return self.AppsV1Api.read_namespaced_deployment_scale(namespace=namespace, name=deploymentName)
except ApiException as e:
print(e)
self.logs.error({'message': 'Exception when calling AppsV1Api.read_namespaced_deployment_scale'})
return False

Expand All @@ -142,6 +148,7 @@ def rolloutDeployment(self, namespace:str, deploymentName:str) -> bool:
self.AppsV1Api.replace_namespaced_deployment(namespace=namespace, name=deploymentName, body=deploymentManifest)
return True
except ApiException as e:
print(e)
self.logs.error({'message': 'Exception when calling AppsV1Api.replace_namespaced_deployment'})
return False

Expand Down

0 comments on commit 273e61f

Please sign in to comment.