diff --git a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/store.go b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/store.go index d45f24cac3..5ec607b461 100644 --- a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/store.go +++ b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/store.go @@ -71,6 +71,9 @@ type managerStore struct { k8sClient *kubernetes.Clientset extensionClient *extensionClientset.Clientset + regkey *regexp.Regexp + regvalue *regexp.Regexp + wg sync.WaitGroup ctx context.Context cancel context.CancelFunc @@ -269,6 +272,10 @@ func NewEtcdStore(kubeconfig string) (store.Store, error) { extensionClient: extensionClient, } + //init object labels regexp + m.regkey, _ = regexp.Compile("^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$") + m.regvalue, _ = regexp.Compile("^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$") + //init clientset crds err = m.initKubeCrd() if err != nil { @@ -342,14 +349,13 @@ func (store *managerStore) filterSpecialLabels(oriLabels map[string]string) map[ if oriLabels == nil { return nil } - regkey, _ := regexp.Compile("^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$") - regvalue, _ := regexp.Compile("^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$") + labels := make(map[string]string) for k, v := range oriLabels { - if !regkey.MatchString(k) { + if !store.regkey.MatchString(k) { continue } - if !regvalue.MatchString(v) { + if !store.regvalue.MatchString(v) { continue }