Exemplo n.º 1
0
def test_calculate_buffer_per_auto_scaling_group_with_nodes_override():
    autoscaling = MagicMock()
    autoscaling.describe_auto_scaling_groups.return_value = {
        'AutoScalingGroups': [{
            'AutoScalingGroupName': 'asg1',
            'DesiredCapacity': 1,
            'MinSize': 1,
            'MaxSize': 10,
            'Tags': [
                {
                    'Key': 'kube-aws-autoscaler:buffer-spare-nodes',
                    'Value': '3',
                },
            ]
        }]
    }

    buffer_percentage = {
        'memory': 10,
        'cpu': 10,
        'pods': 10
    }
    buffer_per_asg = calculate_buffer_per_auto_scaling_group(autoscaling,
                                                             {('asg1', 'z1'): {'cpu': 1/1000, 'memory': 52428800, 'pods': 1}},
                                                             buffer_percentage, 1)
    assert buffer_per_asg == {'asg1': {
        'cpu': 10,
        'memory': 10,
        'pods': 10,
        'nodes': 3  # expected the nodes to match the tag value
    }}
Exemplo n.º 2
0
def test_calculate_buffer_per_auto_scaling_group_with_no_asg_tag():
    autoscaling = MagicMock()
    autoscaling.describe_auto_scaling_groups.return_value = {
        'AutoScalingGroups': [{
            'AutoScalingGroupName': 'asg1',
            'DesiredCapacity': 1,
            'MinSize': 1,
            'MaxSize': 10,
            'Tags': []
        }]
    }
    buffer_per_asg = calculate_buffer_per_auto_scaling_group(autoscaling, {('asg1', 'z1'): {'cpu': 1/1000, 'memory': 52428800, 'pods': 1}}, {}, 0)
    assert buffer_per_asg == {}
Exemplo n.º 3
0
def test_calculate_buffer_per_auto_scaling_group_with_multiple_groups_and_partial_overrides():
    autoscaling = MagicMock()
    autoscaling.describe_auto_scaling_groups.return_value = {
        'AutoScalingGroups': [
            {
                'AutoScalingGroupName': 'asg1',
                'DesiredCapacity': 1,
                'MinSize': 1,
                'MaxSize': 10,
                'Tags': [
                    {
                        'Key': 'kube-aws-autoscaler:buffer-cpu-percentage',
                        'Value': '25',
                    },
                    {
                        'Key': 'kube-aws-autoscaler:buffer-memory-percentage',
                        'Value': '25',
                    },
                    {
                        'Key': 'kube-aws-autoscaler:buffer-pods-percentage',
                        'Value': '25',
                    },
                    {
                        'Key': 'kube-aws-autoscaler:buffer-spare-nodes',
                        'Value': '2',
                    },
                ]
            },
            {
                'AutoScalingGroupName': 'asg2',
                'DesiredCapacity': 1,
                'MinSize': 1,
                'MaxSize': 10,
                'Tags': [
                    {
                        'Key': 'kube-aws-autoscaler:buffer-cpu-percentage',
                        'Value': '20',
                    },
                    {
                        'Key': 'kube-aws-autoscaler:buffer-spare-nodes',
                        'Value': '5',
                    },
                ]
            },
            {
                'AutoScalingGroupName': 'asg3',
                'DesiredCapacity': 1,
                'MinSize': 1,
                'MaxSize': 10,
                'Tags': [
                ]
            }]
    }

    buffer_percentage = {
        'memory': 10,
        'cpu': 10,
        'pods': 10
    }
    buffer_per_asg = calculate_buffer_per_auto_scaling_group(autoscaling,
                                                             {('asg1', 'z1'): {'cpu': 1/1000, 'memory': 52428800, 'pods': 1}},
                                                             buffer_percentage, 1)
    assert buffer_per_asg == {
        'asg1': {'cpu': 25, 'memory': 25, 'pods': 25, 'nodes': 2},
        'asg2': {'cpu': 20, 'memory': 10, 'pods': 10, 'nodes': 5}
    }