Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 发布etcd配置添加MySQL记录 #436

Merged
merged 2 commits into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions internal/pkg/service/confgov2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,21 +750,36 @@ func assemblyJunoAgent(nodes []db.AppNode) []view.JunoAgent {
}

func PublishAllConfig() (err error) {
step := ""
defer func() {
if err != nil {
xlog.Error("PublishAllConfig", zap.Error(err), zap.String("step", step))
}
}()
var configuration []db.Configuration
// todo split page
query := mysql.Where("id > 0").Order("id desc").Limit(1000).Find(&configuration)
if query.Error != nil {
step = "query.Error"
return
}
settings, err := system.System.Setting.GetAll()
clusterList := view.ClusterList{}
for _, item := range configuration {
if step != "" {
xlog.Error("PublishAllConfig.detail", zap.String("step", step))
}
var confHistory db.ConfigurationHistory
query = mysql.Where("configuration_id= ?", item.ID).Order("id desc").First(&confHistory)
if query.Error != nil {
err = query.Error
step = "confHistory.query.Error"
continue
}
var appInfo db.AppInfo
appInfo, err = resource.Resource.GetApp(item.AID)
if err != nil {
step = "resource.Resource.GetApp"
continue
}
// Save the configuration in etcd
Expand All @@ -780,8 +795,37 @@ func PublishAllConfig() (err error) {
Version: confHistory.Version,
PubK8S: true,
}); err != nil {
step = "publishETCD"
continue
}
var cp db.ConfigurationPublish
cp.ConfigurationID = item.ID
cp.ConfigurationHistoryID = confHistory.ID
if err = mysql.Save(&cp).Error; err != nil {
step = "mysql.Save.confHistory"
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加下错误日志

}
_, cp.FilePath = genConfigurePath(appInfo.AppName, item.FileName())
if _, ok := settings["k8s_cluster"]; ok {
if err = json.Unmarshal([]byte(settings["k8s_cluster"]), &clusterList); err == nil {
for _, instance := range clusterList.List {
var cs db.ConfigurationClusterStatus
cs.ConfigurationID = item.ID
cs.ConfigurationPublishID = cp.ID
cs.ClusterName = instance.Name
cs.Used = 0
cs.Synced = 0
cs.TakeEffect = 0
cs.CreatedAt = time.Now()
cs.UpdateAt = time.Now()
if sErr := mysql.Save(&cs).Error; sErr != nil {
step = "mysql.Save.configurationClusterStatus"
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

}
}

}
}
}
return
}
Expand Down