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

Commit

Permalink
fix: use aggregate compute class api for project validation
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Hale <[email protected]>
  • Loading branch information
njhale committed Feb 16, 2024
1 parent d3feb24 commit 122cbf8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 62 deletions.
5 changes: 3 additions & 2 deletions pkg/server/registry/apigroups/acorn/projects/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

apiv1 "github.com/acorn-io/runtime/pkg/apis/api.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/computeclasses"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -35,7 +34,9 @@ func (v *Validator) Validate(ctx context.Context, obj runtime.Object) field.Erro
}

if defaultComputeClass := project.Spec.DefaultComputeClass; defaultComputeClass != "" {
if _, err := computeclasses.GetAsProjectComputeClassInstance(ctx, v.Client, project.Name, defaultComputeClass); apierrors.IsNotFound(err) {
// Check if the default project compute class exists
var cc apiv1.ComputeClass
if err := v.Client.Get(ctx, kclient.ObjectKey{Namespace: project.Name, Name: defaultComputeClass}, &cc); !apierrors.IsNotFound(err) {
// The compute class does not exist, return an invalid error
result = append(result, field.Invalid(field.NewPath("spec", "defaultComputeClass"), defaultComputeClass, "default compute class does not exist"))
} else if err != nil {
Expand Down
60 changes: 0 additions & 60 deletions pkg/server/registry/apigroups/acorn/projects/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

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/scheme"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -102,65 +101,6 @@ func TestProjectCreateValidation(t *testing.T) {
},
wantError: true,
},
{
name: "Create project with default computeclass that points to a specific clustercomputeclass",
project: apiv1.Project{
Spec: v1.ProjectInstanceSpec{
DefaultComputeClass: "cluster-compute-class",
},
},
client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(
&internaladminv1.ClusterComputeClassInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-compute-class",
},
},
&internaladminv1.ClusterComputeClassInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-compute-class-2",
},
},
).Build(),
},
{
name: "Create project with default computeclass that points to a specific projectcomputeclass",
project: apiv1.Project{
ObjectMeta: metav1.ObjectMeta{
Name: "pcc-project",
},
Spec: v1.ProjectInstanceSpec{
DefaultComputeClass: "project-compute-class",
},
},
client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(
&internaladminv1.ProjectComputeClassInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "project-compute-class",
Namespace: "pcc-project",
},
},
).Build(),
},
{
name: "Create project with default computeclass that points to a projectcomputeclass in a different project",
project: apiv1.Project{
ObjectMeta: metav1.ObjectMeta{
Name: "pcc-project",
},
Spec: v1.ProjectInstanceSpec{
DefaultComputeClass: "project-compute-class",
},
},
client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(
&internaladminv1.ProjectComputeClassInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "project-compute-class",
Namespace: "not-pcc-project",
},
},
).Build(),
wantError: true,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 122cbf8

Please sign in to comment.