Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: append comments for modified Validator and CustomValidator
Signed-off-by: STRRL <[email protected]>
  • Loading branch information
STRRL committed Apr 13, 2023
commit 844f97aff94a6d2272fe27f2fef9eb9a0626d55b
20 changes: 17 additions & 3 deletions pkg/webhook/admission/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,25 @@ import (
)

// Validator defines functions for validating an operation.
// The custom resource kind which implements this interface can validate itself.
// To validate the custom resource with another specific struct, use CustomValidator instead.
type Validator interface {
runtime.Object
ValidateCreate() ([]string, error)
ValidateUpdate(old runtime.Object) ([]string, error)
ValidateDelete() ([]string, error)

// ValidateCreate validates the object on creation.
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
ValidateCreate() (warnings []string, err error)

// ValidateUpdate validates the object on update. The oldObj is the object before the update.
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
ValidateUpdate(old runtime.Object) (warnings []string, err error)

// ValidateDelete validates the object on deletion.
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
ValidateDelete() (warnings []string, err error)
}

// ValidatingWebhookFor creates a new Webhook for validating the provided type.
Expand Down
19 changes: 16 additions & 3 deletions pkg/webhook/admission/validator_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,23 @@ import (
)

// CustomValidator defines functions for validating an operation.
// The object to be validated is passed into methods as a parameter.
type CustomValidator interface {
ValidateCreate(ctx context.Context, obj runtime.Object) ([]string, error)
ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) ([]string, error)
ValidateDelete(ctx context.Context, obj runtime.Object) ([]string, error)

// ValidateCreate validates the object on creation.
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
ValidateCreate(ctx context.Context, obj runtime.Object) (warnings []string, err error)

// ValidateUpdate validates the object on update.
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (warnings []string, err error)

// ValidateDelete validates the object on deletion.
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
ValidateDelete(ctx context.Context, obj runtime.Object) (warnings []string, err error)
}

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