Skip to content

Commit efa10a8

Browse files
syscod3claude
andcommitted
feat(webhook): ImpVMClass validator stub
Registration stub implementing admission.Validator[*ImpVMClass]; all three methods return nil. Numeric field minimums are enforced by CEL markers on the CRD schema; immutability checks will follow in Phase 2. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a2d07a7 commit efa10a8

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2026.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"context"
21+
22+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
23+
24+
impdevv1alpha1 "github.com/syscode-labs/imp/api/v1alpha1"
25+
)
26+
27+
// ImpVMClassWebhook validates ImpVMClass objects.
28+
// Numeric field minimums (VCPU≥1, MemoryMiB≥128, DiskGiB≥1) are enforced by
29+
// CEL validation markers on the CRD schema; this webhook is a registration
30+
// stub that will hold immutability checks in Phase 2.
31+
type ImpVMClassWebhook struct{}
32+
33+
var _ admission.Validator[*impdevv1alpha1.ImpVMClass] = &ImpVMClassWebhook{}
34+
35+
// ValidateCreate implements admission.Validator[*impdevv1alpha1.ImpVMClass].
36+
func (w *ImpVMClassWebhook) ValidateCreate(_ context.Context, _ *impdevv1alpha1.ImpVMClass) (admission.Warnings, error) {
37+
return nil, nil
38+
}
39+
40+
// ValidateUpdate implements admission.Validator[*impdevv1alpha1.ImpVMClass].
41+
func (w *ImpVMClassWebhook) ValidateUpdate(_ context.Context, _, _ *impdevv1alpha1.ImpVMClass) (admission.Warnings, error) {
42+
return nil, nil
43+
}
44+
45+
// ValidateDelete implements admission.Validator[*impdevv1alpha1.ImpVMClass].
46+
func (w *ImpVMClassWebhook) ValidateDelete(_ context.Context, _ *impdevv1alpha1.ImpVMClass) (admission.Warnings, error) {
47+
return nil, nil
48+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2026.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
25+
impdevv1alpha1 "github.com/syscode-labs/imp/api/v1alpha1"
26+
)
27+
28+
// newClass builds a minimal ImpVMClass for use in tests.
29+
func newClass(vcpu, memMiB, diskGiB int32) *impdevv1alpha1.ImpVMClass {
30+
return &impdevv1alpha1.ImpVMClass{
31+
ObjectMeta: metav1.ObjectMeta{
32+
Name: "test-class",
33+
},
34+
Spec: impdevv1alpha1.ImpVMClassSpec{
35+
VCPU: vcpu,
36+
MemoryMiB: memMiB,
37+
DiskGiB: diskGiB,
38+
},
39+
}
40+
}
41+
42+
func TestImpVMClassWebhook_ValidateCreate(t *testing.T) {
43+
wh := &ImpVMClassWebhook{}
44+
cls := newClass(2, 256, 10)
45+
46+
_, err := wh.ValidateCreate(context.Background(), cls)
47+
if err != nil {
48+
t.Errorf("expected no error for valid class, got: %v", err)
49+
}
50+
}
51+
52+
func TestImpVMClassWebhook_ValidateUpdate(t *testing.T) {
53+
wh := &ImpVMClassWebhook{}
54+
oldCls := newClass(2, 256, 10)
55+
newCls := newClass(4, 512, 20)
56+
57+
_, err := wh.ValidateUpdate(context.Background(), oldCls, newCls)
58+
if err != nil {
59+
t.Errorf("expected no error on update, got: %v", err)
60+
}
61+
}
62+
63+
func TestImpVMClassWebhook_ValidateDelete(t *testing.T) {
64+
wh := &ImpVMClassWebhook{}
65+
cls := newClass(2, 256, 10)
66+
67+
_, err := wh.ValidateDelete(context.Background(), cls)
68+
if err != nil {
69+
t.Errorf("expected no error on delete, got: %v", err)
70+
}
71+
}

0 commit comments

Comments
 (0)