Skip to content

Commit

Permalink
feature: 过滤掉不合规范的labels #351
Browse files Browse the repository at this point in the history
  • Loading branch information
zmberg committed Feb 11, 2020
1 parent 3bc3918 commit b929791
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions bcs-mesos/bcs-scheduler/src/manager/store/etcd/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit b929791

Please sign in to comment.