mirror of https://github.com/kubernetes/kops.git
Allow cluster autoscaler to get EC2 instance types
When the cluster autoscaler builds its EC2 instance type catalog dynamically instead of using only its statically defined set, grant it the additional IAM permissions required to fetch the instance types from the AWS API.
This commit is contained in:
parent
91bce6627e
commit
de1ecd844d
|
|
@ -19,9 +19,10 @@ package clusterautoscaler
|
|||
import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/kops/pkg/model/iam"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
)
|
||||
|
||||
// ServiceAccount represents the service-account used by the dns-controller.
|
||||
// ServiceAccount represents the service account used by the cluster autoscaler.
|
||||
// It implements iam.Subject to get AWS IAM permissions.
|
||||
type ServiceAccount struct{}
|
||||
|
||||
|
|
@ -32,7 +33,11 @@ func (r *ServiceAccount) BuildAWSPolicy(b *iam.PolicyBuilder) (*iam.Policy, erro
|
|||
clusterName := b.Cluster.ObjectMeta.Name
|
||||
p := iam.NewPolicy(clusterName, b.Partition)
|
||||
|
||||
iam.AddClusterAutoscalerPermissions(p)
|
||||
var useStaticInstanceList bool
|
||||
if ca := b.Cluster.Spec.ClusterAutoscaler; ca != nil && fi.BoolValue(ca.AWSUseStaticInstanceList) {
|
||||
useStaticInstanceList = true
|
||||
}
|
||||
iam.AddClusterAutoscalerPermissions(p, useStaticInstanceList)
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -427,7 +427,12 @@ func (r *NodeRoleMaster) BuildAWSPolicy(b *PolicyBuilder) (*Policy, error) {
|
|||
if b.Cluster.Spec.AWSLoadBalancerController != nil && fi.BoolValue(b.Cluster.Spec.AWSLoadBalancerController.Enabled) {
|
||||
AddAWSLoadbalancerControllerPermissions(p)
|
||||
}
|
||||
AddClusterAutoscalerPermissions(p)
|
||||
|
||||
var useStaticInstanceList bool
|
||||
if ca := b.Cluster.Spec.ClusterAutoscaler; ca != nil && fi.BoolValue(ca.AWSUseStaticInstanceList) {
|
||||
useStaticInstanceList = true
|
||||
}
|
||||
AddClusterAutoscalerPermissions(p, useStaticInstanceList)
|
||||
|
||||
nth := b.Cluster.Spec.NodeTerminationHandler
|
||||
if nth != nil && fi.BoolValue(nth.Enabled) && fi.BoolValue(nth.EnableSQSTerminationDraining) {
|
||||
|
|
@ -1013,7 +1018,7 @@ func AddAWSLoadbalancerControllerPermissions(p *Policy) {
|
|||
)
|
||||
}
|
||||
|
||||
func AddClusterAutoscalerPermissions(p *Policy) {
|
||||
func AddClusterAutoscalerPermissions(p *Policy, useStaticInstanceList bool) {
|
||||
p.clusterTaggedAction.Insert(
|
||||
"autoscaling:SetDesiredCapacity",
|
||||
"autoscaling:TerminateInstanceInAutoScalingGroup",
|
||||
|
|
@ -1024,6 +1029,11 @@ func AddClusterAutoscalerPermissions(p *Policy) {
|
|||
"autoscaling:DescribeLaunchConfigurations",
|
||||
"ec2:DescribeLaunchTemplateVersions",
|
||||
)
|
||||
if !useStaticInstanceList {
|
||||
p.unconditionalAction.Insert(
|
||||
"ec2:DescribeInstanceTypes",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// AddAWSEBSCSIDriverPermissions appens policy statements that the AWS EBS CSI Driver needs to operate.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
"autoscaling:DescribeAutoScalingGroups",
|
||||
"autoscaling:DescribeAutoScalingInstances",
|
||||
"autoscaling:DescribeLaunchConfigurations",
|
||||
"ec2:DescribeInstanceTypes",
|
||||
"ec2:DescribeLaunchTemplateVersions"
|
||||
],
|
||||
"Effect": "Allow",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
"autoscaling:DescribeAutoScalingGroups",
|
||||
"autoscaling:DescribeAutoScalingInstances",
|
||||
"autoscaling:DescribeLaunchConfigurations",
|
||||
"ec2:DescribeInstanceTypes",
|
||||
"ec2:DescribeLaunchTemplateVersions"
|
||||
],
|
||||
"Effect": "Allow",
|
||||
|
|
|
|||
Loading…
Reference in New Issue