diff --git a/worker/appm/controller/upgrade.go b/worker/appm/controller/upgrade.go index 65cb3e59c3..1440c8efe9 100644 --- a/worker/appm/controller/upgrade.go +++ b/worker/appm/controller/upgrade.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" + k8sErrors "k8s.io/apimachinery/pkg/api/errors" ) type upgradeController struct { @@ -74,7 +75,27 @@ func (s *upgradeController) upgradeOne(app v1.AppService) error { return fmt.Errorf("create or check namespace failure %s", err.Error()) } } - + if configs := app.GetConfigMaps(); configs != nil { + for _, config := range configs { + _, err := s.manager.client.CoreV1().ConfigMaps(config.Namespace).Update(config) + if err != nil { + app.Logger.Error(fmt.Sprintf("upgrade service %s failure %s", app.ServiceAlias, err.Error()), getLoggerOption("failure")) + logrus.Errorf("upgrade service %s failure %s", app.ServiceAlias, err.Error()) + } + if err != nil { + if k8sErrors.IsNotFound(err) { + _, err := s.manager.client.CoreV1().ConfigMaps(config.Namespace).Create(config) + if err != nil { + app.Logger.Error(fmt.Sprintf("error creating configmap %+v: %v", config, err), getLoggerOption("failure")) + logrus.Warningf("error creating configmap %+v: %v", config, err) + } + } else { + logrus.Warningf("error updating configmap %+v: %v", config, err) + app.Logger.Error(fmt.Sprintf("error updating configmap %+v: %v", config, err), getLoggerOption("failure")) + } + } + } + } if deployment := app.GetDeployment(); deployment != nil { _, err := s.manager.client.AppsV1().Deployments(deployment.Namespace).Patch(deployment.Name, types.MergePatchType, app.UpgradePatch["deployment"]) if err != nil { @@ -108,15 +129,6 @@ func (s *upgradeController) upgradeOne(app v1.AppService) error { } } } - if configs := app.GetConfigMaps(); configs != nil { - for _, config := range configs { - _, err := s.manager.client.CoreV1().ConfigMaps(config.Namespace).Update(config) - if err != nil { - app.Logger.Error(fmt.Sprintf("upgrade service %s failure %s", app.ServiceAlias, err.Error()), getLoggerOption("failure")) - logrus.Errorf("upgrade service %s failure %s", app.ServiceAlias, err.Error()) - } - } - } if secrets := app.GetSecrets(); secrets != nil { for _, secret := range secrets { _, err := s.manager.client.CoreV1().Secrets(secret.Namespace).Update(secret) diff --git a/worker/appm/conversion/version.go b/worker/appm/conversion/version.go index b90e4e7165..af8cb0519c 100644 --- a/worker/appm/conversion/version.go +++ b/worker/appm/conversion/version.go @@ -353,12 +353,9 @@ func createVolumes(as *v1.AppService, version *dbmodel.VersionInfo, dbmanager db logrus.Errorf("error getting config file by volume name(%s): %v", v.VolumeName, err) return nil, fmt.Errorf("error getting config file by volume name(%s): %v", v.VolumeName, err) } - name := fmt.Sprintf("manual%s%s", as.ServiceID, v.VolumePath) - name = strings.Replace(name, "/", "slash", -1) - name = strings.Replace(name, ".", "dot", -1) cmap = &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: name, + Name: util.NewUUID(), Namespace: as.TenantID, Labels: as.GetCommonLabels(), }, @@ -411,12 +408,9 @@ func createVolumes(as *v1.AppService, version *dbmodel.VersionInfo, dbmanager db return nil, fmt.Errorf("error getting TenantServiceConfigFileDao according to volumeName(%s): %v", t.VolumeName, err) } - name := fmt.Sprintf("manual%s%s", as.ServiceID, t.VolumePath) - name = strings.Replace(name, "/", "slash", -1) - name = strings.Replace(name, ".", "dot", -1) cmap := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: name, + Name: util.NewUUID(), Namespace: as.TenantID, Labels: as.GetCommonLabels(), }, diff --git a/worker/appm/store/store.go b/worker/appm/store/store.go index 9d8291b6ce..ffb96e9b40 100644 --- a/worker/appm/store/store.go +++ b/worker/appm/store/store.go @@ -577,7 +577,6 @@ func (a *appRuntimeStore) GetAppServiceStatus(serviceID string) string { func (a *appRuntimeStore) GetAppServicesStatus(serviceIDs []string) map[string]string { statusMap := make(map[string]string, len(serviceIDs)) if serviceIDs == nil || len(serviceIDs) == 0 { - logrus.Debugf("get all services status, number of all services is %d", a.appCount) a.appServices.Range(func(k, v interface{}) bool { appService, _ := v.(*v1.AppService) statusMap[appService.ServiceID] = a.GetAppServiceStatus(appService.ServiceID) diff --git a/worker/appm/types/v1/patch.go b/worker/appm/types/v1/patch.go index b834c8b5aa..8f13758c83 100644 --- a/worker/appm/types/v1/patch.go +++ b/worker/appm/types/v1/patch.go @@ -50,6 +50,9 @@ func (a *AppService) SetUpgradePatch(new *AppService) error { } a.UpgradePatch["deployment"] = deploymentPatch } + if new.configMaps != nil && len(new.configMaps) > 0 { + a.configMaps = new.configMaps + } return nil }