Skip to content

Commit 2ed9b18

Browse files
committed
checkpoint
Signed-off-by: Jeff Ortel <jortel@redhat.com>
1 parent 512201e commit 2ed9b18

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

cmd/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ func addonManager(db *gorm.DB) (mgr manager.Manager, err error) {
9494

9595
// main.
9696
func main() {
97-
log.Info("Started", "settings", Settings)
97+
log.Info(
98+
"Starting",
99+
"build",
100+
Settings.Hub.Build,
101+
"settings",
102+
Settings)
98103
var err error
99104
defer func() {
100105
if err != nil {

seed/seed.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package seed
22

33
import (
4-
"errors"
54
"fmt"
65
"strings"
76

@@ -124,21 +123,23 @@ func matchBuild(db *gorm.DB) (matched bool, err error) {
124123
if err != nil {
125124
return
126125
}
126+
if build == "" {
127+
return
128+
}
127129
matched = build == Settings.Hub.Build
128130
log.Info("Seed build (version)", "matched", matched)
129131
return
130132
}
131133

132134
// getBuild returns the hub build version that seeded.
133135
func getBuild(db *gorm.DB) (version string, err error) {
134-
setting := &model.Setting{}
135-
err = db.First(setting, model.Setting{Key: BuildKey}).Error
136+
setting := &model.Setting{
137+
Key: BuildKey,
138+
}
139+
db = db.Where("key", BuildKey)
140+
err = db.FirstOrCreate(setting).Error
136141
if err != nil {
137-
if !errors.Is(err, gorm.ErrRecordNotFound) {
138-
err = liberr.Wrap(err)
139-
} else {
140-
err = nil
141-
}
142+
err = liberr.Wrap(err)
142143
return
143144
}
144145
if n, cast := setting.Value.(string); cast {
@@ -153,7 +154,8 @@ func saveBuild(db *gorm.DB) (err error) {
153154
Key: BuildKey,
154155
Value: Settings.Hub.Build,
155156
}
156-
err = db.Save(setting).Error
157+
db = db.Where("key", BuildKey)
158+
err = db.Updates(setting).Error
157159
if err != nil {
158160
err = liberr.Wrap(err)
159161
return

settings/hub.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
const (
1212
EnvNamespace = "NAMESPACE"
13+
EnvBuild = "BUILD"
1314
EnvDbPath = "DB_PATH"
1415
EnvDbMaxCon = "DB_MAX_CONNECTION"
1516
EnvDbSeedPath = "DB_SEED_PATH"
@@ -367,10 +368,13 @@ func (r *Hub) namespace() (ns string, err error) {
367368
// build returns the hub build version.
368369
// This is expected to be the output of `git describe`.
369370
// Examples:
370-
//
371-
// v0.6.0
372371
// v0.6.0-ea89gcd
372+
// v0.6.0
373373
func (r *Hub) build() (version string, err error) {
374+
version, found := os.LookupEnv(EnvBuild)
375+
if found {
376+
return
377+
}
374378
f, err := os.Open("/etc/hub-build")
375379
if err != nil {
376380
if os.IsNotExist(err) {

0 commit comments

Comments
 (0)