Skip to content

Commit 844f97a

Browse files
committed
chore: append comments for modified Validator and CustomValidator
Signed-off-by: STRRL <[email protected]>
1 parent 6e2a023 commit 844f97a

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

pkg/webhook/admission/validator.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,25 @@ import (
2828
)
2929

3030
// Validator defines functions for validating an operation.
31+
// The custom resource kind which implements this interface can validate itself.
32+
// To validate the custom resource with another specific struct, use CustomValidator instead.
3133
type Validator interface {
3234
runtime.Object
33-
ValidateCreate() ([]string, error)
34-
ValidateUpdate(old runtime.Object) ([]string, error)
35-
ValidateDelete() ([]string, error)
35+
36+
// ValidateCreate validates the object on creation.
37+
// The optional warnings will be added to the response as warning messages.
38+
// Return an error if the object is invalid.
39+
ValidateCreate() (warnings []string, err error)
40+
41+
// ValidateUpdate validates the object on update. The oldObj is the object before the update.
42+
// The optional warnings will be added to the response as warning messages.
43+
// Return an error if the object is invalid.
44+
ValidateUpdate(old runtime.Object) (warnings []string, err error)
45+
46+
// ValidateDelete validates the object on deletion.
47+
// The optional warnings will be added to the response as warning messages.
48+
// Return an error if the object is invalid.
49+
ValidateDelete() (warnings []string, err error)
3650
}
3751

3852
// ValidatingWebhookFor creates a new Webhook for validating the provided type.

pkg/webhook/admission/validator_custom.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,23 @@ import (
2828
)
2929

3030
// CustomValidator defines functions for validating an operation.
31+
// The object to be validated is passed into methods as a parameter.
3132
type CustomValidator interface {
32-
ValidateCreate(ctx context.Context, obj runtime.Object) ([]string, error)
33-
ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) ([]string, error)
34-
ValidateDelete(ctx context.Context, obj runtime.Object) ([]string, error)
33+
34+
// ValidateCreate validates the object on creation.
35+
// The optional warnings will be added to the response as warning messages.
36+
// Return an error if the object is invalid.
37+
ValidateCreate(ctx context.Context, obj runtime.Object) (warnings []string, err error)
38+
39+
// ValidateUpdate validates the object on update.
40+
// The optional warnings will be added to the response as warning messages.
41+
// Return an error if the object is invalid.
42+
ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (warnings []string, err error)
43+
44+
// ValidateDelete validates the object on deletion.
45+
// The optional warnings will be added to the response as warning messages.
46+
// Return an error if the object is invalid.
47+
ValidateDelete(ctx context.Context, obj runtime.Object) (warnings []string, err error)
3548
}
3649

3750
// WithCustomValidator creates a new Webhook for validating the provided type.

0 commit comments

Comments
 (0)