This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch deprecate in repository https://gitbox.apache.org/repos/asf/skywalking-swck.git
commit 7ec002f2848af775e62bee591aede8c2d4651b18 Author: kezhenxu94 <kezhenx...@apache.org> AuthorDate: Fri Feb 21 21:09:54 2025 +0800 Replace deprecated APIs with recommended ones --- .../apis/operator/v1alpha1/banyandb_webhook.go | 15 +++++++----- .../operator/v1alpha1/eventexporter_webhook.go | 27 +++++++++++++--------- operator/apis/operator/v1alpha1/fetcher_webhook.go | 20 ++++++++-------- .../apis/operator/v1alpha1/javaagent_webhook.go | 23 ++++++++++-------- .../apis/operator/v1alpha1/oapserver_webhook.go | 21 +++++++++-------- .../operator/v1alpha1/oapserverconfig_webhook.go | 15 +++++++----- .../v1alpha1/oapserverdynamicconfig_webhook.go | 20 ++++++++-------- .../apis/operator/v1alpha1/satellite_webhook.go | 21 +++++++++-------- operator/apis/operator/v1alpha1/storage_webhook.go | 21 +++++++++-------- operator/apis/operator/v1alpha1/swagent_webhook.go | 21 +++++++++-------- operator/apis/operator/v1alpha1/ui_webhook.go | 21 +++++++++-------- 11 files changed, 129 insertions(+), 96 deletions(-) diff --git a/operator/apis/operator/v1alpha1/banyandb_webhook.go b/operator/apis/operator/v1alpha1/banyandb_webhook.go index 81c30c1..5afe576 100644 --- a/operator/apis/operator/v1alpha1/banyandb_webhook.go +++ b/operator/apis/operator/v1alpha1/banyandb_webhook.go @@ -18,6 +18,7 @@ package v1alpha1 import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime" @@ -38,9 +39,9 @@ func (r *BanyanDB) SetupWebhookWithManager(mgr ctrl.Manager) error { // nolint: lll //+kubebuilder:webhook:path=/mutate-operator-skywalking-apache-org-v1alpha1-banyandb,mutating=true,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=banyandbs,verbs=create;update,versions=v1alpha1,name=mbanyandb.kb.io,admissionReviewVersions=v1 -var _ webhook.Defaulter = &BanyanDB{} +var _ webhook.CustomDefaulter = &BanyanDB{} -func (r *BanyanDB) Default() { +func (r *BanyanDB) Default(_ context.Context, _ runtime.Object) error { banyandbLog.Info("default", "name", r.Name) if r.Spec.Version == "" { @@ -56,24 +57,26 @@ func (r *BanyanDB) Default() { // currently only support one data copy r.Spec.Counts = 1 } + + return nil } // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,verbs=create;update,path=/validate-operator-skywalking-apache-org-v1alpha1-banyandb,mutating=false,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=banyandbs,versions=v1alpha1,name=vbanyandb.kb.io -var _ webhook.Validator = &BanyanDB{} +var _ webhook.CustomValidator = &BanyanDB{} -func (r *BanyanDB) ValidateCreate() (admission.Warnings, error) { +func (r *BanyanDB) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { banyandbLog.Info("validate create", "name", r.Name) return nil, r.validate() } -func (r *BanyanDB) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +func (r *BanyanDB) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { banyandbLog.Info("validate update", "name", r.Name) return nil, r.validate() } -func (r *BanyanDB) ValidateDelete() (admission.Warnings, error) { +func (r *BanyanDB) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { banyandbLog.Info("validate delete", "name", r.Name) return nil, r.validate() } diff --git a/operator/apis/operator/v1alpha1/eventexporter_webhook.go b/operator/apis/operator/v1alpha1/eventexporter_webhook.go index eac2e55..f5e8e01 100644 --- a/operator/apis/operator/v1alpha1/eventexporter_webhook.go +++ b/operator/apis/operator/v1alpha1/eventexporter_webhook.go @@ -18,6 +18,7 @@ package v1alpha1 import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime" @@ -27,8 +28,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" ) -const latestVersion = "latest" -const image = "apache/skywalking-kubernetes-event-exporter" +const ( + latestVersion = "latest" + image = "apache/skywalking-kubernetes-event-exporter" +) // log is for logging in this package. var eventexporterlog = logf.Log.WithName("eventexporter-resource") @@ -42,10 +45,10 @@ func (r *EventExporter) SetupWebhookWithManager(mgr ctrl.Manager) error { // nolint: lll //+kubebuilder:webhook:path=/mutate-operator-skywalking-apache-org-v1alpha1-eventexporter,mutating=true,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=eventexporters,verbs=create;update,versions=v1alpha1,name=meventexporter.kb.io,admissionReviewVersions=v1 -var _ webhook.Defaulter = &EventExporter{} +var _ webhook.CustomDefaulter = &EventExporter{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *EventExporter) Default() { +func (r *EventExporter) Default(_ context.Context, _ runtime.Object) error { eventexporterlog.Info("default", "name", r.Name) if r.Spec.Version == "" { @@ -59,29 +62,31 @@ func (r *EventExporter) Default() { if r.Spec.Replicas == 0 { r.Spec.Replicas = 1 } + + return nil } // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,path=/mutate-operator-skywalking-apache-org-v1alpha1-eventexporter,mutating=true,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=eventexporters,verbs=create;update,versions=v1alpha1,name=meventexporter.kb.io -var _ webhook.Validator = &EventExporter{} +var _ webhook.CustomValidator = &EventExporter{} -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *EventExporter) ValidateCreate() (admission.Warnings, error) { +// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *EventExporter) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { eventexporterlog.Info("validate create", "name", r.Name) return nil, r.validate() } -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *EventExporter) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *EventExporter) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { eventexporterlog.Info("validate update", "name", r.Name) return nil, r.validate() } -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *EventExporter) ValidateDelete() (admission.Warnings, error) { +// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type +func (r *EventExporter) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { eventexporterlog.Info("validate delete", "name", r.Name) return nil, nil diff --git a/operator/apis/operator/v1alpha1/fetcher_webhook.go b/operator/apis/operator/v1alpha1/fetcher_webhook.go index cd02aba..023526a 100644 --- a/operator/apis/operator/v1alpha1/fetcher_webhook.go +++ b/operator/apis/operator/v1alpha1/fetcher_webhook.go @@ -18,6 +18,7 @@ package v1alpha1 import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime" @@ -39,35 +40,36 @@ func (r *Fetcher) SetupWebhookWithManager(mgr ctrl.Manager) error { // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,path=/mutate-operator-skywalking-apache-org-v1alpha1-fetcher,mutating=true,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=fetchers,verbs=create;update,versions=v1alpha1,name=mfetcher.kb.io -var _ webhook.Defaulter = &Fetcher{} +var _ webhook.CustomDefaulter = &Fetcher{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *Fetcher) Default() { +func (r *Fetcher) Default(_ context.Context, _ runtime.Object) error { fetcherlog.Info("default", "name", r.Name) if r.Spec.ClusterName == "" { r.Spec.ClusterName = r.Name } + return nil } // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,verbs=create;update,path=/validate-operator-skywalking-apache-org-v1alpha1-fetcher,mutating=false,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=fetchers,versions=v1alpha1,name=vfetcher.kb.io -var _ webhook.Validator = &Fetcher{} +var _ webhook.CustomValidator = &Fetcher{} -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *Fetcher) ValidateCreate() (admission.Warnings, error) { +// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *Fetcher) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { fetcherlog.Info("validate create", "name", r.Name) return nil, r.validate() } -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *Fetcher) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *Fetcher) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { fetcherlog.Info("validate update", "name", r.Name) return nil, r.validate() } -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *Fetcher) ValidateDelete() (admission.Warnings, error) { +// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type +func (r *Fetcher) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { fetcherlog.Info("validate delete", "name", r.Name) return nil, nil } diff --git a/operator/apis/operator/v1alpha1/javaagent_webhook.go b/operator/apis/operator/v1alpha1/javaagent_webhook.go index 2f98087..2aec612 100644 --- a/operator/apis/operator/v1alpha1/javaagent_webhook.go +++ b/operator/apis/operator/v1alpha1/javaagent_webhook.go @@ -18,6 +18,7 @@ package v1alpha1 import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime" @@ -45,15 +46,15 @@ func (r *JavaAgent) SetupWebhookWithManager(mgr ctrl.Manager) error { // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,path=/mutate-operator-skywalking-apache-org-v1alpha1-javaagent,mutating=true,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=javaagents,verbs=create;update,versions=v1alpha1,name=mjavaagent.kb.io -var _ webhook.Defaulter = &JavaAgent{} +var _ webhook.CustomDefaulter = &JavaAgent{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *JavaAgent) Default() { +func (r *JavaAgent) Default(_ context.Context, _ runtime.Object) error { javaagentlog.Info("default", "name", r.Name) config := r.Spec.AgentConfiguration if config == nil { - return + return nil } service := GetServiceName(&config) @@ -65,27 +66,29 @@ func (r *JavaAgent) Default() { if r.Spec.BackendService == "" && backend != "" { r.Spec.BackendService = backend } + + return nil } // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,verbs=create;update,path=/validate-operator-skywalking-apache-org-v1alpha1-javaagent,mutating=false,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=javaagents,versions=v1alpha1,name=vjavaagent.kb.io -var _ webhook.Validator = &JavaAgent{} +var _ webhook.CustomValidator = &JavaAgent{} -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *JavaAgent) ValidateCreate() (admission.Warnings, error) { +// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *JavaAgent) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { javaagentlog.Info("validate create", "name", r.Name) return nil, r.validate() } -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *JavaAgent) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *JavaAgent) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { javaagentlog.Info("validate update", "name", r.Name) return nil, r.validate() } -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *JavaAgent) ValidateDelete() (admission.Warnings, error) { +// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type +func (r *JavaAgent) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { javaagentlog.Info("validate delete", "name", r.Name) return nil, nil } diff --git a/operator/apis/operator/v1alpha1/oapserver_webhook.go b/operator/apis/operator/v1alpha1/oapserver_webhook.go index 7e3cb0a..ab6625c 100644 --- a/operator/apis/operator/v1alpha1/oapserver_webhook.go +++ b/operator/apis/operator/v1alpha1/oapserver_webhook.go @@ -18,6 +18,7 @@ package v1alpha1 import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime" @@ -41,10 +42,10 @@ func (r *OAPServer) SetupWebhookWithManager(mgr ctrl.Manager) error { // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,path=/mutate-operator-skywalking-apache-org-v1alpha1-oapserver,mutating=true,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=oapservers,verbs=create;update,versions=v1alpha1,name=moapserver.kb.io -var _ webhook.Defaulter = &OAPServer{} +var _ webhook.CustomDefaulter = &OAPServer{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *OAPServer) Default() { +func (r *OAPServer) Default(_ context.Context, _ runtime.Object) error { oapserverlog.Info("default", "name", r.Name) image := r.Spec.Image @@ -59,27 +60,29 @@ func (r *OAPServer) Default() { "--set meshConfig.enableEnvoyAccessLogService=true", r.Name, r.Namespace) } } + + return nil } // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,verbs=create;update,path=/validate-operator-skywalking-apache-org-v1alpha1-oapserver,mutating=false,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=oapservers,versions=v1alpha1,name=voapserver.kb.io -var _ webhook.Validator = &OAPServer{} +var _ webhook.CustomValidator = &OAPServer{} -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *OAPServer) ValidateCreate() (admission.Warnings, error) { +// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *OAPServer) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { oapserverlog.Info("validate create", "name", r.Name) return nil, r.validate() } -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *OAPServer) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *OAPServer) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { oapserverlog.Info("validate update", "name", r.Name) return nil, r.validate() } -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *OAPServer) ValidateDelete() (admission.Warnings, error) { +// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type +func (r *OAPServer) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { oapserverlog.Info("validate delete", "name", r.Name) return nil, nil } diff --git a/operator/apis/operator/v1alpha1/oapserverconfig_webhook.go b/operator/apis/operator/v1alpha1/oapserverconfig_webhook.go index ee76e94..907b93a 100644 --- a/operator/apis/operator/v1alpha1/oapserverconfig_webhook.go +++ b/operator/apis/operator/v1alpha1/oapserverconfig_webhook.go @@ -18,6 +18,7 @@ package v1alpha1 import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime" @@ -39,37 +40,39 @@ func (r *OAPServerConfig) SetupWebhookWithManager(mgr ctrl.Manager) error { // nolint: lll //+kubebuilder:webhook:path=/mutate-operator-skywalking-apache-org-v1alpha1-oapserverconfig,mutating=true,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=oapserverconfigs,verbs=create;update,versions=v1alpha1,name=moapserverconfig.kb.io,admissionReviewVersions=v1 -var _ webhook.Defaulter = &OAPServerConfig{} +var _ webhook.CustomDefaulter = &OAPServerConfig{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *OAPServerConfig) Default() { +func (r *OAPServerConfig) Default(_ context.Context, _ runtime.Object) error { oapserverconfiglog.Info("default", "name", r.Name) // Default version is "9.5.0" if r.Spec.Version == "" { r.Spec.Version = "9.5.0" } + + return nil } // nolint: lll //+kubebuilder:webhook:path=/validate-operator-skywalking-apache-org-v1alpha1-oapserverconfig,mutating=false,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=oapserverconfigs,verbs=create;update,versions=v1alpha1,name=voapserverconfig.kb.io,admissionReviewVersions=v1 -var _ webhook.Validator = &OAPServerConfig{} +var _ webhook.CustomValidator = &OAPServerConfig{} // ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *OAPServerConfig) ValidateCreate() (admission.Warnings, error) { +func (r *OAPServerConfig) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { oapserverconfiglog.Info("validate create", "name", r.Name) return nil, r.validate() } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *OAPServerConfig) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +func (r *OAPServerConfig) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { oapserverconfiglog.Info("validate update", "name", r.Name) return nil, r.validate() } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *OAPServerConfig) ValidateDelete() (admission.Warnings, error) { +func (r *OAPServerConfig) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { oapserverconfiglog.Info("validate delete", "name", r.Name) return nil, nil } diff --git a/operator/apis/operator/v1alpha1/oapserverdynamicconfig_webhook.go b/operator/apis/operator/v1alpha1/oapserverdynamicconfig_webhook.go index 994f0f2..1f89a07 100644 --- a/operator/apis/operator/v1alpha1/oapserverdynamicconfig_webhook.go +++ b/operator/apis/operator/v1alpha1/oapserverdynamicconfig_webhook.go @@ -18,6 +18,7 @@ package v1alpha1 import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime" @@ -39,10 +40,10 @@ func (r *OAPServerDynamicConfig) SetupWebhookWithManager(mgr ctrl.Manager) error // nolint: lll //+kubebuilder:webhook:path=/mutate-operator-skywalking-apache-org-v1alpha1-oapserverdynamicconfig,mutating=true,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=oapserverdynamicconfigs,verbs=create;update,versions=v1alpha1,name=moapserverdynamicconfig.kb.io,admissionReviewVersions=v1 -var _ webhook.Defaulter = &OAPServerDynamicConfig{} +var _ webhook.CustomDefaulter = &OAPServerDynamicConfig{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *OAPServerDynamicConfig) Default() { +func (r *OAPServerDynamicConfig) Default(_ context.Context, _ runtime.Object) error { oapserverdynamicconfiglog.Info("default", "name", r.Name) // Default version is "9.5.0" @@ -54,27 +55,28 @@ func (r *OAPServerDynamicConfig) Default() { if r.Spec.LabelSelector == "" { r.Spec.LabelSelector = "app=collector,release=skywalking" } + return nil } // nolint: lll //+kubebuilder:webhook:path=/validate-operator-skywalking-apache-org-v1alpha1-oapserverdynamicconfig,mutating=false,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=oapserverdynamicconfigs,verbs=create;update,versions=v1alpha1,name=voapserverdynamicconfig.kb.io,admissionReviewVersions=v1 -var _ webhook.Validator = &OAPServerDynamicConfig{} +var _ webhook.CustomValidator = &OAPServerDynamicConfig{} -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *OAPServerDynamicConfig) ValidateCreate() (admission.Warnings, error) { +// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *OAPServerDynamicConfig) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { oapserverdynamicconfiglog.Info("validate create", "name", r.Name) return nil, r.validate() } -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *OAPServerDynamicConfig) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *OAPServerDynamicConfig) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { oapserverdynamicconfiglog.Info("validate update", "name", r.Name) return nil, r.validate() } -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *OAPServerDynamicConfig) ValidateDelete() (admission.Warnings, error) { +// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type +func (r *OAPServerDynamicConfig) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { oapserverdynamicconfiglog.Info("validate delete", "name", r.Name) return nil, nil } diff --git a/operator/apis/operator/v1alpha1/satellite_webhook.go b/operator/apis/operator/v1alpha1/satellite_webhook.go index 55517ec..05a6905 100644 --- a/operator/apis/operator/v1alpha1/satellite_webhook.go +++ b/operator/apis/operator/v1alpha1/satellite_webhook.go @@ -18,6 +18,7 @@ package v1alpha1 import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime" @@ -39,10 +40,10 @@ func (r *Satellite) SetupWebhookWithManager(mgr ctrl.Manager) error { //nolint: lll //+kubebuilder:webhook:path=/mutate-operator-skywalking-apache-org-v1alpha1-satellite,mutating=true,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=satellites,verbs=create;update,versions=v1alpha1,name=msatellite.kb.io,admissionReviewVersions=v1 -var _ webhook.Defaulter = &Satellite{} +var _ webhook.CustomDefaulter = &Satellite{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *Satellite) Default() { +func (r *Satellite) Default(_ context.Context, _ runtime.Object) error { satellitelog.Info("default", "name", r.Name) image := r.Spec.Image @@ -60,27 +61,29 @@ func (r *Satellite) Default() { "--set meshConfig.defaultConfig.envoyAccessLogService.address=%s.%s:11800 "+ "--set meshConfig.enableEnvoyAccessLogService=true", r.Name, r.Namespace) } + + return nil } //nolint: lll //+kubebuilder:webhook:path=/validate-operator-skywalking-apache-org-v1alpha1-satellite,mutating=false,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=satellites,verbs=create;update,versions=v1alpha1,name=vsatellite.kb.io,admissionReviewVersions=v1 -var _ webhook.Validator = &Satellite{} +var _ webhook.CustomValidator = &Satellite{} -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *Satellite) ValidateCreate() (admission.Warnings, error) { +// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *Satellite) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { satellitelog.Info("validate create", "name", r.Name) return nil, r.validate() } -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *Satellite) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *Satellite) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { satellitelog.Info("validate update", "name", r.Name) return nil, r.validate() } -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *Satellite) ValidateDelete() (admission.Warnings, error) { +// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type +func (r *Satellite) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { satellitelog.Info("validate delete", "name", r.Name) return nil, r.validate() } diff --git a/operator/apis/operator/v1alpha1/storage_webhook.go b/operator/apis/operator/v1alpha1/storage_webhook.go index 94ca31b..0b05db7 100644 --- a/operator/apis/operator/v1alpha1/storage_webhook.go +++ b/operator/apis/operator/v1alpha1/storage_webhook.go @@ -18,6 +18,8 @@ package v1alpha1 import ( + "context" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -40,10 +42,10 @@ func (r *Storage) SetupWebhookWithManager(mgr ctrl.Manager) error { // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,path=/mutate-operator-skywalking-apache-org-v1alpha1-storage,mutating=true,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=storages,verbs=create;update,versions=v1alpha1,name=mstorage.kb.io -var _ webhook.Defaulter = &Storage{} +var _ webhook.CustomDefaulter = &Storage{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *Storage) Default() { +func (r *Storage) Default(_ context.Context, _ runtime.Object) error { storagelog.Info("default", "name", r.Name) if r.Spec.ConnectType == "internal" { if r.Spec.Image == "" { @@ -53,27 +55,28 @@ func (r *Storage) Default() { r.Spec.Instances = 3 } } + return nil } // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,verbs=create;update,path=/validate-operator-skywalking-apache-org-v1alpha1-storage,mutating=false,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=storages,versions=v1alpha1,name=vstorage.kb.io -var _ webhook.Validator = &Storage{} +var _ webhook.CustomValidator = &Storage{} -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *Storage) ValidateCreate() (admission.Warnings, error) { +// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *Storage) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { storagelog.Info("validate create", "name", r.Name) return nil, r.valid() } -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *Storage) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *Storage) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { storagelog.Info("validate update", "name", r.Name) return nil, r.valid() } -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *Storage) ValidateDelete() (admission.Warnings, error) { +// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type +func (r *Storage) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { storagelog.Info("validate delete", "name", r.Name) return nil, nil } diff --git a/operator/apis/operator/v1alpha1/swagent_webhook.go b/operator/apis/operator/v1alpha1/swagent_webhook.go index aac6bf7..0bc720b 100644 --- a/operator/apis/operator/v1alpha1/swagent_webhook.go +++ b/operator/apis/operator/v1alpha1/swagent_webhook.go @@ -18,6 +18,8 @@ package v1alpha1 import ( + "context" + "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -37,34 +39,35 @@ func (r *SwAgent) SetupWebhookWithManager(mgr ctrl.Manager) error { // nolint: lll //+kubebuilder:webhook:path=/mutate-operator-skywalking-apache-org-v1alpha1-swagent,mutating=true,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=swagents,verbs=create;update,versions=v1alpha1,name=mswagent.kb.io,admissionReviewVersions=v1 -var _ webhook.Defaulter = &SwAgent{} +var _ webhook.CustomDefaulter = &SwAgent{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *SwAgent) Default() { +func (r *SwAgent) Default(_ context.Context, _ runtime.Object) error { swagentlog.Info("default", "name", r.Name) r.setDefault() + return nil } // nolint: lll //+kubebuilder:webhook:path=/validate-operator-skywalking-apache-org-v1alpha1-swagent,mutating=false,failurePolicy=fail,sideEffects=None,groups=operator.skywalking.apache.org,resources=swagents,verbs=create;update,versions=v1alpha1,name=vswagent.kb.io,admissionReviewVersions=v1 -var _ webhook.Validator = &SwAgent{} +var _ webhook.CustomValidator = &SwAgent{} -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *SwAgent) ValidateCreate() (admission.Warnings, error) { +// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *SwAgent) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { swagentlog.Info("validate create", "name", r.Name) r.setDefault() return nil, nil } -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *SwAgent) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *SwAgent) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { swagentlog.Info("validate update", "name", r.Name) return nil, nil } -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *SwAgent) ValidateDelete() (admission.Warnings, error) { +// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type +func (r *SwAgent) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { swagentlog.Info("validate delete", "name", r.Name) return nil, nil } diff --git a/operator/apis/operator/v1alpha1/ui_webhook.go b/operator/apis/operator/v1alpha1/ui_webhook.go index 959318f..a719cbf 100644 --- a/operator/apis/operator/v1alpha1/ui_webhook.go +++ b/operator/apis/operator/v1alpha1/ui_webhook.go @@ -18,6 +18,7 @@ package v1alpha1 import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime" @@ -39,10 +40,10 @@ func (r *UI) SetupWebhookWithManager(mgr ctrl.Manager) error { // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,path=/mutate-operator-skywalking-apache-org-v1alpha1-ui,mutating=true,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=uis,verbs=create;update,versions=v1alpha1,name=mui.kb.io -var _ webhook.Defaulter = &UI{} +var _ webhook.CustomDefaulter = &UI{} // Default implements webhook.Defaulter so a webhook will be registered for the type -func (r *UI) Default() { +func (r *UI) Default(_ context.Context, _ runtime.Object) error { uilog.Info("default", "name", r.Name) if r.Spec.Image == "" { @@ -53,27 +54,29 @@ func (r *UI) Default() { if r.Spec.OAPServerAddress == "" { r.Spec.OAPServerAddress = fmt.Sprintf("http://%s-oap.%s:12800", r.Name, r.Namespace) } + + return nil } // nolint: lll // +kubebuilder:webhook:admissionReviewVersions=v1,sideEffects=None,verbs=create;update,path=/validate-operator-skywalking-apache-org-v1alpha1-ui,mutating=false,failurePolicy=fail,groups=operator.skywalking.apache.org,resources=uis,versions=v1alpha1,name=vui.kb.io -var _ webhook.Validator = &UI{} +var _ webhook.CustomValidator = &UI{} -// ValidateCreate implements webhook.Validator so a webhook will be registered for the type -func (r *UI) ValidateCreate() (admission.Warnings, error) { +// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *UI) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { uilog.Info("validate create", "name", r.Name) return nil, r.validate() } -// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type -func (r *UI) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { +// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type +func (r *UI) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { uilog.Info("validate update", "name", r.Name) return nil, r.validate() } -// ValidateDelete implements webhook.Validator so a webhook will be registered for the type -func (r *UI) ValidateDelete() (admission.Warnings, error) { +// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type +func (r *UI) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { uilog.Info("validate delete", "name", r.Name) return nil, nil }