Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
enhance: set project default cc status field
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Hale <[email protected]>
  • Loading branch information
njhale committed Feb 19, 2024
1 parent 48a4fe9 commit b4b7f4e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/project/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/acorn-io/baaah/pkg/router"
apiv1 "github.com/acorn-io/runtime/pkg/apis/api.acorn.io/v1"
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
internaladminv1 "github.com/acorn-io/runtime/pkg/apis/internal.admin.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/computeclasses"
"github.com/acorn-io/runtime/pkg/labels"
corev1 "k8s.io/api/core/v1"
Expand All @@ -26,18 +27,27 @@ func SetDefaultComputeClass(req router.Request, resp router.Response) error {
}

// Check if the given compute class exists
if project.Status.DefaultComputeClass != "" {
if _, err := computeclasses.GetAsProjectComputeClassInstance(req.Ctx, req.Client, project.Name, project.Status.DefaultComputeClass); err != nil {
if computeClassName := project.Status.DefaultComputeClass; computeClassName != "" {
if _, err := computeclasses.GetAsProjectComputeClassInstance(req.Ctx, req.Client, project.Name, computeClassName); err != nil {
if !apierrors.IsNotFound(err) {
return fmt.Errorf("failed to check existence of default compute class on project [%s] status: %w", project.Name, err)
return fmt.Errorf("failed to check existence of default compute class [%s] specified by project [%s] status: %w", computeClassName, project.Name, err)
}

// The compute class does not exist, clear the status field.
project.Status.DefaultComputeClass = ""
}
}

resp.Objects(req.Object)
// Pick a default from the available compute classes
if project.Status.DefaultComputeClass == "" {
computeClassName, err := internaladminv1.GetDefaultComputeClassName(req.Ctx, req.Client, project.Name)
if err != nil {
return fmt.Errorf("failed to get default compute class for project [%s]: %w", project.Name, err)
}

project.Status.DefaultComputeClass = computeClassName
}

return nil
}

Expand Down

0 comments on commit b4b7f4e

Please sign in to comment.