Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Ellis Tarn <[email protected]>
  • Loading branch information
suket22 and ellistarn authored Nov 24, 2021
1 parent 26c1831 commit 2591f0a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/controllers/provisioning/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (c *Controller) Apply(ctx context.Context, provisioner *v1alpha5.Provisione

// Returns true if the new candidate provisioner is different than the provisioner in memory.
func (c *Controller) hasChanged(ctx context.Context, provisionerNew *v1alpha5.Provisioner) bool {
oldProvisioner, _ := c.provisioners.Load(provisionerNew.Name)
if oldProvisioner == nil {
oldProvisioner, ok := c.provisioners.Load(provisionerNew.Name)
if !ok {
return true
}
hashKeyOld, err := hashstructure.Hash(oldProvisioner.(*Provisioner).Spec, hashstructure.FormatV2, &hashstructure.HashOptions{SlicesAsSets: true})
Expand Down
5 changes: 2 additions & 3 deletions pkg/controllers/provisioning/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ type Launcher struct {

func (l *Launcher) Launch(ctx context.Context, provisioner *v1alpha5.Provisioner, schedules []*scheduling.Schedule,
instanceTypes []cloudprovider.InstanceType) error {

// Pack and bind pods
errs := make([]error, len(schedules))
workqueue.ParallelizeUntil(ctx, len(schedules), len(schedules), func(index int) {
for _, packing := range l.Packer.Pack(ctx, schedules[index], instanceTypes) {
if err := l.verifyResourceLimits(ctx, provisioner); err != nil {
errs[index] = multierr.Append(errs[index], err)
errs[index] = multierr.Append(errs[index], fmt.Errorf("verifying limits, %w", err))
continue
}
// Create thread safe channel to pop off packed pod slices
Expand Down Expand Up @@ -120,7 +119,7 @@ func (l *Launcher) bind(ctx context.Context, node *v1.Node, pods []*v1.Pod) (err
func (l *Launcher) verifyResourceLimits(ctx context.Context, provisioner *v1alpha5.Provisioner) error {
latest := &v1alpha5.Provisioner{}
if err := l.KubeClient.Get(ctx, client.ObjectKeyFromObject(provisioner), latest); err != nil {
return err
return fmt.Errorf("getting current resource usage, %w", err)
}
return provisioner.Spec.Limits.ExceededBy(latest.Status.Resources)
}
Expand Down

0 comments on commit 2591f0a

Please sign in to comment.