Files
spark-operator/internal/webhook/sparkapplication_defaulter.go
Shingo OmuraandGitHub 566d62aa81 Bump k8s to v1.35.4 and controller-runtime to v0.23.3 (#2946)
* Bump k8s api to 0.35.4, and controller runtime to v0.23.3

Signed-off-by: Shingo Omura <[email protected]>

* Migrated defaulter/validator to be Generic ones

Signed-off-by: Shingo Omura <[email protected]>

* Fixed Endpoints deprecation lint errors (replaced with EndpointSlice)

Signed-off-by: Shingo Omura <[email protected]>

* Deleted unused internal/controller/sparkapplication/validator.go

Signed-off-by: Shingo Omura <[email protected]>

* Add SA1019 exclusion to golangci-lint config so to preserve Requeue behavior of controllers

Signed-off-by: Shingo Omura <[email protected]>

* Fixed util.WriteObjectToFile test. Null creationTimestamp is not marshalled anymore.

Signed-off-by: Shingo Omura <[email protected]>

* Updated codegen and API definitions

Signed-off-by: Shingo Omura <[email protected]>

* Fixed mgr.GetEventRecorderFor() deprecation (replace with mgr.GetEventRecorder())

Signed-off-by: Shingo Omura <[email protected]>

---------

Signed-off-by: Shingo Omura <[email protected]>
2026-06-18 15:36:34 +00:00

60 lines
2.2 KiB
Go

/*
Copyright 2024 The Kubeflow authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package webhook
import (
"context"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
"github.com/kubeflow/spark-operator/v2/api/v1beta2"
operatorscheme "github.com/kubeflow/spark-operator/v2/pkg/scheme"
"github.com/kubeflow/spark-operator/v2/pkg/util"
)
// +kubebuilder:webhook:admissionReviewVersions=v1,failurePolicy=fail,groups=sparkoperator.k8s.io,matchPolicy=Exact,mutating=true,name=mutate-sparkapplication.sparkoperator.k8s.io,path=/mutate-sparkoperator-k8s-io-v1beta2-sparkapplication,reinvocationPolicy=Never,resources=sparkapplications,sideEffects=None,verbs=create;update,versions=v1beta2,webhookVersions=v1
// SparkApplicationDefaulter sets default values for a SparkApplication.
type SparkApplicationDefaulter struct{}
// NewSparkApplicationDefaulter creates a new SparkApplicationDefaulter instance.
func NewSparkApplicationDefaulter() *SparkApplicationDefaulter {
return &SparkApplicationDefaulter{}
}
// SparkApplicationDefaulter implements admission.CustomDefaulter.
var _ admission.Defaulter[*v1beta2.SparkApplication] = &SparkApplicationDefaulter{}
// Default implements admission.CustomDefaulter.
func (d *SparkApplicationDefaulter) Default(ctx context.Context, app *v1beta2.SparkApplication) error {
if app == nil {
return nil
}
// Only set the default values for spark applications with new state or invalidating state.
state := util.GetApplicationState(app)
if state != v1beta2.ApplicationStateNew && state != v1beta2.ApplicationStateInvalidating {
return nil
}
logger := log.FromContext(ctx)
logger.Info("Mutating SparkApplication", "state", util.GetApplicationState(app))
operatorscheme.WebhookScheme.Default(app)
return nil
}