Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: WorkloadSpread feature judgment #1566

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"encoding/json"
"flag"
"fmt"

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

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 @@
// 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) {

Check warning on line 108 in pkg/controller/workloadspread/workloadspread_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/workloadspread/workloadspread_controller.go#L108

Added line #L108 was not covered by tests
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 @@

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

admissionv1 "k8s.io/api/admission/v1"
Expand All @@ -26,6 +27,8 @@
"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 @@
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))

Check warning on line 53 in pkg/webhook/workloadspread/validating/workloadspread_create_update_handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/workloadspread/validating/workloadspread_create_update_handler.go#L52-L53

Added lines #L52 - L53 were not covered by tests
}
switch req.AdmissionRequest.Operation {
case admissionv1.Create:
if err := h.Decoder.Decode(req, obj); err != nil {
Expand Down
Loading