Skip to content

Commit

Permalink
Merge pull request #191 from GLYASAI/V5.0
Browse files Browse the repository at this point in the history
[FIX] deploment has no configmap while updating
  • Loading branch information
barnettZQG authored Jan 11, 2019
2 parents b053a10 + 730d962 commit e4756dd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
32 changes: 22 additions & 10 deletions worker/appm/controller/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions worker/appm/conversion/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down Expand Up @@ -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(),
},
Expand Down
1 change: 0 additions & 1 deletion worker/appm/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions worker/appm/types/v1/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit e4756dd

Please sign in to comment.