Skip to content

Commit b2a19c4

Browse files
committed
move imageDefaults from watch to defaults in config root
1 parent b9615bf commit b2a19c4

22 files changed

+136
-127
lines changed

internal/app/diun.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -153,32 +153,32 @@ func (di *Diun) Run() {
153153
defer di.pool.Release()
154154

155155
// Docker provider
156-
for _, job := range dockerPrd.New(di.cfg.Providers.Docker, di.cfg.Watch.ImageDefaults).ListJob() {
156+
for _, job := range dockerPrd.New(di.cfg.Providers.Docker, di.cfg.Defaults).ListJob() {
157157
di.createJob(job)
158158
}
159159

160160
// Swarm provider
161-
for _, job := range swarmPrd.New(di.cfg.Providers.Swarm, di.cfg.Watch.ImageDefaults).ListJob() {
161+
for _, job := range swarmPrd.New(di.cfg.Providers.Swarm, di.cfg.Defaults).ListJob() {
162162
di.createJob(job)
163163
}
164164

165165
// Kubernetes provider
166-
for _, job := range kubernetesPrd.New(di.cfg.Providers.Kubernetes, di.cfg.Watch.ImageDefaults).ListJob() {
166+
for _, job := range kubernetesPrd.New(di.cfg.Providers.Kubernetes, di.cfg.Defaults).ListJob() {
167167
di.createJob(job)
168168
}
169169

170170
// File provider
171-
for _, job := range filePrd.New(di.cfg.Providers.File, di.cfg.Watch.ImageDefaults).ListJob() {
171+
for _, job := range filePrd.New(di.cfg.Providers.File, di.cfg.Defaults).ListJob() {
172172
di.createJob(job)
173173
}
174174

175175
// Dockerfile provider
176-
for _, job := range dockerfilePrd.New(di.cfg.Providers.Dockerfile, di.cfg.Watch.ImageDefaults).ListJob() {
176+
for _, job := range dockerfilePrd.New(di.cfg.Providers.Dockerfile, di.cfg.Defaults).ListJob() {
177177
di.createJob(job)
178178
}
179179

180180
// Nomad provider
181-
for _, job := range nomadPrd.New(di.cfg.Providers.Nomad, di.cfg.Watch.ImageDefaults).ListJob() {
181+
for _, job := range nomadPrd.New(di.cfg.Providers.Nomad, di.cfg.Defaults).ListJob() {
182182
di.createJob(job)
183183
}
184184

internal/config/config.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
type Config struct {
1717
Db *model.Db `yaml:"db,omitempty" json:"db,omitempty"`
1818
Watch *model.Watch `yaml:"watch,omitempty" json:"watch,omitempty"`
19+
Defaults *model.Defaults `yaml:"defaults,omitempty" json:"defaults,omitempty"`
1920
Notif *model.Notif `yaml:"notif,omitempty" json:"notif,omitempty"`
2021
RegOpts model.RegOpts `yaml:"regopts,omitempty" json:"regopts,omitempty" validate:"unique=Name,dive"`
2122
Providers *model.Providers `yaml:"providers,omitempty" json:"providers,omitempty"`
@@ -24,8 +25,9 @@ type Config struct {
2425
// Load returns Config struct
2526
func Load(config string) (*Config, error) {
2627
cfg := Config{
27-
Db: (&model.Db{}).GetDefaults(),
28-
Watch: (&model.Watch{}).GetDefaults(),
28+
Db: (&model.Db{}).GetDefaults(),
29+
Watch: (&model.Watch{}).GetDefaults(),
30+
Defaults: (&model.Defaults{}).GetDefaults(),
2931
}
3032

3133
fileLoader := gonfig.NewFileLoader(gonfig.FileLoaderConfig{

internal/config/config_test.go

+26-20
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ func TestLoadFile(t *testing.T) {
5858
BaseURL: "https://hc-ping.com/",
5959
UUID: "5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278",
6060
},
61-
ImageDefaults: &model.ImageDefaults{
62-
WatchRepo: utl.NewFalse(),
63-
NotifyOn: []model.NotifyOn{model.NotifyOnNew},
64-
MaxTags: 5,
65-
SortTags: registry.SortTagReverse,
66-
},
61+
},
62+
Defaults: &model.Defaults{
63+
WatchRepo: utl.NewFalse(),
64+
NotifyOn: []model.NotifyOn{model.NotifyOnNew},
65+
MaxTags: 5,
66+
SortTags: registry.SortTagReverse,
6767
},
6868
Notif: &model.Notif{
6969
Amqp: &model.NotifAmqp{
@@ -271,10 +271,11 @@ func TestLoadEnv(t *testing.T) {
271271
"DIUN_PROVIDERS_DOCKER=true",
272272
},
273273
expected: &Config{
274-
Db: (&model.Db{}).GetDefaults(),
275-
Watch: (&model.Watch{}).GetDefaults(),
276-
Notif: nil,
277-
RegOpts: nil,
274+
Db: (&model.Db{}).GetDefaults(),
275+
Watch: (&model.Watch{}).GetDefaults(),
276+
Defaults: (&model.Defaults{}).GetDefaults(),
277+
Notif: nil,
278+
RegOpts: nil,
278279
Providers: &model.Providers{
279280
Docker: &model.PrdDocker{
280281
TLSVerify: utl.NewTrue(),
@@ -296,8 +297,9 @@ func TestLoadEnv(t *testing.T) {
296297
"DIUN_PROVIDERS_DOCKER=true",
297298
},
298299
expected: &Config{
299-
Db: (&model.Db{}).GetDefaults(),
300-
Watch: (&model.Watch{}).GetDefaults(),
300+
Db: (&model.Db{}).GetDefaults(),
301+
Watch: (&model.Watch{}).GetDefaults(),
302+
Defaults: (&model.Defaults{}).GetDefaults(),
301303
RegOpts: model.RegOpts{
302304
{
303305
Name: "docker.io",
@@ -326,8 +328,9 @@ func TestLoadEnv(t *testing.T) {
326328
"DIUN_PROVIDERS_SWARM=true",
327329
},
328330
expected: &Config{
329-
Db: (&model.Db{}).GetDefaults(),
330-
Watch: (&model.Watch{}).GetDefaults(),
331+
Db: (&model.Db{}).GetDefaults(),
332+
Watch: (&model.Watch{}).GetDefaults(),
333+
Defaults: (&model.Defaults{}).GetDefaults(),
331334
Notif: &model.Notif{
332335
Telegram: &model.NotifTelegram{
333336
Token: "abcdef123456",
@@ -352,8 +355,9 @@ func TestLoadEnv(t *testing.T) {
352355
"DIUN_PROVIDERS_FILE_DIRECTORY=./fixtures",
353356
},
354357
expected: &Config{
355-
Db: (&model.Db{}).GetDefaults(),
356-
Watch: (&model.Watch{}).GetDefaults(),
358+
Db: (&model.Db{}).GetDefaults(),
359+
Watch: (&model.Watch{}).GetDefaults(),
360+
Defaults: (&model.Defaults{}).GetDefaults(),
357361
Notif: &model.Notif{
358362
Script: &model.NotifScript{
359363
Cmd: "uname",
@@ -424,8 +428,9 @@ func TestLoadMixed(t *testing.T) {
424428
"DIUN_NOTIF_MAIL_LOCALNAME=foo.com",
425429
},
426430
expected: &Config{
427-
Db: (&model.Db{}).GetDefaults(),
428-
Watch: (&model.Watch{}).GetDefaults(),
431+
Db: (&model.Db{}).GetDefaults(),
432+
Watch: (&model.Watch{}).GetDefaults(),
433+
Defaults: (&model.Defaults{}).GetDefaults(),
429434
Notif: &model.Notif{
430435
Mail: &model.NotifMail{
431436
Host: "127.0.0.1",
@@ -469,8 +474,9 @@ for <code>{{ .Entry.Manifest.Platform }}</code> platform.
469474
"DIUN_NOTIF_WEBHOOK_TIMEOUT=1m",
470475
},
471476
expected: &Config{
472-
Db: (&model.Db{}).GetDefaults(),
473-
Watch: (&model.Watch{}).GetDefaults(),
477+
Db: (&model.Db{}).GetDefaults(),
478+
Watch: (&model.Watch{}).GetDefaults(),
479+
Defaults: (&model.Defaults{}).GetDefaults(),
474480
Notif: &model.Notif{
475481
Webhook: &model.NotifWebhook{
476482
Endpoint: "http://webhook.foo.com/sd54qad89azd5a",

internal/config/fixtures/config.test.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ watch:
1111
healthchecks:
1212
baseURL: https://hc-ping.com/
1313
uuid: 5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278
14-
imageDefaults:
15-
notifyOn:
16-
- new
17-
maxTags: 5
14+
15+
defaults:
16+
notifyOn:
17+
- new
18+
maxTags: 5
1819

1920
notif:
2021
amqp:

internal/model/watch_imagedefaults.go internal/model/defaults.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"github.com/crazy-max/diun/v4/pkg/utl"
66
)
77

8-
// ImageDefaults holds data necessary for image defaults configuration
9-
type ImageDefaults struct {
8+
// Defaults holds data necessary for image defaults configuration
9+
type Defaults struct {
1010
WatchRepo *bool `yaml:"watchRepo,omitempty" json:"watchRepo,omitempty"`
1111
NotifyOn []NotifyOn `yaml:"notifyOn,omitempty" json:"notifyOn,omitempty"`
1212
MaxTags int `yaml:"maxTags,omitempty" json:"maxTags,omitempty"`
@@ -17,14 +17,14 @@ type ImageDefaults struct {
1717
}
1818

1919
// GetDefaults gets the default values
20-
func (s *ImageDefaults) GetDefaults() *Watch {
21-
n := &Watch{}
20+
func (s *Defaults) GetDefaults() *Defaults {
21+
n := &Defaults{}
2222
n.SetDefaults()
2323
return n
2424
}
2525

2626
// SetDefaults sets the default values
27-
func (s *ImageDefaults) SetDefaults() {
27+
func (s *Defaults) SetDefaults() {
2828
s.WatchRepo = utl.NewFalse()
2929
s.NotifyOn = NotifyOnDefaults
3030
s.SortTags = registry.SortTagReverse

internal/model/watch.go

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type Watch struct {
1515
RunOnStartup *bool `yaml:"runOnStartup,omitempty" json:"runOnStartup,omitempty" validate:"required"`
1616
CompareDigest *bool `yaml:"compareDigest,omitempty" json:"compareDigest,omitempty" validate:"required"`
1717
Healthchecks *Healthchecks `yaml:"healthchecks,omitempty" json:"healthchecks,omitempty"`
18-
ImageDefaults *ImageDefaults `yaml:"imageDefaults,omitempty" json:"imageDefaults,omitempty"`
1918
}
2019

2120
// GetDefaults gets the default values

internal/provider/common.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ var (
1818
)
1919

2020
// ValidateImage returns a standard image through Docker labels
21-
func ValidateImage(image string, metadata, labels map[string]string, watchByDef bool, imageDefaults *model.ImageDefaults) (img model.Image, err error) {
21+
func ValidateImage(image string, metadata, labels map[string]string, watchByDef bool, defaults *model.Defaults) (img model.Image, err error) {
2222
img = model.Image{
2323
Name: image,
2424
}
2525

26-
if imageDefaults != nil {
27-
img.WatchRepo = imageDefaults.WatchRepo
28-
img.NotifyOn = imageDefaults.NotifyOn
29-
img.MaxTags = imageDefaults.MaxTags
30-
img.SortTags = imageDefaults.SortTags
31-
img.IncludeTags = imageDefaults.IncludeTags
32-
img.ExcludeTags = imageDefaults.ExcludeTags
33-
img.Metadata = imageDefaults.Metadata
26+
if defaults != nil {
27+
img.WatchRepo = defaults.WatchRepo
28+
img.NotifyOn = defaults.NotifyOn
29+
img.MaxTags = defaults.MaxTags
30+
img.SortTags = defaults.SortTags
31+
img.IncludeTags = defaults.IncludeTags
32+
img.ExcludeTags = defaults.ExcludeTags
33+
img.Metadata = defaults.Metadata
3434
}
3535

3636
if enableStr, ok := labels["diun.enable"]; ok {

0 commit comments

Comments
 (0)