[REV] change get common labels method

This commit is contained in:
barnett 2018-11-19 14:16:21 +08:00
parent b98e089c83
commit 55fa1801f0
3 changed files with 14 additions and 17 deletions

View File

@ -134,11 +134,9 @@ func initBaseStatefulSet(as *v1.AppService, service *dbmodel.TenantServices) {
stateful.Namespace = service.TenantID
stateful.Name = service.ServiceAlias
stateful.GenerateName = service.ServiceAlias
stateful.Labels = getCommonLable(stateful.Labels, map[string]string{
"name": service.ServiceAlias,
"version": service.DeployVersion,
"service_id": service.ServiceID,
"creater_id": as.CreaterID,
stateful.Labels = as.GetCommonLables(stateful.Labels, map[string]string{
"name": service.ServiceAlias,
"version": service.DeployVersion,
})
as.SetStatefulSet(stateful)
}
@ -157,11 +155,9 @@ func initBaseDeployment(as *v1.AppService, service *dbmodel.TenantServices) {
deployment.Namespace = service.TenantID
deployment.Name = util.NewUUID()
deployment.GenerateName = strings.Replace(service.ServiceAlias, "_", "-", -1)
deployment.Labels = getCommonLable(deployment.Labels, map[string]string{
"name": service.ServiceAlias,
"version": service.DeployVersion,
"service_id": service.ServiceID,
"creater_id": as.CreaterID,
deployment.Labels = as.GetCommonLables(deployment.Labels, map[string]string{
"name": service.ServiceAlias,
"version": service.DeployVersion,
})
as.SetDeployment(deployment)
}

View File

@ -56,11 +56,9 @@ func TenantServiceVersion(as *v1.AppService, dbmanager db.Manager) error {
}
podtmpSpec := corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: getCommonLable(map[string]string{
"name": as.ServiceAlias,
"version": as.DeployVersion,
"service_id": as.ServiceID,
"creater_id": as.CreaterID,
Labels: as.GetCommonLables(map[string]string{
"name": as.ServiceAlias,
"version": as.DeployVersion,
}),
Annotations: createPodAnnotations(as),
},

View File

@ -16,9 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package conversion
package v1
func getCommonLable(labels ...map[string]string) map[string]string {
//GetCommonLables get common lables
func (a *AppService) GetCommonLables(labels ...map[string]string) map[string]string {
var resultLabel = make(map[string]string)
for _, l := range labels {
for k, v := range l {
@ -26,5 +27,7 @@ func getCommonLable(labels ...map[string]string) map[string]string {
}
}
resultLabel["creater"] = "Rainbond"
resultLabel["creater_id"] = a.CreaterID
resultLabel["service_id"] = a.ServiceID
return resultLabel
}