mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): lb local cert sync fix
This commit is contained in:
@@ -312,11 +312,7 @@ func (man *SCachedLoadbalancerCertificateManager) newFromCloudLoadbalancerCertif
|
||||
lbcert.ManagerId = provider.Id
|
||||
lbcert.CloudregionId = region.Id
|
||||
|
||||
c := SLoadbalancerCertificate{}
|
||||
q1 := LoadbalancerCertificateManager.Query().IsFalse("pending_deleted")
|
||||
q1 = q1.Equals("fingerprint", extCertificate.GetFingerprint())
|
||||
q1 = q1.Equals("tenant_id", provider.ProjectId)
|
||||
err := q1.First(&c)
|
||||
c, err := LoadbalancerCertificateManager.GetLbCertByFingerprint(provider.ProjectId, extCertificate.GetFingerprint())
|
||||
if err != nil {
|
||||
switch err {
|
||||
case sql.ErrNoRows:
|
||||
@@ -365,6 +361,23 @@ func (lbcert *SCachedLoadbalancerCertificate) SyncWithCloudLoadbalancerCertifica
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update local lb cert
|
||||
localCert, err := LoadbalancerCertificateManager.GetLbCertByFingerprint(projectId.GetProjectId(), extCertificate.GetFingerprint())
|
||||
if err == nil && !localCert.IsComplete() {
|
||||
pkey := extCertificate.GetPrivateKey()
|
||||
cert := extCertificate.GetPublickKey()
|
||||
if len(pkey) > 0 && len(cert) > 0 {
|
||||
_, err = db.UpdateWithLock(ctx, localCert, func() error {
|
||||
localCert.Certificate = cert
|
||||
localCert.PrivateKey = pkey
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("SyncWithCloudLoadbalancerCertificate.Update.localcert %s %s", localCert.Id, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
db.OpsLog.LogSyncUpdate(lbcert, diff, userCred)
|
||||
|
||||
SyncCloudProject(userCred, lbcert, projectId, extCertificate, lbcert.ManagerId)
|
||||
|
||||
@@ -478,3 +478,16 @@ func (manager *SLoadbalancerCertificateManager) GetResourceCount() ([]db.SScopeR
|
||||
virts := manager.Query().IsFalse("pending_deleted")
|
||||
return db.CalculateResourceCount(virts, "tenant_id")
|
||||
}
|
||||
|
||||
func (manager *SLoadbalancerCertificateManager) GetLbCertByFingerprint(tenantId, fingerprint string) (*SLoadbalancerCertificate, error) {
|
||||
c := SLoadbalancerCertificate{}
|
||||
c.SetModelManager(manager, &c)
|
||||
q1 := LoadbalancerCertificateManager.Query().IsFalse("pending_deleted")
|
||||
q1 = q1.Equals("fingerprint", fingerprint)
|
||||
q1 = q1.Equals("tenant_id", tenantId)
|
||||
if err := q1.First(&c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user