Merge branch 'V3.7' of https://github.com/goodrain/rainbond into V3.7

This commit is contained in:
barnettZQG 2018-10-13 13:12:58 +08:00
commit 74107558f9
5 changed files with 105 additions and 3 deletions

View File

@ -149,7 +149,6 @@ func (c *NotificationEventDaoImpl) AddModel(mo model.Interface) error {
return err
}
} else {
logrus.Infoln("event result is exist")
return c.UpdateModel(mo)
}
return nil

View File

@ -102,8 +102,8 @@ func NewManager(conf option.Config, statusManager *client.AppRuntimeSyncClient)
}
cacheManager := NewCacheManager()
return &manager{kubeclient: clientset, conf: conf,
dbmanager: db.GetManager(),
statusCache: cacheManager,
dbmanager: db.GetManager(),
statusCache: cacheManager,
statusManager: statusManager,
}, nil
}
@ -266,3 +266,26 @@ func (m *manager) SyncData() {
//step2 :同步tenant_service_pod
//TODO:
}
func DeletePods(m *manager, service *model.TenantServices, logger event.Logger) error {
podList, err := m.kubeclient.Pods(service.ServiceID).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("name=%s,creator=%s,version=%s", service.ServiceAlias, "RainBond", service.DeployVersion)})
if err != nil {
if err = checkNotFoundError(err); err != nil {
logrus.Error("get service pods error.", err.Error())
logger.Error("从集群中查询该应用的pod失败", map[string]string{"step": "worker-appm", "status": "error"})
return err
}
}
for _, v := range podList.Items {
err := m.kubeclient.Pods(service.ServiceID).Delete(v.Name, &metav1.DeleteOptions{});
if err != nil {
if err = checkNotFoundError(err); err != nil {
logrus.Error("delete service pod error.", err.Error())
logger.Error("从集群中删除应用的pod失败", map[string]string{"step": "worker-appm", "status": "error"})
}
}
}
logger.Info("根据资源标签移除残留的pod资源完成", map[string]string{"step": "worker-appm", "status": "starting"})
return nil
}

View File

@ -195,6 +195,33 @@ func (m *manager) StopDeployment(serviceID string, logger event.Logger) error {
}
}
}
//清理集群内可能遗留的资源
deletePodsErr := DeletePods(m, service, logger);
if deletePodsErr != nil {
return deletePodsErr
}
rcList, err := m.kubeclient.AppsV1beta1().Deployments(service.ServiceID).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("name=%s,creator=%s,version=%s", service.ServiceAlias, "RainBond", service.DeployVersion)})
if err != nil {
if err = checkNotFoundError(err); err != nil {
logrus.Error("get service Deployments error.", err.Error())
logger.Error("从集群中查询该应用的Deployments失败", map[string]string{"step": "worker-appm", "status": "error"})
return err
}
}
for _, v := range rcList.Items {
err := m.kubeclient.AppsV1beta1().Deployments(service.ServiceID).Delete(v.Name, &metav1.DeleteOptions{});
if err != nil {
if err = checkNotFoundError(err); err != nil {
logrus.Error("delete service Deployments error.", err.Error())
logger.Error("从集群中删除应用的Deployments失败", map[string]string{"step": "worker-appm", "status": "error"})
return err
}
}
}
logger.Info("根据资源标签移除残留的Deployments资源完成", map[string]string{"step": "worker-appm", "status": "starting"})
return nil
}

View File

@ -207,6 +207,32 @@ func (m *manager) StopReplicationController(serviceID string, logger event.Logge
}
}
logger.Info("移除残留的Pod实例完成", map[string]string{"step": "worker-appm", "status": "starting"})
//清理集群内可能遗留的资源
deletePodsErr := DeletePods(m, service, logger);
if deletePodsErr != nil {
return deletePodsErr
}
rcList, err := m.kubeclient.ReplicationControllers(service.ServiceID).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("name=%s,creator=%s,version=%s", service.ServiceAlias, "RainBond", service.DeployVersion)})
if err != nil {
if err = checkNotFoundError(err); err != nil {
logrus.Error("get service ReplicationController error.", err.Error())
logger.Error("从集群中查询该应用的ReplicationController失败", map[string]string{"step": "worker-appm", "status": "error"})
return err
}
}
for _, v := range rcList.Items {
err := m.kubeclient.ReplicationControllers(service.ServiceID).Delete(v.Name, &metav1.DeleteOptions{});
if err != nil {
if err = checkNotFoundError(err); err != nil {
logrus.Error("delete service ReplicationController error.", err.Error())
logger.Error("从集群中删除应用的ReplicationController失败", map[string]string{"step": "worker-appm", "status": "error"})
return err
}
}
}
logger.Info("根据资源标签移除残留的rc资源完成", map[string]string{"step": "worker-appm", "status": "starting"})
return nil
}

View File

@ -204,6 +204,33 @@ func (m *manager) StopStatefulSet(serviceID string, logger event.Logger) error {
}
}
}
//清理集群内可能遗留的资源
deletePodsErr := DeletePods(m, service, logger);
if deletePodsErr != nil {
return deletePodsErr
}
rcList, err := m.kubeclient.AppsV1beta1().StatefulSets(service.ServiceID).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("name=%s,creator=%s,version=%s", service.ServiceAlias, "RainBond", service.DeployVersion)})
if err != nil {
if err = checkNotFoundError(err); err != nil {
logrus.Error("get service StatefulSets error.", err.Error())
logger.Error("从集群中查询该应用的StatefulSets失败", map[string]string{"step": "worker-appm", "status": "error"})
return err
}
}
for _, v := range rcList.Items {
err := m.kubeclient.AppsV1beta1().StatefulSets(service.ServiceID).Delete(v.Name, &metav1.DeleteOptions{});
if err != nil {
if err = checkNotFoundError(err); err != nil {
logrus.Error("delete service StatefulSets error.", err.Error())
logger.Error("从集群中删除应用的StatefulSets失败", map[string]string{"step": "worker-appm", "status": "error"})
return err
}
}
}
logger.Info("根据资源标签移除残留的StatefulSets资源完成", map[string]string{"step": "worker-appm", "status": "starting"})
return nil
}