未验证 提交 78f906ec 编写于 作者: M mouuii 提交者: GitHub

pm hostid bug (#177)

Signed-off-by: Nmouuii <zhouchengbin@koderover.com>
Co-authored-by: Nmouuii <zhouchengbin@koderover.com>
上级 639fa730
......@@ -63,15 +63,26 @@ func (c *PrivateKeyColl) EnsureIndex(ctx context.Context) error {
return err
}
func (c *PrivateKeyColl) Find(id string) (*models.PrivateKey, error) {
type FindPrivateKeyOption struct {
ID string
Address string
}
func (c *PrivateKeyColl) Find(option FindPrivateKeyOption) (*models.PrivateKey, error) {
privateKey := new(models.PrivateKey)
oid, err := primitive.ObjectIDFromHex(id)
if err != nil {
return nil, err
query := bson.M{}
if option.ID != "" {
oid, err := primitive.ObjectIDFromHex(option.ID)
if err != nil {
return nil, err
}
query["_id"] = oid
}
if option.Address != "" {
query["ip"] = option.Address
}
query := bson.M{"_id": oid}
err = c.FindOne(context.TODO(), query).Decode(privateKey)
err := c.FindOne(context.TODO(), query).Decode(privateKey)
return privateKey, err
}
......
......@@ -395,7 +395,11 @@ func UpdateServiceTemplate(args *commonservice.ServiceTmplObject) error {
existEnv = true
}
if _, err := commonrepo.NewPrivateKeyColl().Find(envStatus.HostID); err == nil {
op := commonrepo.FindPrivateKeyOption{
Address: envStatus.Address,
ID: envStatus.HostID,
}
if _, err := commonrepo.NewPrivateKeyColl().Find(op); err == nil {
existHost = true
}
......
......@@ -35,7 +35,9 @@ func ListPrivateKeys(log *zap.SugaredLogger) ([]*commonmodels.PrivateKey, error)
}
func GetPrivateKey(id string, log *zap.SugaredLogger) (*commonmodels.PrivateKey, error) {
resp, err := commonrepo.NewPrivateKeyColl().Find(id)
resp, err := commonrepo.NewPrivateKeyColl().Find(commonrepo.FindPrivateKeyOption{
ID: id,
})
if err != nil {
log.Errorf("PrivateKey.Find %s error: %v", id, err)
return resp, e.ErrGetPrivateKey
......
......@@ -1639,7 +1639,7 @@ func BuildModuleToSubTasks(moduleName, version, target, serviceName, productName
privateKeys := make([]*task.SSH, 0)
for _, sshID := range module.SSHs {
//私钥信息可能被更新,而构建中存储的信息是旧的,需要根据id获取最新的私钥信息
latestKeyInfo, err := commonrepo.NewPrivateKeyColl().Find(sshID)
latestKeyInfo, err := commonrepo.NewPrivateKeyColl().Find(commonrepo.FindPrivateKeyOption{ID: sshID})
if err != nil || latestKeyInfo == nil {
log.Errorf("PrivateKey.Find failed, id:%s, err:%v", sshID, err)
continue
......
......@@ -166,6 +166,10 @@ func (c *CronClient) RunScheduledService(svc *service.Service, healthCheck *serv
}
key := fmt.Sprintf("%s-%s-%d-%s-%s", healthCheck.Protocol, tmpEnvStatus.Address, healthCheck.Port, healthCheck.Path, tmpEnvStatus.EnvName)
envStatusKeys.Insert(key)
if tmpEnvStatus.Address == "" {
tmpEnvStatus.Address = envStatus.Address
}
tmpEnvStatus.Status = envStatus.Status
}
currentEnvStatusKey := fmt.Sprintf("%s-%s-%d-%s-%s", healthCheck.Protocol, envStatus.Address, healthCheck.Port, healthCheck.Path, envStatus.EnvName)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册