sideshowbandana / k8s-sqs-autoscaler

Kubernetes pod autoscaler based on queue size in AWS SQS
71 stars 26 forks source link

deployments.items[0] -> IndexError: list index out of range #9

Open lhriley opened 5 years ago

lhriley commented 5 years ago

I found your SQS autoscaler from the Wattpad issues discussion (https://github.com/Wattpad/kube-sqs-autoscaler/issues/7). Unfortunately, your tool is apparently suffering from it's own issues.

I ran into the region problem (https://github.com/sideshowbandana/k8s-sqs-autoscaler/issues/1), and was able to fix it with the suggested env var. However, I'm not faced with the following:

{'sqs_queue_url': '<sqs url>', 'kubernetes_deployment': '<deployment>', 'kubernetes_namespace': <namespace>', 'aws_region': '<region>', 'poll_period': 5, 'scale_down_cool_down': 300, 'scale_up_cool_down': 30, 'scale_up_messages': 2, 'scale_down_messages': 0, 'max_pods': 5, 'min_pods': 1}
Starting poll for <sqs url> every 5s
Waiting for scale up cooldown
Waiting for scale up cooldown
Waiting for scale up cooldown
Waiting for scale up cooldown
Waiting for scale up cooldown
Waiting for scale up cooldown
loading deployment: <deployment> from namespace: <namepsace>
Traceback (most recent call last):
  File "./k8s-sqs-autoscaler", line 71, in <module>
    sqs.run(options)
  File "/usr/src/app/sqs/sqs.py", line 95, in run
    SQSPoller(options).run()
  File "/usr/src/app/sqs/sqs.py", line 88, in run
    self.poll()
  File "/usr/src/app/sqs/sqs.py", line 35, in poll
    self.scale_up()
  File "/usr/src/app/sqs/sqs.py", line 50, in scale_up
    deployment = self.deployment()
  File "/usr/src/app/sqs/sqs.py", line 74, in deployment
    return deployments.items[0]
IndexError: list index out of range

The error isn't really all that clear. Is this due to a lack of RBAC permissions? Or just some bad logic in your code? I can't really tell, unfortunately.

amitnanaware commented 5 years ago

@lhriley The error says that the api is not getting any response for deployments. the code is as below:

deployments = self.extensions_v1_beta1.list_namespaced_deployment(self.options.kubernetes_namespace, label_selector="app={}".format(self.options.kubernetes_deployment))
return deployments.items[0]

Make sure the namespace and deployment which you are passing is correct. The deployment here is the label which you defile in deployment section of your yaml file e.g.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend
spec:
  template:
    metadata:
      labels:
        app: frontend

In this case value of deployment is frontend.