mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-30 06:03:45 +01:00
Merge pull request #6083 from reasonerjt/multi-adminserver-conflict
Ignore duplication error when inserting config
This commit is contained in:
commit
0b0678b7fe
@ -126,6 +126,12 @@ func GetOrmer() orm.Ormer {
|
|||||||
return globalOrm
|
return globalOrm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isDupRecErr checks if the error is due to a duplication of record, currently this
|
||||||
|
// works only for pgSQL
|
||||||
|
func isDupRecErr(e error) bool {
|
||||||
|
return strings.Contains(e.Error(), "duplicate key value violates unique constraint")
|
||||||
|
}
|
||||||
|
|
||||||
// ClearTable is the shortcut for test cases, it should be called only in test cases.
|
// ClearTable is the shortcut for test cases, it should be called only in test cases.
|
||||||
func ClearTable(table string) error {
|
func ClearTable(table string) error {
|
||||||
o := GetOrmer()
|
o := GetOrmer()
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AuthModeCanBeModified determines whether auth mode can be
|
// AuthModeCanBeModified determines whether auth mode can be
|
||||||
@ -60,7 +61,8 @@ func SaveConfigEntries(entries []models.ConfigEntry) error {
|
|||||||
tempEntry.Key = entry.Key
|
tempEntry.Key = entry.Key
|
||||||
tempEntry.Value = entry.Value
|
tempEntry.Value = entry.Value
|
||||||
created, _, err := o.ReadOrCreate(&tempEntry, "k")
|
created, _, err := o.ReadOrCreate(&tempEntry, "k")
|
||||||
if err != nil {
|
if err != nil && !isDupRecErr(err) {
|
||||||
|
log.Errorf("Error create configuration entry: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !created {
|
if !created {
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -1486,5 +1487,9 @@ func TestSaveConfigEntries(t *testing.T) {
|
|||||||
if findItem != 3 {
|
if findItem != 3 {
|
||||||
t.Fatalf("Should update 3 configuration but only update %d", findItem)
|
t.Fatalf("Should update 3 configuration but only update %d", findItem)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIsDupRecError(t *testing.T) {
|
||||||
|
assert.True(t, isDupRecErr(fmt.Errorf("pq: duplicate key value violates unique constraint \"properties_k_key\"")))
|
||||||
|
assert.False(t, isDupRecErr(fmt.Errorf("other error")))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user