Skip to content

Commit

Permalink
Optimize performance of LabelSelector conversion
Browse files Browse the repository at this point in the history
Signed-off-by: FillZpp <FillZpp.pub@gmail.com>
  • Loading branch information
FillZpp committed Aug 29, 2022
1 parent c25a7f0 commit 11b68f6
Show file tree
Hide file tree
Showing 30 changed files with 192 additions and 51 deletions.
4 changes: 2 additions & 2 deletions pkg/control/pubcontrol/pub_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func (c *commonControl) GetPodsForPub(pub *policyv1alpha1.PodUnavailableBudget)
return nil, 0, nil
}
// get pods for selector
labelSelector, err := util.GetFastLabelSelector(pub.Spec.Selector)
labelSelector, err := util.ValidatedLabelSelectorAsSelector(pub.Spec.Selector)
if err != nil {
klog.Warningf("pub(%s/%s) GetFastLabelSelector failed: %s", pub.Namespace, pub.Name, err.Error())
klog.Warningf("pub(%s/%s) ValidatedLabelSelectorAsSelector failed: %s", pub.Namespace, pub.Name, err.Error())
return nil, 0, nil
}
listOptions = &client.ListOptions{Namespace: pub.Namespace, LabelSelector: labelSelector}
Expand Down
2 changes: 1 addition & 1 deletion pkg/control/sidecarcontrol/history_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (r *realControl) GetRevisionSelector(s *appsv1alpha1.SidecarSet) labels.Sel
SidecarSetKindName: s.GetName(),
},
}
selector, err := util.GetFastLabelSelector(labelSelector)
selector, err := util.ValidatedLabelSelectorAsSelector(labelSelector)
if err != nil {
// static error, just panic
panic("Incorrect label selector for ControllerRevision of SidecarSet.")
Expand Down
4 changes: 2 additions & 2 deletions pkg/control/sidecarcontrol/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func PodMatchedSidecarSet(pod *corev1.Pod, sidecarSet appsv1alpha1.SidecarSet) (
return false, nil
}
// if selector not matched, then continue
selector, err := metav1.LabelSelectorAsSelector(sidecarSet.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(sidecarSet.Spec.Selector)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -471,7 +471,7 @@ func ValidateSidecarSetPatchMetadataWhitelist(c client.Client, sidecarSet *appsv

for _, rule := range whitelist.Rules {
if rule.Selector != nil {
selector, err := util.GetFastLabelSelector(rule.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(rule.Selector)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/cloneset/cloneset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
synccontrol "github.com/openkruise/kruise/pkg/controller/cloneset/sync"
clonesetutils "github.com/openkruise/kruise/pkg/controller/cloneset/utils"
"github.com/openkruise/kruise/pkg/features"
"github.com/openkruise/kruise/pkg/util"
utilclient "github.com/openkruise/kruise/pkg/util/client"
utildiscovery "github.com/openkruise/kruise/pkg/util/discovery"
"github.com/openkruise/kruise/pkg/util/expectations"
Expand Down Expand Up @@ -214,7 +215,7 @@ func (r *ReconcileCloneSet) doReconcile(request reconcile.Request) (res reconcil
return reconcile.Result{}, nil
}

selector, err := metav1.LabelSelectorAsSelector(instance.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(instance.Spec.Selector)
if err != nil {
klog.Errorf("Error converting CloneSet %s selector: %v", request, err)
// This is a non-transient error, so don't retry.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/daemonset/daemonset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (dsc *ReconcileDaemonSet) Reconcile(ctx context.Context, request reconcile.
// Note that returned Pods are pointers to objects in the cache.
// If you want to modify one, you need to deep-copy it first.
func (dsc *ReconcileDaemonSet) getDaemonPods(ds *appsv1alpha1.DaemonSet) ([]*corev1.Pod, error) {
selector, err := metav1.LabelSelectorAsSelector(ds.Spec.Selector)
selector, err := kruiseutil.ValidatedLabelSelectorAsSelector(ds.Spec.Selector)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/daemonset/daemonset_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

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

var _ handler.EventHandler = &podEventHandler{}
Expand Down Expand Up @@ -211,7 +212,7 @@ func (e *podEventHandler) getPodDaemonSets(pod *v1.Pod) []*appsv1alpha1.DaemonSe
var dsMatched []*appsv1alpha1.DaemonSet
for i := range dsList.Items {
ds := &dsList.Items[i]
selector, err := metav1.LabelSelectorAsSelector(ds.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(ds.Spec.Selector)
if err != nil || selector.Empty() || !selector.Matches(labels.Set(pod.Labels)) {
continue
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/daemonset/daemonset_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"reflect"

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/util"
apps "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -96,7 +97,7 @@ func (dsc *ReconcileDaemonSet) constructHistory(ds *appsv1alpha1.DaemonSet) (cur
// Note that returned histories are pointers to objects in the cache.
// If you want to modify one, you need to deep-copy it first.
func (dsc *ReconcileDaemonSet) controlledHistories(ds *appsv1alpha1.DaemonSet) ([]*apps.ControllerRevision, error) {
selector, err := metav1.LabelSelectorAsSelector(ds.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(ds.Spec.Selector)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/daemonset/daemonset_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
clonesetutils "github.com/openkruise/kruise/pkg/controller/cloneset/utils"
"github.com/openkruise/kruise/pkg/util"
"github.com/openkruise/kruise/pkg/util/inplaceupdate"
apps "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -306,7 +307,7 @@ func (dsc *ReconcileDaemonSet) filterDaemonPodsNodeToUpdate(ds *appsv1alpha1.Dae
partition = *ds.Spec.UpdateStrategy.RollingUpdate.Partition
}
if ds.Spec.UpdateStrategy.RollingUpdate != nil && ds.Spec.UpdateStrategy.RollingUpdate.Selector != nil {
if selector, err = metav1.LabelSelectorAsSelector(ds.Spec.UpdateStrategy.RollingUpdate.Selector); err != nil {
if selector, err = util.ValidatedLabelSelectorAsSelector(ds.Spec.UpdateStrategy.RollingUpdate.Selector); err != nil {
return nil, err
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/daemonset/daemonset_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

appspub "github.com/openkruise/kruise/apis/apps/pub"
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
kruiseutil "github.com/openkruise/kruise/pkg/util"
"github.com/openkruise/kruise/pkg/util/inplaceupdate"
"github.com/openkruise/kruise/pkg/util/lifecycle"

Expand Down Expand Up @@ -156,7 +157,7 @@ func (dsc *ReconcileDaemonSet) GetPodDaemonSets(pod *corev1.Pod) ([]*appsv1alpha
var selector labels.Selector
var daemonSets []*appsv1alpha1.DaemonSet
for _, ds := range dsList {
selector, err = metav1.LabelSelectorAsSelector(ds.Spec.Selector)
selector, err = kruiseutil.ValidatedLabelSelectorAsSelector(ds.Spec.Selector)
if err != nil {
// this should not happen if the DaemonSet passed validation
return nil, err
Expand Down Expand Up @@ -343,7 +344,7 @@ func NodeShouldUpdateBySelector(node *corev1.Node, ds *appsv1alpha1.DaemonSet) b
if ds.Spec.UpdateStrategy.RollingUpdate == nil || ds.Spec.UpdateStrategy.RollingUpdate.Selector == nil {
return false
}
selector, err := metav1.LabelSelectorAsSelector(ds.Spec.UpdateStrategy.RollingUpdate.Selector)
selector, err := kruiseutil.ValidatedLabelSelectorAsSelector(ds.Spec.UpdateStrategy.RollingUpdate.Selector)
if err != nil {
// this should not happen if the DaemonSet passed validation
return false
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/ephemeraljob/ephemeraljob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (r *ReconcileEphemeralJob) Reconcile(context context.Context, request recon
}

func (r *ReconcileEphemeralJob) filterPods(job *appsv1alpha1.EphemeralJob) ([]*v1.Pod, error) {
selector, err := util.GetFastLabelSelector(job.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(job.Spec.Selector)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func (r *ReconcileEphemeralJob) filterPods(job *appsv1alpha1.EphemeralJob) ([]*v

// filterInjectedPods will return pods which has injected ephemeral containers
func (r *ReconcileEphemeralJob) filterInjectedPods(job *appsv1alpha1.EphemeralJob) ([]*v1.Pod, error) {
selector, err := util.GetFastLabelSelector(job.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(job.Spec.Selector)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/ephemeraljob/ephemeraljob_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"fmt"
"time"

"k8s.io/klog/v2"

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/controller/ephemeraljob/econtainer"
"github.com/openkruise/kruise/pkg/util"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog/v2"
)

// pastActiveDeadline checks if job has ActiveDeadlineSeconds field set and if it is exceeded.
Expand All @@ -29,7 +29,7 @@ func podMatchedEphemeralJob(pod *v1.Pod, ejob *appsv1alpha1.EphemeralJob) (bool,
if pod.Namespace != ejob.Namespace {
return false, nil
}
selector, err := metav1.LabelSelectorAsSelector(ejob.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(ejob.Spec.Selector)
if err != nil {
return false, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (r *ReconcilePodUnavailableBudget) getPodsForPub(pub *policyv1alpha1.PodUna
return nil, nil
}
// get pods for selector
labelSelector, err := util.GetFastLabelSelector(pub.Spec.Selector)
labelSelector, err := util.ValidatedLabelSelectorAsSelector(pub.Spec.Selector)
if err != nil {
r.recorder.Eventf(pub, corev1.EventTypeWarning, "Selector", fmt.Sprintf("Label selector failed: %s", err.Error()))
return nil, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/podunavailablebudget/pub_pod_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func GetPubForPod(c client.Client, pod *corev1.Pod) (*policyv1alpha1.PodUnavaila
}
} else {
// This error is irreversible, so continue
labelSelector, err := util.GetFastLabelSelector(pub.Spec.Selector)
labelSelector, err := util.ValidatedLabelSelectorAsSelector(pub.Spec.Selector)
if err != nil {
continue
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func (e *SetEnqueueRequestForPUB) addSetRequest(object client.Object, q workqueu
}
} else {
// This error is irreversible, so continue
labelSelector, err := util.GetFastLabelSelector(pub.Spec.Selector)
labelSelector, err := util.ValidatedLabelSelectorAsSelector(pub.Spec.Selector)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/resourcedistribution/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func matchViaIncludedNamespaces(namespace *corev1.Namespace, distributor *appsv1

// matchViaLabelSelector return true if namespace matches with target.NamespacesLabelSelectors
func matchViaLabelSelector(namespace *corev1.Namespace, distributor *appsv1alpha1.ResourceDistribution) (bool, error) {
selector, err := metav1.LabelSelectorAsSelector(&distributor.Spec.Targets.NamespaceLabelSelector)
selector, err := util.ValidatedLabelSelectorAsSelector(&distributor.Spec.Targets.NamespaceLabelSelector)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func listNamespacesForDistributor(handlerClient client.Client, targets *appsv1al

if !targets.AllNamespaces && (len(targets.NamespaceLabelSelector.MatchLabels) != 0 || len(targets.NamespaceLabelSelector.MatchExpressions) != 0) {
// 3. select the namespaces via targets.NamespaceLabelSelector
selectors, err := util.GetFastLabelSelector(&targets.NamespaceLabelSelector)
selectors, err := util.ValidatedLabelSelectorAsSelector(&targets.NamespaceLabelSelector)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/sidecarset/sidecarset_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (p *Processor) updateSidecarSetStatus(sidecarSet *appsv1alpha1.SidecarSet,
// If you need update the pod object, you must DeepCopy it
func (p *Processor) getMatchingPods(s *appsv1alpha1.SidecarSet) ([]*corev1.Pod, error) {
// get more faster selector
selector, err := util.GetFastLabelSelector(s.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(s.Spec.Selector)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/sidecarset/sidecarset_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/control/sidecarcontrol"
"github.com/openkruise/kruise/pkg/util"
"github.com/openkruise/kruise/pkg/util/updatesort"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
intstrutil "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (p *spreadingStrategy) GetNextUpgradePods(control sidecarcontrol.SidecarCon
return true
}
// if selector failed, always return false
selector, err := metav1.LabelSelectorAsSelector(strategy.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(strategy.Selector)
if err != nil {
klog.Errorf("sidecarSet(%s) rolling selector error, err: %v", sidecarset.Name, err)
return false
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/statefulset/stateful_set_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
intstrutil "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
Expand All @@ -38,6 +37,7 @@ import (
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
appsv1beta1 "github.com/openkruise/kruise/apis/apps/v1beta1"
"github.com/openkruise/kruise/pkg/features"
"github.com/openkruise/kruise/pkg/util"
utilfeature "github.com/openkruise/kruise/pkg/util/feature"
imagejobutilfunc "github.com/openkruise/kruise/pkg/util/imagejob/utilfunction"
"github.com/openkruise/kruise/pkg/util/inplaceupdate"
Expand Down Expand Up @@ -161,7 +161,7 @@ func (ssc *defaultStatefulSetControl) performUpdate(
}

func (ssc *defaultStatefulSetControl) ListRevisions(set *appsv1beta1.StatefulSet) ([]*apps.ControllerRevision, error) {
selector, err := metav1.LabelSelectorAsSelector(set.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(set.Spec.Selector)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -306,7 +306,7 @@ func (ssc *defaultStatefulSetControl) updateStatefulSet(
collisionCount int32,
pods []*v1.Pod,
revisions []*apps.ControllerRevision) (*appsv1beta1.StatefulSetStatus, error) {
selector, err := metav1.LabelSelectorAsSelector(set.Spec.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(set.Spec.Selector)
if err != nil {
return set.Status.DeepCopy(), err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/workloadspread/workloadspread_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (r *ReconcileWorkloadSpread) getPodJob(ref *appsv1alpha1.TargetReference, n
return nil, -1, err
}

labelSelector, err := util.GetFastLabelSelector(job.Spec.Selector)
labelSelector, err := util.ValidatedLabelSelectorAsSelector(job.Spec.Selector)
if err != nil {
klog.Errorf("gets labelSelector failed: %s", err.Error())
return nil, -1, nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/controllerfinder/pods_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllerfinder
import (
"context"

"github.com/openkruise/kruise/pkg/util"
utilclient "github.com/openkruise/kruise/pkg/util/client"
"github.com/openkruise/kruise/pkg/util/fieldindex"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -113,7 +114,7 @@ func (r *ControllerFinder) getReplicaSetsForDeployment(apiVersion, kind, ns, nam
}
// List ReplicaSets owned by this Deployment
rsList := &appsv1.ReplicaSetList{}
selector, err := metav1.LabelSelectorAsSelector(scaleNSelector.Selector)
selector, err := util.ValidatedLabelSelectorAsSelector(scaleNSelector.Selector)
if err != nil {
klog.Errorf("Deployment (%s/%s) get labelSelector failed: %s", ns, name, err.Error())
return nil, nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/history/controller_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/util"
apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestRevisionHistory(t *testing.T) {
t.Fatalf("Expected ControllerRevision name %v, got %v", expectedName, newCR.Name)
}

selector, _ := metav1.LabelSelectorAsSelector(parent.Spec.Selector)
selector, _ := util.ValidatedLabelSelectorAsSelector(parent.Spec.Selector)
gotRevisions, err := historyControl.ListControllerRevisions(parent, selector)
if err != nil {
t.Fatalf("Failed to list revisions: %v", err)
Expand Down
10 changes: 5 additions & 5 deletions pkg/util/imagejob/imagejob_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func GetNodeImagesForJob(reader client.Reader, job *appsv1alpha1.ImagePullJob) (
}()

if job.Spec.PodSelector != nil {
selector, err := util.GetFastLabelSelector(&job.Spec.PodSelector.LabelSelector)
selector, err := util.ValidatedLabelSelectorAsSelector(&job.Spec.PodSelector.LabelSelector)
if err != nil {
return nil, fmt.Errorf("parse podSelector error: %v", err)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func GetNodeImagesForJob(reader client.Reader, job *appsv1alpha1.ImagePullJob) (
return nodeImages, nil
}

selector, err := util.GetFastLabelSelector(&job.Spec.Selector.LabelSelector)
selector, err := util.ValidatedLabelSelectorAsSelector(&job.Spec.Selector.LabelSelector)
if err != nil {
return nil, fmt.Errorf("parse selector error: %v", err)
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func GetActiveJobsForNodeImage(reader client.Reader, nodeImage, oldNodeImage *ap
var oldMatched bool

if job.Spec.PodSelector != nil {
selector, err := util.GetFastLabelSelector(&job.Spec.PodSelector.LabelSelector)
selector, err := util.ValidatedLabelSelectorAsSelector(&job.Spec.PodSelector.LabelSelector)
if err != nil {
return nil, nil, fmt.Errorf("parse podSelector for %s/%s error: %v", job.Namespace, job.Name, err)
}
Expand All @@ -198,7 +198,7 @@ func GetActiveJobsForNodeImage(reader client.Reader, nodeImage, oldNodeImage *ap
oldMatched = true
}
} else {
selector, err := util.GetFastLabelSelector(&job.Spec.Selector.LabelSelector)
selector, err := util.ValidatedLabelSelectorAsSelector(&job.Spec.Selector.LabelSelector)
if err != nil {
return nil, nil, fmt.Errorf("parse selector for %s/%s error: %v", job.Namespace, job.Name, err)
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func GetActiveJobsForPod(reader client.Reader, pod, oldPod *v1.Pod) (newJobs, ol
job := &jobList.Items[i]

if job.Spec.PodSelector != nil {
selector, err := util.GetFastLabelSelector(&job.Spec.PodSelector.LabelSelector)
selector, err := util.ValidatedLabelSelectorAsSelector(&job.Spec.PodSelector.LabelSelector)
if err != nil {
return nil, nil, fmt.Errorf("parse podSelector for %s/%s error: %v", job.Namespace, job.Name, err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/refmanager/ref_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"reflect"
"sync"

"github.com/openkruise/kruise/pkg/util"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -47,7 +48,7 @@ type RefManager struct {
// New returns a RefManager that exposes
// methods to manage the controllerRef of pods.
func New(client client.Client, selector *metav1.LabelSelector, owner metav1.Object, schema *runtime.Scheme) (*RefManager, error) {
s, err := metav1.LabelSelectorAsSelector(selector)
s, err := util.ValidatedLabelSelectorAsSelector(selector)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 11b68f6

Please sign in to comment.