Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tzneal committed Jun 14, 2022
1 parent c2388d4 commit 34cdf72
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
5 changes: 1 addition & 4 deletions pkg/controllers/provisioning/scheduling/inflightnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ func (n *InFlightNode) Add(pod *v1.Pod) error {
}

// determine the number of volumes that will be mounted if the pod schedules
mountedVolumeCount, err := n.volumeUsage.Validate(pod)
if err != nil {
return err
}
mountedVolumeCount := n.volumeUsage.Validate(pod)
if mountedVolumeCount > n.maxVolumes {
return fmt.Errorf("%d would exceed max volume count of %d", mountedVolumeCount, n.maxVolumes)
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/controllers/provisioning/scheduling/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ func (n *Node) Add(pod *v1.Pod) error {
// Check instance type combinations
requests := resources.Merge(n.requests, resources.RequestsForPods(pod))
// determine the number of volumes that will be mounted if the pod schedules
mountedVolumeCount, err := n.volumeUsage.Validate(pod)
if err != nil {
return err
}
mountedVolumeCount := n.volumeUsage.Validate(pod)
instanceTypes := filterInstanceTypes(n.InstanceTypeOptions, nodeRequirements, requests, mountedVolumeCount)
if len(instanceTypes) == 0 {
return fmt.Errorf("no instance type satisfied resources %s and requirements %s", resources.String(resources.RequestsForPods(pod)), nodeRequirements)
Expand Down
19 changes: 7 additions & 12 deletions pkg/scheduling/volumelimits.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"knative.dev/pkg/logging"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -43,33 +42,29 @@ func NewVolumeLimits(ctx context.Context) *VolumeLimits {
}

func (v *VolumeLimits) Add(pod *v1.Pod) {
podVolumes, err := v.validate(pod)
if err != nil {
logging.FromContext(v.ctx).Errorf("inconsistent state registering volume li mit, %s", err)
}
podVolumes := v.validate(pod)
v.podVolumes[client.ObjectKeyFromObject(pod)] = podVolumes
v.volumes = v.volumes.Union(podVolumes)
}

func (v *VolumeLimits) Validate(pod *v1.Pod) (int, error) {
podVolumes, err := v.validate(pod)
func (v *VolumeLimits) Validate(pod *v1.Pod) int {
podVolumes := v.validate(pod)
result := v.volumes.Union(podVolumes)
return len(result), err
return len(result)
}

func (v *VolumeLimits) validate(pod *v1.Pod) (sets.String, error) {
func (v *VolumeLimits) validate(pod *v1.Pod) sets.String {
podPVCs := sets.String{}
for _, volume := range pod.Spec.Volumes {
if volume.PersistentVolumeClaim != nil {
podPVCs.Insert(fmt.Sprintf("%s/%s", pod.Namespace, volume.PersistentVolumeClaim.ClaimName))
} else if volume.Ephemeral != nil {
// generated name per https://kubernetes.io/docs/concepts/storage/ephemeral-volumes/#persistentvolumeclaim-naming
pvcName := fmt.Sprintf("%s-%s", pod.Name, volume.Name)
podPVCs.Insert(fmt.Sprintf("%s/%s", pod.Namespace, pvcName))
podPVCs.Insert(fmt.Sprintf("%s/%s-%s", pod.Namespace, pod.Name, volume.Name))
}
}

return podPVCs, nil
return podPVCs
}

func (v *VolumeLimits) DeletePod(key types.NamespacedName) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func MustParse() Options {
flag.BoolVar(&opts.AWSENILimitedPodDensity, "aws-eni-limited-pod-density", env.WithDefaultBool("AWS_ENI_LIMITED_POD_DENSITY", true), "Indicates whether new nodes should use ENI-based pod density")
flag.StringVar(&opts.AWSDefaultInstanceProfile, "aws-default-instance-profile", env.WithDefaultString("AWS_DEFAULT_INSTANCE_PROFILE", ""), "The default instance profile to use when provisioning nodes in AWS")
flag.BoolVar(&opts.AWSEnablePodENI, "aws-enable-pod-eni", env.WithDefaultBool("AWS_ENABLE_POD_ENI", false), "If true then instances that support pod ENI will report a vpc.amazonaws.com/pod-eni resource")
// See https://github.com/kubernetes-sigs/aws-ebs-csi-driver/blob/master/docs/options.md for the EBS CSI volume-attach-limit docs
flag.IntVar(&opts.AWSVolumeAttachLimit, "aws-volume-attach-limit", env.WithDefaultInt("AWS_VOLUME_ATTACH_LIMIT", -1), "If set to a value >=0, this is the maximum number of volumes attachable per node and should match the value passed to the EBS CSI driver.")
flag.Parse()
if err := opts.Validate(); err != nil {
Expand All @@ -67,8 +68,7 @@ type Options struct {
AWSENILimitedPodDensity bool
AWSDefaultInstanceProfile string
AWSEnablePodENI bool
// AWSVolumeAttachLimit is the setting of the volume-attach-limit from the ebs CSI driver
AWSVolumeAttachLimit int
AWSVolumeAttachLimit int
}

func (o Options) Validate() (err error) {
Expand Down

0 comments on commit 34cdf72

Please sign in to comment.