Skip to content

Commit

Permalink
fix: WorkloadSpread feature judgment (#1566)
Browse files Browse the repository at this point in the history
Signed-off-by: acejilam <[email protected]>
  • Loading branch information
ls-2018 authored Apr 23, 2024
1 parent 2da1b90 commit 36cc7d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pkg/controller/workloadspread/workloadspread_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"flag"
"fmt"

"math"
"strings"
"time"
Expand All @@ -47,11 +48,13 @@ import (

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
ctrlUtil "github.com/openkruise/kruise/pkg/controller/util"
"github.com/openkruise/kruise/pkg/features"
"github.com/openkruise/kruise/pkg/util"
utilclient "github.com/openkruise/kruise/pkg/util/client"
"github.com/openkruise/kruise/pkg/util/configuration"
"github.com/openkruise/kruise/pkg/util/controllerfinder"
utildiscovery "github.com/openkruise/kruise/pkg/util/discovery"
utilfeature "github.com/openkruise/kruise/pkg/util/feature"
"github.com/openkruise/kruise/pkg/util/fieldindex"
"github.com/openkruise/kruise/pkg/util/ratelimiter"
"github.com/openkruise/kruise/pkg/util/requeueduration"
Expand Down Expand Up @@ -102,7 +105,7 @@ var durationStore = requeueduration.DurationStore{}
// Add creates a new WorkloadSpread Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(mgr manager.Manager) error {
if !utildiscovery.DiscoverGVK(controllerKruiseKindWS) {
if !utildiscovery.DiscoverGVK(controllerKruiseKindWS) || !utilfeature.DefaultFeatureGate.Enabled(features.WorkloadSpread) {
return nil
}
return add(mgr, newReconciler(mgr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package validating

import (
"context"
"fmt"
"net/http"

admissionv1 "k8s.io/api/admission/v1"
Expand All @@ -26,6 +27,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/features"
utilfeature "github.com/openkruise/kruise/pkg/util/feature"
)

// WorkloadSpreadCreateUpdateHandler handles WorkloadSpread
Expand All @@ -46,7 +49,9 @@ var _ admission.Handler = &WorkloadSpreadCreateUpdateHandler{}
func (h *WorkloadSpreadCreateUpdateHandler) Handle(ctx context.Context, req admission.Request) admission.Response {
obj := &appsv1alpha1.WorkloadSpread{}
oldObj := &appsv1alpha1.WorkloadSpread{}

if !utilfeature.DefaultFeatureGate.Enabled(features.WorkloadSpread) {
return admission.Errored(http.StatusForbidden, fmt.Errorf("feature-gate %s is not enabled", features.WorkloadSpread))
}
switch req.AdmissionRequest.Operation {
case admissionv1.Create:
if err := h.Decoder.Decode(req, obj); err != nil {
Expand Down

0 comments on commit 36cc7d8

Please sign in to comment.