Skip to content

Commit

Permalink
chore: update all dependencies for the operator (#685)
Browse files Browse the repository at this point in the history
This PR includes following changes:
-  all dependencies are upgraded to the latest version
- `controler-runtime` package changed the API, this PR also includes
migration to the new API
- `k8s-operator-libs` package changed the API, this PR removes logic
which is not required anymore and does migration to the new API
- move from deprecated `wait.Poll` function to
`wait.PollUntilContextTimeout`
  • Loading branch information
adrianchiris committed Nov 27, 2023
2 parents 350b9cb + 2dc25e3 commit a255cf7
Show file tree
Hide file tree
Showing 34 changed files with 527 additions and 1,108 deletions.
19 changes: 10 additions & 9 deletions api/v1alpha1/hostdevicenetwork_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 @@ -43,40 +44,40 @@ func (w *HostDeviceNetwork) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &HostDeviceNetwork{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (w *HostDeviceNetwork) ValidateCreate() error {
func (w *HostDeviceNetwork) ValidateCreate() (admission.Warnings, error) {
if skipValidations {
nicClusterPolicyLog.Info("skipping CR validation")
return nil
return nil, nil
}

hostDeviceNetworkLog.Info("validate create", "name", w.Name)

return w.validateHostDeviceNetwork()
return nil, w.validateHostDeviceNetwork()
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (w *HostDeviceNetwork) ValidateUpdate(_ runtime.Object) error {
func (w *HostDeviceNetwork) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
if skipValidations {
nicClusterPolicyLog.Info("skipping CR validation")
return nil
return nil, nil
}

hostDeviceNetworkLog.Info("validate update", "name", w.Name)

return w.validateHostDeviceNetwork()
return nil, w.validateHostDeviceNetwork()
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (w *HostDeviceNetwork) ValidateDelete() error {
func (w *HostDeviceNetwork) ValidateDelete() (admission.Warnings, error) {
if skipValidations {
nicClusterPolicyLog.Info("skipping CR validation")
return nil
return nil, nil
}

hostDeviceNetworkLog.Info("validate delete", "name", w.Name)

// Validation for delete call is not required
return nil
return nil, nil
}

/*
Expand Down
6 changes: 4 additions & 2 deletions api/v1alpha1/hostdevicenetwork_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var _ = Describe("Validate", func() {
ResourceName: "hostdev",
},
}
Expect(hostDeviceNetwork.ValidateCreate()).NotTo(HaveOccurred())
_, err := hostDeviceNetwork.ValidateCreate()
Expect(err).NotTo(HaveOccurred())
})
It("Invalid ResourceName", func() {
hostDeviceNetwork := HostDeviceNetwork{
Expand All @@ -40,7 +41,8 @@ var _ = Describe("Validate", func() {
ResourceName: "hostdev!!",
},
}
Expect(hostDeviceNetwork.ValidateCreate().Error()).To(ContainSubstring("Invalid Resource name"))
_, err := hostDeviceNetwork.ValidateCreate()
Expect(err.Error()).To(ContainSubstring("Invalid Resource name"))
})
})
})
19 changes: 10 additions & 9 deletions api/v1alpha1/nicclusterpolicy_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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"
)

const (
Expand Down Expand Up @@ -62,38 +63,38 @@ func (w *NicClusterPolicy) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &NicClusterPolicy{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (w *NicClusterPolicy) ValidateCreate() error {
func (w *NicClusterPolicy) ValidateCreate() (admission.Warnings, error) {
if skipValidations {
nicClusterPolicyLog.Info("skipping CR validation")
return nil
return nil, nil
}

nicClusterPolicyLog.Info("validate create", "name", w.Name)
return w.validateNicClusterPolicy()
return nil, w.validateNicClusterPolicy()
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (w *NicClusterPolicy) ValidateUpdate(_ runtime.Object) error {
func (w *NicClusterPolicy) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
if skipValidations {
nicClusterPolicyLog.Info("skipping CR validation")
return nil
return nil, nil
}

nicClusterPolicyLog.Info("validate update", "name", w.Name)
return w.validateNicClusterPolicy()
return nil, w.validateNicClusterPolicy()
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (w *NicClusterPolicy) ValidateDelete() error {
func (w *NicClusterPolicy) ValidateDelete() (admission.Warnings, error) {
if skipValidations {
nicClusterPolicyLog.Info("skipping CR validation")
return nil
return nil, nil
}

nicClusterPolicyLog.Info("validate delete", "name", w.Name)

// Validation for delete call is not required
return nil
return nil, nil
}

/*
Expand Down
Loading

0 comments on commit a255cf7

Please sign in to comment.