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

Commit

Permalink
enhance: add handler to set the default cc status field on projects
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
  • Loading branch information
njhale committed Feb 7, 2024
1 parent b4b66f3 commit d8f39d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
4 changes: 3 additions & 1 deletion pkg/controller/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func routes(router *router.Router, cfg *rest.Config, registryTransport http.Roun
appRouter.HandlerFunc(appstatus.CLIStatus)

projectRouter := router.Type(&v1.ProjectInstance{})
projectRouter.HandlerFunc(project.SetProjectSupportedRegions)
projectRouter.HandlerFunc(project.SetSupportedRegions)
projectRouter.HandlerFunc(project.SetDefaultComputeClass)

// Don't delete the namespace until the project instance is deleted.
projectRouter.IncludeFinalizing().HandlerFunc(project.CreateNamespace)
projectRouter.FinalizeFunc(labels.Prefix+"project-app-delete", project.EnsureAllAppsRemoved)
Expand Down
15 changes: 14 additions & 1 deletion pkg/project/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ import (
kclient "sigs.k8s.io/controller-runtime/pkg/client"
)

func SetProjectSupportedRegions(req router.Request, resp router.Response) error {
// SetDefaultComputeClass sets the default compute class status field of a [v1.ProjectInstance] to the value of its spec
// field if set.
func SetDefaultComputeClass(req router.Request, resp router.Response) error {
project := req.Object.(*v1.ProjectInstance)
if cc := project.Spec.DefaultComputeClass; cc != "" &&
project.Status.DefaultComputeClass != cc {
project.Status.DefaultComputeClass = cc
}

resp.Objects(req.Object)
return nil
}

func SetSupportedRegions(req router.Request, resp router.Response) error {
project := req.Object.(*v1.ProjectInstance)
project.SetDefaultRegion(apiv1.LocalRegion)
if slices.Contains(project.Status.SupportedRegions, apiv1.AllRegions) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/project/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

func TestSetProjectSupportedRegions(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/setsupportedregions/no-default", SetProjectSupportedRegions)
tester.DefaultTest(t, scheme.Scheme, "testdata/setsupportedregions/with-supported-regions", SetProjectSupportedRegions)
tester.DefaultTest(t, scheme.Scheme, "testdata/setsupportedregions/with-default-and-supported", SetProjectSupportedRegions)
tester.DefaultTest(t, scheme.Scheme, "testdata/setsupportedregions/all-supported-regions-with-default", SetProjectSupportedRegions)
tester.DefaultTest(t, scheme.Scheme, "testdata/setsupportedregions/no-default", SetSupportedRegions)
tester.DefaultTest(t, scheme.Scheme, "testdata/setsupportedregions/with-supported-regions", SetSupportedRegions)
tester.DefaultTest(t, scheme.Scheme, "testdata/setsupportedregions/with-default-and-supported", SetSupportedRegions)
tester.DefaultTest(t, scheme.Scheme, "testdata/setsupportedregions/all-supported-regions-with-default", SetSupportedRegions)
}

func TestCreateNamespace(t *testing.T) {
Expand Down

0 comments on commit d8f39d1

Please sign in to comment.