Skip to content

Commit

Permalink
feat(STONEINTG-677): update webhooks to for controller-runtime v0.16.3
Browse files Browse the repository at this point in the history
* Add the addmissions.warnings to validation functions

Signed-off-by: dirgim <[email protected]>
  • Loading branch information
dirgim committed Nov 13, 2023
1 parent 3529869 commit 41b7f7c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 8 additions & 7 deletions api/v1beta1/integrationtestscenario_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (r *IntegrationTestScenario) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand All @@ -35,24 +36,24 @@ func (r *IntegrationTestScenario) SetupWebhookWithManager(mgr ctrl.Manager) erro
var _ webhook.Validator = &IntegrationTestScenario{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *IntegrationTestScenario) ValidateCreate() error {
func (r *IntegrationTestScenario) ValidateCreate() (warnings admission.Warnings, err error) {
// We use the DNS-1035 format for application names, so ensure it conforms to that specification

if len(validation.IsDNS1035Label(r.Name)) != 0 {
return field.Invalid(field.NewPath("metadata").Child("name"), r.Name,
return nil, field.Invalid(field.NewPath("metadata").Child("name"), r.Name,
"an IntegrationTestScenario resource name must start with a lower case "+
"alphabetical character, be under 63 characters, and can only consist "+
"of lower case alphanumeric characters or ‘-’")
}
return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *IntegrationTestScenario) ValidateUpdate(old runtime.Object) error {
return nil
func (r *IntegrationTestScenario) ValidateUpdate(old runtime.Object) (warnings admission.Warnings, err error) {
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *IntegrationTestScenario) ValidateDelete() error {
return nil
func (r *IntegrationTestScenario) ValidateDelete() (warnings admission.Warnings, err error) {
return nil, nil
}
9 changes: 9 additions & 0 deletions status/reporters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package status_test
import (
"bytes"
"context"
"k8s.io/apimachinery/pkg/runtime/schema"
"time"

"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -195,6 +196,14 @@ type MockK8sClient struct {
err error
}

func (c *MockK8sClient) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error) {
return schema.GroupVersionKind{}, nil
}

func (c *MockK8sClient) IsObjectNamespaced(obj runtime.Object) (bool, error) {
return true, nil
}

func (c *MockK8sClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
if c.listInterceptor != nil {
c.listInterceptor(list)
Expand Down

0 comments on commit 41b7f7c

Please sign in to comment.