Skip to content

Commit

Permalink
Upgrade to controller-runtime 0.16.2
Browse files Browse the repository at this point in the history
Signed-off-by: Dean Roehrich <[email protected]>
  • Loading branch information
roehrich-hpe committed Oct 9, 2023
1 parent 0247467 commit b5f4f19
Show file tree
Hide file tree
Showing 821 changed files with 58,112 additions and 31,562 deletions.
23 changes: 12 additions & 11 deletions api/v1alpha1/nnfcontainerprofile_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand All @@ -47,7 +48,7 @@ func (r *NnfContainerProfile) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &NnfContainerProfile{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *NnfContainerProfile) ValidateCreate() error {
func (r *NnfContainerProfile) ValidateCreate() (admission.Warnings, error) {
nnfcontainerprofilelog.Info("validate create", "name", r.Name)

// If it's not pinned, then it's being made available for users to select
Expand All @@ -56,27 +57,27 @@ func (r *NnfContainerProfile) ValidateCreate() error {
if !r.Data.Pinned && r.GetNamespace() != profileNamespace {
err := fmt.Errorf("incorrect namespace for profile that is intended to be selected by users; the namespace should be '%s'", profileNamespace)
nnfstorageprofilelog.Error(err, "invalid")
return err
return nil, err
}

if err := r.validateContent(); err != nil {
nnfcontainerprofilelog.Error(err, "invalid NnfContainerProfile resource")
return err
return nil, err
}

return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *NnfContainerProfile) ValidateUpdate(old runtime.Object) error {
func (r *NnfContainerProfile) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
nnfcontainerprofilelog.Info("validate update", "name", r.Name)

obj := old.(*NnfContainerProfile)

if obj.Data.Pinned != r.Data.Pinned {
err := fmt.Errorf("the pinned flag is immutable")
nnfcontainerprofilelog.Error(err, "invalid")
return err
return nil, err
}

if obj.Data.Pinned {
Expand All @@ -86,16 +87,16 @@ func (r *NnfContainerProfile) ValidateUpdate(old runtime.Object) error {
if !reflect.DeepEqual(r.Data, obj.Data) {
err := fmt.Errorf("update on pinned resource not allowed")
nnfcontainerprofilelog.Error(err, "invalid")
return err
return nil, err
}
}

if err := r.validateContent(); err != nil {
nnfcontainerprofilelog.Error(err, "invalid NnfContainerProfile resource")
return err
return nil, err
}

return nil
return nil, nil
}

func (r *NnfContainerProfile) validateContent() error {
Expand Down Expand Up @@ -160,7 +161,7 @@ func (r *NnfContainerProfile) validateContent() error {
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *NnfContainerProfile) ValidateDelete() error {
func (r *NnfContainerProfile) ValidateDelete() (admission.Warnings, error) {
nnfcontainerprofilelog.Info("validate delete", "name", r.Name)
return nil
return nil, nil
}
23 changes: 12 additions & 11 deletions api/v1alpha1/nnfstorageprofile_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand All @@ -45,7 +46,7 @@ func (r *NnfStorageProfile) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &NnfStorageProfile{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *NnfStorageProfile) ValidateCreate() error {
func (r *NnfStorageProfile) ValidateCreate() (admission.Warnings, error) {
nnfstorageprofilelog.V(1).Info("validate create", "name", r.Name)

// If it's not pinned, then it's being made available for users to select
Expand All @@ -54,24 +55,24 @@ func (r *NnfStorageProfile) ValidateCreate() error {
if !r.Data.Pinned && r.GetNamespace() != profileNamespace {
err := fmt.Errorf("incorrect namespace for profile that is intended to be selected by users; the namespace should be '%s'", profileNamespace)
nnfstorageprofilelog.Error(err, "invalid")
return err
return nil, err
}
if err := r.validateContent(); err != nil {
nnfstorageprofilelog.Error(err, "invalid NnfStorageProfile resource")
return err
return nil, err
}
return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *NnfStorageProfile) ValidateUpdate(old runtime.Object) error {
func (r *NnfStorageProfile) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
nnfstorageprofilelog.V(1).Info("validate update", "name", r.Name)

obj := old.(*NnfStorageProfile)
if obj.Data.Pinned != r.Data.Pinned {
err := fmt.Errorf("the pinned flag is immutable")
nnfcontainerprofilelog.Error(err, "invalid")
return err
return nil, err
}
if obj.Data.Pinned {
// Allow metadata to be updated, for things like finalizers,
Expand All @@ -81,23 +82,23 @@ func (r *NnfStorageProfile) ValidateUpdate(old runtime.Object) error {
msg := "update on pinned resource not allowed"
err := fmt.Errorf(msg)
nnfstorageprofilelog.Error(err, "invalid")
return err
return nil, err
}
}

if err := r.validateContent(); err != nil {
nnfstorageprofilelog.Error(err, "invalid NnfStorageProfile resource")
return err
return nil, err
}
return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *NnfStorageProfile) ValidateDelete() error {
func (r *NnfStorageProfile) ValidateDelete() (admission.Warnings, error) {
//nnfstorageprofilelog.V(1).Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil
}

func (r *NnfStorageProfile) validateContent() error {
Expand Down
16 changes: 10 additions & 6 deletions api/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down Expand Up @@ -111,12 +113,14 @@ var _ = BeforeSuite(func() {
// start webhook server using Manager
webhookInstallOptions := &testEnv.WebhookInstallOptions
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
LeaderElection: false,
MetricsBindAddress: "0",
Scheme: scheme,
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
LeaderElection: false,
Metrics: metricsserver.Options{BindAddress: "0"},
})
Expect(err).NotTo(HaveOccurred())

Expand Down
Loading

0 comments on commit b5f4f19

Please sign in to comment.