diff --git a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/application.go b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/application.go index 27bb0bfae6..b9f31992a8 100644 --- a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/application.go +++ b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/application.go @@ -95,7 +95,7 @@ func (store *managerStore) SaveApplication(application *types.Application) error ObjectMeta: metav1.ObjectMeta{ Name: application.ID, Namespace: application.RunAs, - Labels: application.ObjectMeta.Labels, + Labels: store.filterSpecialLabels(application.ObjectMeta.Labels), Annotations: application.ObjectMeta.Annotations, }, Spec: v2.ApplicationSpec{ diff --git a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/configmap.go b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/configmap.go index b06cbb0544..c83841f244 100644 --- a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/configmap.go +++ b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/configmap.go @@ -45,7 +45,7 @@ func (store *managerStore) SaveConfigMap(configmap *commtypes.BcsConfigMap) erro ObjectMeta: metav1.ObjectMeta{ Name: configmap.Name, Namespace: configmap.NameSpace, - Labels: configmap.Labels, + Labels: store.filterSpecialLabels(configmap.Labels), Annotations: configmap.Annotations, }, Spec: v2.BcsConfigMapSpec{ diff --git a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/deployment.go b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/deployment.go index 1481b3cc64..762b33dc3f 100644 --- a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/deployment.go +++ b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/deployment.go @@ -95,7 +95,7 @@ func (store *managerStore) SaveDeployment(deployment *types.Deployment) error { ObjectMeta: metav1.ObjectMeta{ Name: deployment.ObjectMeta.Name, Namespace: deployment.ObjectMeta.NameSpace, - Labels: deployment.ObjectMeta.Labels, + Labels: store.filterSpecialLabels(deployment.ObjectMeta.Labels), Annotations: deployment.ObjectMeta.Annotations, }, Spec: v2.DeploymentSpec{ diff --git a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/endpoint.go b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/endpoint.go index 0327749f7c..f3d2cb8d06 100644 --- a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/endpoint.go +++ b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/endpoint.go @@ -45,7 +45,7 @@ func (store *managerStore) SaveEndpoint(endpoint *commtypes.BcsEndpoint) error { ObjectMeta: metav1.ObjectMeta{ Name: endpoint.Name, Namespace: endpoint.NameSpace, - Labels: endpoint.Labels, + Labels: store.filterSpecialLabels(endpoint.Labels), Annotations: endpoint.Annotations, }, Spec: v2.BcsEndpointSpec{ diff --git a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/secret.go b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/secret.go index 25aa01e9b3..d66e4219cf 100644 --- a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/secret.go +++ b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/secret.go @@ -45,7 +45,7 @@ func (store *managerStore) SaveSecret(secret *commtypes.BcsSecret) error { ObjectMeta: metav1.ObjectMeta{ Name: secret.Name, Namespace: secret.NameSpace, - Labels: secret.Labels, + Labels: store.filterSpecialLabels(secret.Labels), Annotations: secret.Annotations, }, Spec: v2.BcsSecretSpec{ diff --git a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/service.go b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/service.go index f85556ec3c..49244857c8 100644 --- a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/service.go +++ b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/service.go @@ -45,7 +45,7 @@ func (store *managerStore) SaveService(service *commtypes.BcsService) error { ObjectMeta: metav1.ObjectMeta{ Name: service.Name, Namespace: service.NameSpace, - Labels: service.Labels, + Labels: store.filterSpecialLabels(service.Labels), Annotations: service.Annotations, }, Spec: v2.BcsServiceSpec{ 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 0ab715c204..90d3fdb62f 100644 --- a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/store.go +++ b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/store.go @@ -16,6 +16,7 @@ package etcd import ( "context" "fmt" + "regexp" "strings" "sync" "time" @@ -336,3 +337,23 @@ func (store *managerStore) ListDeploymentRunAs() ([]string, error) { return store.ListRunAs() } + +func (store *managerStore) filterSpecialLabels(oriLabels map[string]string) map[string]string { + 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) { + continue + } + if !regvalue.MatchString(v) { + continue + } + + labels[k] = v + } + return labels +} \ No newline at end of file diff --git a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/taskgroup.go b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/taskgroup.go index 0b907d433d..35a860a605 100644 --- a/bcs-mesos/bcs-scheduler/src/manager/store/etcd/taskgroup.go +++ b/bcs-mesos/bcs-scheduler/src/manager/store/etcd/taskgroup.go @@ -42,7 +42,7 @@ func (store *managerStore) SaveTaskGroup(taskGroup *types.TaskGroup) error { ObjectMeta: metav1.ObjectMeta{ Name: taskGroup.ID, Namespace: taskGroup.RunAs, - Labels: taskGroup.ObjectMeta.Labels, + Labels: store.filterSpecialLabels(taskGroup.ObjectMeta.Labels), Annotations: taskGroup.ObjectMeta.Annotations, }, Spec: v2.TaskGroupSpec{