move imageDefaults from watch to defaults in config root

This commit is contained in:
CrazyMax
2023-09-23 13:26:09 +02:00
parent b9615bf2db
commit b2a19c457c
22 changed files with 136 additions and 127 deletions

View File

@@ -153,32 +153,32 @@ func (di *Diun) Run() {
defer di.pool.Release() defer di.pool.Release()
// Docker provider // Docker provider
for _, job := range dockerPrd.New(di.cfg.Providers.Docker, di.cfg.Watch.ImageDefaults).ListJob() { for _, job := range dockerPrd.New(di.cfg.Providers.Docker, di.cfg.Defaults).ListJob() {
di.createJob(job) di.createJob(job)
} }
// Swarm provider // Swarm provider
for _, job := range swarmPrd.New(di.cfg.Providers.Swarm, di.cfg.Watch.ImageDefaults).ListJob() { for _, job := range swarmPrd.New(di.cfg.Providers.Swarm, di.cfg.Defaults).ListJob() {
di.createJob(job) di.createJob(job)
} }
// Kubernetes provider // Kubernetes provider
for _, job := range kubernetesPrd.New(di.cfg.Providers.Kubernetes, di.cfg.Watch.ImageDefaults).ListJob() { for _, job := range kubernetesPrd.New(di.cfg.Providers.Kubernetes, di.cfg.Defaults).ListJob() {
di.createJob(job) di.createJob(job)
} }
// File provider // File provider
for _, job := range filePrd.New(di.cfg.Providers.File, di.cfg.Watch.ImageDefaults).ListJob() { for _, job := range filePrd.New(di.cfg.Providers.File, di.cfg.Defaults).ListJob() {
di.createJob(job) di.createJob(job)
} }
// Dockerfile provider // Dockerfile provider
for _, job := range dockerfilePrd.New(di.cfg.Providers.Dockerfile, di.cfg.Watch.ImageDefaults).ListJob() { for _, job := range dockerfilePrd.New(di.cfg.Providers.Dockerfile, di.cfg.Defaults).ListJob() {
di.createJob(job) di.createJob(job)
} }
// Nomad provider // Nomad provider
for _, job := range nomadPrd.New(di.cfg.Providers.Nomad, di.cfg.Watch.ImageDefaults).ListJob() { for _, job := range nomadPrd.New(di.cfg.Providers.Nomad, di.cfg.Defaults).ListJob() {
di.createJob(job) di.createJob(job)
} }

View File

@@ -16,6 +16,7 @@ import (
type Config struct { type Config struct {
Db *model.Db `yaml:"db,omitempty" json:"db,omitempty"` Db *model.Db `yaml:"db,omitempty" json:"db,omitempty"`
Watch *model.Watch `yaml:"watch,omitempty" json:"watch,omitempty"` Watch *model.Watch `yaml:"watch,omitempty" json:"watch,omitempty"`
Defaults *model.Defaults `yaml:"defaults,omitempty" json:"defaults,omitempty"`
Notif *model.Notif `yaml:"notif,omitempty" json:"notif,omitempty"` Notif *model.Notif `yaml:"notif,omitempty" json:"notif,omitempty"`
RegOpts model.RegOpts `yaml:"regopts,omitempty" json:"regopts,omitempty" validate:"unique=Name,dive"` RegOpts model.RegOpts `yaml:"regopts,omitempty" json:"regopts,omitempty" validate:"unique=Name,dive"`
Providers *model.Providers `yaml:"providers,omitempty" json:"providers,omitempty"` Providers *model.Providers `yaml:"providers,omitempty" json:"providers,omitempty"`
@@ -24,8 +25,9 @@ type Config struct {
// Load returns Config struct // Load returns Config struct
func Load(config string) (*Config, error) { func Load(config string) (*Config, error) {
cfg := Config{ cfg := Config{
Db: (&model.Db{}).GetDefaults(), Db: (&model.Db{}).GetDefaults(),
Watch: (&model.Watch{}).GetDefaults(), Watch: (&model.Watch{}).GetDefaults(),
Defaults: (&model.Defaults{}).GetDefaults(),
} }
fileLoader := gonfig.NewFileLoader(gonfig.FileLoaderConfig{ fileLoader := gonfig.NewFileLoader(gonfig.FileLoaderConfig{

View File

@@ -58,12 +58,12 @@ func TestLoadFile(t *testing.T) {
BaseURL: "https://hc-ping.com/", BaseURL: "https://hc-ping.com/",
UUID: "5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278", UUID: "5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278",
}, },
ImageDefaults: &model.ImageDefaults{ },
WatchRepo: utl.NewFalse(), Defaults: &model.Defaults{
NotifyOn: []model.NotifyOn{model.NotifyOnNew}, WatchRepo: utl.NewFalse(),
MaxTags: 5, NotifyOn: []model.NotifyOn{model.NotifyOnNew},
SortTags: registry.SortTagReverse, MaxTags: 5,
}, SortTags: registry.SortTagReverse,
}, },
Notif: &model.Notif{ Notif: &model.Notif{
Amqp: &model.NotifAmqp{ Amqp: &model.NotifAmqp{
@@ -271,10 +271,11 @@ func TestLoadEnv(t *testing.T) {
"DIUN_PROVIDERS_DOCKER=true", "DIUN_PROVIDERS_DOCKER=true",
}, },
expected: &Config{ expected: &Config{
Db: (&model.Db{}).GetDefaults(), Db: (&model.Db{}).GetDefaults(),
Watch: (&model.Watch{}).GetDefaults(), Watch: (&model.Watch{}).GetDefaults(),
Notif: nil, Defaults: (&model.Defaults{}).GetDefaults(),
RegOpts: nil, Notif: nil,
RegOpts: nil,
Providers: &model.Providers{ Providers: &model.Providers{
Docker: &model.PrdDocker{ Docker: &model.PrdDocker{
TLSVerify: utl.NewTrue(), TLSVerify: utl.NewTrue(),
@@ -296,8 +297,9 @@ func TestLoadEnv(t *testing.T) {
"DIUN_PROVIDERS_DOCKER=true", "DIUN_PROVIDERS_DOCKER=true",
}, },
expected: &Config{ expected: &Config{
Db: (&model.Db{}).GetDefaults(), Db: (&model.Db{}).GetDefaults(),
Watch: (&model.Watch{}).GetDefaults(), Watch: (&model.Watch{}).GetDefaults(),
Defaults: (&model.Defaults{}).GetDefaults(),
RegOpts: model.RegOpts{ RegOpts: model.RegOpts{
{ {
Name: "docker.io", Name: "docker.io",
@@ -326,8 +328,9 @@ func TestLoadEnv(t *testing.T) {
"DIUN_PROVIDERS_SWARM=true", "DIUN_PROVIDERS_SWARM=true",
}, },
expected: &Config{ expected: &Config{
Db: (&model.Db{}).GetDefaults(), Db: (&model.Db{}).GetDefaults(),
Watch: (&model.Watch{}).GetDefaults(), Watch: (&model.Watch{}).GetDefaults(),
Defaults: (&model.Defaults{}).GetDefaults(),
Notif: &model.Notif{ Notif: &model.Notif{
Telegram: &model.NotifTelegram{ Telegram: &model.NotifTelegram{
Token: "abcdef123456", Token: "abcdef123456",
@@ -352,8 +355,9 @@ func TestLoadEnv(t *testing.T) {
"DIUN_PROVIDERS_FILE_DIRECTORY=./fixtures", "DIUN_PROVIDERS_FILE_DIRECTORY=./fixtures",
}, },
expected: &Config{ expected: &Config{
Db: (&model.Db{}).GetDefaults(), Db: (&model.Db{}).GetDefaults(),
Watch: (&model.Watch{}).GetDefaults(), Watch: (&model.Watch{}).GetDefaults(),
Defaults: (&model.Defaults{}).GetDefaults(),
Notif: &model.Notif{ Notif: &model.Notif{
Script: &model.NotifScript{ Script: &model.NotifScript{
Cmd: "uname", Cmd: "uname",
@@ -424,8 +428,9 @@ func TestLoadMixed(t *testing.T) {
"DIUN_NOTIF_MAIL_LOCALNAME=foo.com", "DIUN_NOTIF_MAIL_LOCALNAME=foo.com",
}, },
expected: &Config{ expected: &Config{
Db: (&model.Db{}).GetDefaults(), Db: (&model.Db{}).GetDefaults(),
Watch: (&model.Watch{}).GetDefaults(), Watch: (&model.Watch{}).GetDefaults(),
Defaults: (&model.Defaults{}).GetDefaults(),
Notif: &model.Notif{ Notif: &model.Notif{
Mail: &model.NotifMail{ Mail: &model.NotifMail{
Host: "127.0.0.1", Host: "127.0.0.1",
@@ -469,8 +474,9 @@ for <code>{{ .Entry.Manifest.Platform }}</code> platform.
"DIUN_NOTIF_WEBHOOK_TIMEOUT=1m", "DIUN_NOTIF_WEBHOOK_TIMEOUT=1m",
}, },
expected: &Config{ expected: &Config{
Db: (&model.Db{}).GetDefaults(), Db: (&model.Db{}).GetDefaults(),
Watch: (&model.Watch{}).GetDefaults(), Watch: (&model.Watch{}).GetDefaults(),
Defaults: (&model.Defaults{}).GetDefaults(),
Notif: &model.Notif{ Notif: &model.Notif{
Webhook: &model.NotifWebhook{ Webhook: &model.NotifWebhook{
Endpoint: "http://webhook.foo.com/sd54qad89azd5a", Endpoint: "http://webhook.foo.com/sd54qad89azd5a",

View File

@@ -11,10 +11,11 @@ watch:
healthchecks: healthchecks:
baseURL: https://hc-ping.com/ baseURL: https://hc-ping.com/
uuid: 5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278 uuid: 5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278
imageDefaults:
notifyOn: defaults:
- new notifyOn:
maxTags: 5 - new
maxTags: 5
notif: notif:
amqp: amqp:

View File

@@ -5,8 +5,8 @@ import (
"github.com/crazy-max/diun/v4/pkg/utl" "github.com/crazy-max/diun/v4/pkg/utl"
) )
// ImageDefaults holds data necessary for image defaults configuration // Defaults holds data necessary for image defaults configuration
type ImageDefaults struct { type Defaults struct {
WatchRepo *bool `yaml:"watchRepo,omitempty" json:"watchRepo,omitempty"` WatchRepo *bool `yaml:"watchRepo,omitempty" json:"watchRepo,omitempty"`
NotifyOn []NotifyOn `yaml:"notifyOn,omitempty" json:"notifyOn,omitempty"` NotifyOn []NotifyOn `yaml:"notifyOn,omitempty" json:"notifyOn,omitempty"`
MaxTags int `yaml:"maxTags,omitempty" json:"maxTags,omitempty"` MaxTags int `yaml:"maxTags,omitempty" json:"maxTags,omitempty"`
@@ -17,14 +17,14 @@ type ImageDefaults struct {
} }
// GetDefaults gets the default values // GetDefaults gets the default values
func (s *ImageDefaults) GetDefaults() *Watch { func (s *Defaults) GetDefaults() *Defaults {
n := &Watch{} n := &Defaults{}
n.SetDefaults() n.SetDefaults()
return n return n
} }
// SetDefaults sets the default values // SetDefaults sets the default values
func (s *ImageDefaults) SetDefaults() { func (s *Defaults) SetDefaults() {
s.WatchRepo = utl.NewFalse() s.WatchRepo = utl.NewFalse()
s.NotifyOn = NotifyOnDefaults s.NotifyOn = NotifyOnDefaults
s.SortTags = registry.SortTagReverse s.SortTags = registry.SortTagReverse

View File

@@ -15,7 +15,6 @@ type Watch struct {
RunOnStartup *bool `yaml:"runOnStartup,omitempty" json:"runOnStartup,omitempty" validate:"required"` RunOnStartup *bool `yaml:"runOnStartup,omitempty" json:"runOnStartup,omitempty" validate:"required"`
CompareDigest *bool `yaml:"compareDigest,omitempty" json:"compareDigest,omitempty" validate:"required"` CompareDigest *bool `yaml:"compareDigest,omitempty" json:"compareDigest,omitempty" validate:"required"`
Healthchecks *Healthchecks `yaml:"healthchecks,omitempty" json:"healthchecks,omitempty"` Healthchecks *Healthchecks `yaml:"healthchecks,omitempty" json:"healthchecks,omitempty"`
ImageDefaults *ImageDefaults `yaml:"imageDefaults,omitempty" json:"imageDefaults,omitempty"`
} }
// GetDefaults gets the default values // GetDefaults gets the default values

View File

@@ -18,19 +18,19 @@ var (
) )
// ValidateImage returns a standard image through Docker labels // ValidateImage returns a standard image through Docker labels
func ValidateImage(image string, metadata, labels map[string]string, watchByDef bool, imageDefaults *model.ImageDefaults) (img model.Image, err error) { func ValidateImage(image string, metadata, labels map[string]string, watchByDef bool, defaults *model.Defaults) (img model.Image, err error) {
img = model.Image{ img = model.Image{
Name: image, Name: image,
} }
if imageDefaults != nil { if defaults != nil {
img.WatchRepo = imageDefaults.WatchRepo img.WatchRepo = defaults.WatchRepo
img.NotifyOn = imageDefaults.NotifyOn img.NotifyOn = defaults.NotifyOn
img.MaxTags = imageDefaults.MaxTags img.MaxTags = defaults.MaxTags
img.SortTags = imageDefaults.SortTags img.SortTags = defaults.SortTags
img.IncludeTags = imageDefaults.IncludeTags img.IncludeTags = defaults.IncludeTags
img.ExcludeTags = imageDefaults.ExcludeTags img.ExcludeTags = defaults.ExcludeTags
img.Metadata = imageDefaults.Metadata img.Metadata = defaults.Metadata
} }
if enableStr, ok := labels["diun.enable"]; ok { if enableStr, ok := labels["diun.enable"]; ok {

View File

@@ -17,7 +17,7 @@ func TestValidateImage(t *testing.T) {
metadata map[string]string metadata map[string]string
labels map[string]string labels map[string]string
watchByDef bool watchByDef bool
imageDefaults *model.ImageDefaults defaults *model.Defaults
expectedImage model.Image expectedImage model.Image
expectedErr error expectedErr error
}{ }{
@@ -85,8 +85,8 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.regopt": "foo", "diun.regopt": "foo",
}, },
watchByDef: true, watchByDef: true,
imageDefaults: &model.ImageDefaults{}, defaults: &model.Defaults{},
expectedImage: model.Image{ expectedImage: model.Image{
Name: "myimg", Name: "myimg",
RegOpt: "foo", RegOpt: "foo",
@@ -110,7 +110,7 @@ func TestValidateImage(t *testing.T) {
name: "Include using global settings", name: "Include using global settings",
image: "myimg", image: "myimg",
watchByDef: true, watchByDef: true,
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
WatchRepo: utl.NewTrue(), WatchRepo: utl.NewTrue(),
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -126,7 +126,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.watch_repo": "chickens", "diun.watch_repo": "chickens",
}, },
imageDefaults: &model.ImageDefaults{}, defaults: &model.Defaults{},
expectedImage: model.Image{ expectedImage: model.Image{
Name: "myimg", Name: "myimg",
}, },
@@ -139,7 +139,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.watch_repo": "false", "diun.watch_repo": "false",
}, },
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
WatchRepo: utl.NewTrue(), WatchRepo: utl.NewTrue(),
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -155,7 +155,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.watch_repo": "true", "diun.watch_repo": "true",
}, },
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
WatchRepo: utl.NewFalse(), WatchRepo: utl.NewFalse(),
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -207,7 +207,7 @@ func TestValidateImage(t *testing.T) {
image: "myimg", image: "myimg",
watchByDef: true, watchByDef: true,
labels: map[string]string{}, labels: map[string]string{},
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
NotifyOn: []model.NotifyOn{model.NotifyOnNew}, NotifyOn: []model.NotifyOn{model.NotifyOnNew},
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -223,7 +223,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.notify_on": "update", "diun.notify_on": "update",
}, },
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
NotifyOn: []model.NotifyOn{model.NotifyOnNew}, NotifyOn: []model.NotifyOn{model.NotifyOnNew},
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -274,7 +274,7 @@ func TestValidateImage(t *testing.T) {
image: "myimg", image: "myimg",
watchByDef: true, watchByDef: true,
labels: map[string]string{}, labels: map[string]string{},
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
SortTags: registry.SortTagSemver, SortTags: registry.SortTagSemver,
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -290,7 +290,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.sort_tags": "reverse", "diun.sort_tags": "reverse",
}, },
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
SortTags: registry.SortTagSemver, SortTags: registry.SortTagSemver,
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -341,7 +341,7 @@ func TestValidateImage(t *testing.T) {
image: "myimg", image: "myimg",
watchByDef: true, watchByDef: true,
labels: map[string]string{}, labels: map[string]string{},
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
MaxTags: 10, MaxTags: 10,
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -357,7 +357,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.max_tags": "11", "diun.max_tags": "11",
}, },
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
MaxTags: 10, MaxTags: 10,
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -397,7 +397,7 @@ func TestValidateImage(t *testing.T) {
image: "myimg", image: "myimg",
watchByDef: true, watchByDef: true,
labels: map[string]string{}, labels: map[string]string{},
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
IncludeTags: []string{"alpine"}, IncludeTags: []string{"alpine"},
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -413,7 +413,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.include_tags": "ubuntu", "diun.include_tags": "ubuntu",
}, },
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
IncludeTags: []string{"alpine"}, IncludeTags: []string{"alpine"},
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -453,7 +453,7 @@ func TestValidateImage(t *testing.T) {
image: "myimg", image: "myimg",
watchByDef: true, watchByDef: true,
labels: map[string]string{}, labels: map[string]string{},
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
ExcludeTags: []string{"alpine"}, ExcludeTags: []string{"alpine"},
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -469,7 +469,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.exclude_tags": "ubuntu", "diun.exclude_tags": "ubuntu",
}, },
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
ExcludeTags: []string{"alpine"}, ExcludeTags: []string{"alpine"},
}, },
expectedImage: model.Image{ expectedImage: model.Image{
@@ -626,7 +626,7 @@ func TestValidateImage(t *testing.T) {
image: "myimg", image: "myimg",
watchByDef: true, watchByDef: true,
labels: map[string]string{}, labels: map[string]string{},
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
Metadata: map[string]string{ Metadata: map[string]string{
"foo123": "bar", "foo123": "bar",
}, },
@@ -646,7 +646,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.metadata.biz123": "baz", "diun.metadata.biz123": "baz",
}, },
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
Metadata: map[string]string{ Metadata: map[string]string{
"foo123": "bar", "foo123": "bar",
}, },
@@ -667,7 +667,7 @@ func TestValidateImage(t *testing.T) {
labels: map[string]string{ labels: map[string]string{
"diun.metadata.foo123": "baz", "diun.metadata.foo123": "baz",
}, },
imageDefaults: &model.ImageDefaults{ defaults: &model.Defaults{
Metadata: map[string]string{ Metadata: map[string]string{
"foo123": "bar", "foo123": "bar",
}, },
@@ -690,7 +690,7 @@ func TestValidateImage(t *testing.T) {
tt.metadata, tt.metadata,
tt.labels, tt.labels,
tt.watchByDef, tt.watchByDef,
tt.imageDefaults, tt.defaults,
) )
if tt.expectedErr == nil { if tt.expectedErr == nil {
assert.NoError(t, err) assert.NoError(t, err)

View File

@@ -91,7 +91,7 @@ func (c *Client) listContainerImage() []model.Image {
Str("ctn_image", imageName). Str("ctn_image", imageName).
Interface("ctn_labels", ctn.Labels). Interface("ctn_labels", ctn.Labels).
Msg("Validate image") Msg("Validate image")
image, err := provider.ValidateImage(imageName, metadata(ctn), ctn.Labels, *c.config.WatchByDefault, c.imageDefaults) image, err := provider.ValidateImage(imageName, metadata(ctn), ctn.Labels, *c.config.WatchByDefault, c.defaults)
if err != nil { if err != nil {
c.logger.Error().Err(err). c.logger.Error().Err(err).

View File

@@ -10,18 +10,18 @@ import (
// Client represents an active docker provider object // Client represents an active docker provider object
type Client struct { type Client struct {
*provider.Client *provider.Client
config *model.PrdDocker config *model.PrdDocker
logger zerolog.Logger logger zerolog.Logger
imageDefaults *model.ImageDefaults defaults *model.Defaults
} }
// New creates new docker provider instance // New creates new docker provider instance
func New(config *model.PrdDocker, imageDefaults *model.ImageDefaults) *provider.Client { func New(config *model.PrdDocker, defaults *model.Defaults) *provider.Client {
return &provider.Client{ return &provider.Client{
Handler: &Client{ Handler: &Client{
config: config, config: config,
logger: log.With().Str("provider", "docker").Logger(), logger: log.With().Str("provider", "docker").Logger(),
imageDefaults: imageDefaults, defaults: defaults,
}, },
} }
} }

View File

@@ -10,18 +10,18 @@ import (
// Client represents an active dockerfile provider object // Client represents an active dockerfile provider object
type Client struct { type Client struct {
*provider.Client *provider.Client
config *model.PrdDockerfile config *model.PrdDockerfile
logger zerolog.Logger logger zerolog.Logger
imageDefaults *model.ImageDefaults defaults *model.Defaults
} }
// New creates new dockerfile provider instance // New creates new dockerfile provider instance
func New(config *model.PrdDockerfile, imageDefaults *model.ImageDefaults) *provider.Client { func New(config *model.PrdDockerfile, defaults *model.Defaults) *provider.Client {
return &provider.Client{ return &provider.Client{
Handler: &Client{ Handler: &Client{
config: config, config: config,
logger: log.With().Str("provider", "dockerfile").Logger(), logger: log.With().Str("provider", "dockerfile").Logger(),
imageDefaults: imageDefaults, defaults: defaults,
}, },
} }
} }

View File

@@ -32,7 +32,7 @@ func (c *Client) listExtImage() (list []model.Image) {
Interface("dfile_comments", fromImage.Comments). Interface("dfile_comments", fromImage.Comments).
Int("dfile_line", fromImage.Line). Int("dfile_line", fromImage.Line).
Msg("Validate image") Msg("Validate image")
image, err := provider.ValidateImage(fromImage.Name, nil, c.extractLabels(fromImage.Comments), true, c.imageDefaults) image, err := provider.ValidateImage(fromImage.Name, nil, c.extractLabels(fromImage.Comments), true, c.defaults)
if err != nil { if err != nil {
c.logger.Error().Err(err). c.logger.Error().Err(err).
Str("dfile_image", fromImage.Name). Str("dfile_image", fromImage.Name).

View File

@@ -10,18 +10,18 @@ import (
// Client represents an active file provider object // Client represents an active file provider object
type Client struct { type Client struct {
*provider.Client *provider.Client
config *model.PrdFile config *model.PrdFile
logger zerolog.Logger logger zerolog.Logger
imageDefaults *model.ImageDefaults defaults *model.Defaults
} }
// New creates new file provider instance // New creates new file provider instance
func New(config *model.PrdFile, imageDefaults *model.ImageDefaults) *provider.Client { func New(config *model.PrdFile, defaults *model.Defaults) *provider.Client {
return &provider.Client{ return &provider.Client{
Handler: &Client{ Handler: &Client{
config: config, config: config,
logger: log.With().Str("provider", "file").Logger(), logger: log.With().Str("provider", "file").Logger(),
imageDefaults: imageDefaults, defaults: defaults,
}, },
} }
} }

View File

@@ -10,7 +10,7 @@ import (
) )
var ( var (
defaultImageDefaults = model.ImageDefaults{ defaults = model.Defaults{
NotifyOn: model.NotifyOnDefaults, NotifyOn: model.NotifyOnDefaults,
SortTags: registry.SortTagReverse, SortTags: registry.SortTagReverse,
} }
@@ -157,7 +157,7 @@ var (
func TestListJobFilename(t *testing.T) { func TestListJobFilename(t *testing.T) {
fc := New(&model.PrdFile{ fc := New(&model.PrdFile{
Filename: "./fixtures/dockerhub.yml", Filename: "./fixtures/dockerhub.yml",
}, &defaultImageDefaults) }, &defaults)
assert.Equal(t, dockerhubFile, fc.ListJob()) assert.Equal(t, dockerhubFile, fc.ListJob())
} }
@@ -165,7 +165,7 @@ func TestListJobFilename(t *testing.T) {
func TestListJobDirectory(t *testing.T) { func TestListJobDirectory(t *testing.T) {
fc := New(&model.PrdFile{ fc := New(&model.PrdFile{
Directory: "./fixtures", Directory: "./fixtures",
}, &defaultImageDefaults) }, &defaults)
assert.Equal(t, append(append(bintrayFile, dockerhubFile...), append(lscrFile, quayFile...)...), fc.ListJob()) assert.Equal(t, append(append(bintrayFile, dockerhubFile...), append(lscrFile, quayFile...)...), fc.ListJob())
} }
@@ -173,7 +173,7 @@ func TestListJobDirectory(t *testing.T) {
func TestDefaultImageOptions(t *testing.T) { func TestDefaultImageOptions(t *testing.T) {
fc := New(&model.PrdFile{ fc := New(&model.PrdFile{
Filename: "./fixtures/dockerhub.yml", Filename: "./fixtures/dockerhub.yml",
}, &model.ImageDefaults{ }, &model.Defaults{
WatchRepo: utl.NewTrue(), WatchRepo: utl.NewTrue(),
}) })

View File

@@ -34,11 +34,11 @@ func (c *Client) listFileImage() []model.Image {
for _, item := range items { for _, item := range items {
// Set default WatchRepo // Set default WatchRepo
if item.WatchRepo == nil { if item.WatchRepo == nil {
item.WatchRepo = c.imageDefaults.WatchRepo item.WatchRepo = c.defaults.WatchRepo
} }
// Check NotifyOn // Check NotifyOn
if len(item.NotifyOn) == 0 { if len(item.NotifyOn) == 0 {
item.NotifyOn = c.imageDefaults.NotifyOn item.NotifyOn = c.defaults.NotifyOn
} else { } else {
for _, no := range item.NotifyOn { for _, no := range item.NotifyOn {
if !no.Valid() { if !no.Valid() {
@@ -52,7 +52,7 @@ func (c *Client) listFileImage() []model.Image {
// Check SortType // Check SortType
if item.SortTags == "" { if item.SortTags == "" {
item.SortTags = c.imageDefaults.SortTags item.SortTags = c.defaults.SortTags
} }
if !item.SortTags.Valid() { if !item.SortTags.Valid() {
c.logger.Error(). c.logger.Error().

View File

@@ -10,18 +10,18 @@ import (
// Client represents an active kubernetes provider object // Client represents an active kubernetes provider object
type Client struct { type Client struct {
*provider.Client *provider.Client
config *model.PrdKubernetes config *model.PrdKubernetes
logger zerolog.Logger logger zerolog.Logger
imageDefaults *model.ImageDefaults defaults *model.Defaults
} }
// New creates new kubernetes provider instance // New creates new kubernetes provider instance
func New(config *model.PrdKubernetes, imageDefaults *model.ImageDefaults) *provider.Client { func New(config *model.PrdKubernetes, defaults *model.Defaults) *provider.Client {
return &provider.Client{ return &provider.Client{
Handler: &Client{ Handler: &Client{
config: config, config: config,
logger: log.With().Str("provider", "kubernetes").Logger(), logger: log.With().Str("provider", "kubernetes").Logger(),
imageDefaults: imageDefaults, defaults: defaults,
}, },
} }
} }

View File

@@ -41,7 +41,7 @@ func (c *Client) listPodImage() []model.Image {
Str("ctn_image", ctn.Image). Str("ctn_image", ctn.Image).
Msg("Validate image") Msg("Validate image")
image, err := provider.ValidateImage(ctn.Image, metadata(pod, ctn), pod.Annotations, *c.config.WatchByDefault, c.imageDefaults) image, err := provider.ValidateImage(ctn.Image, metadata(pod, ctn), pod.Annotations, *c.config.WatchByDefault, c.defaults)
if err != nil { if err != nil {
c.logger.Error().Err(err). c.logger.Error().Err(err).
Str("pod_name", pod.Name). Str("pod_name", pod.Name).

View File

@@ -10,18 +10,18 @@ import (
// Client represents an active nomad provider object // Client represents an active nomad provider object
type Client struct { type Client struct {
*provider.Client *provider.Client
config *model.PrdNomad config *model.PrdNomad
logger zerolog.Logger logger zerolog.Logger
imageDefaults *model.ImageDefaults defaults *model.Defaults
} }
// New creates new nomad provider instance // New creates new nomad provider instance
func New(config *model.PrdNomad, imageDefaults *model.ImageDefaults) *provider.Client { func New(config *model.PrdNomad, defaults *model.Defaults) *provider.Client {
return &provider.Client{ return &provider.Client{
Handler: &Client{ Handler: &Client{
config: config, config: config,
logger: log.With().Str("provider", "nomad").Logger(), logger: log.With().Str("provider", "nomad").Logger(),
imageDefaults: imageDefaults, defaults: defaults,
}, },
} }
} }

View File

@@ -101,7 +101,7 @@ func (c *Client) listTaskImages() []model.Image {
c.logger.Error().Err(err).Msg("Cannot merge task metadata") c.logger.Error().Err(err).Msg("Cannot merge task metadata")
} }
image, err := provider.ValidateImage(imageName, metadata(job, taskGroup, task), labels, *c.config.WatchByDefault, c.imageDefaults) image, err := provider.ValidateImage(imageName, metadata(job, taskGroup, task), labels, *c.config.WatchByDefault, c.defaults)
if err != nil { if err != nil {
c.logger.Error(). c.logger.Error().
Err(err). Err(err).

View File

@@ -37,7 +37,7 @@ func (c *Client) listServiceImage() []model.Image {
Str("ctn_image", svc.Spec.TaskTemplate.ContainerSpec.Image). Str("ctn_image", svc.Spec.TaskTemplate.ContainerSpec.Image).
Msg("Validate image") Msg("Validate image")
image, err := provider.ValidateImage(svc.Spec.TaskTemplate.ContainerSpec.Image, metadata(svc), svc.Spec.Labels, *c.config.WatchByDefault, c.imageDefaults) image, err := provider.ValidateImage(svc.Spec.TaskTemplate.ContainerSpec.Image, metadata(svc), svc.Spec.Labels, *c.config.WatchByDefault, c.defaults)
if err != nil { if err != nil {
c.logger.Error().Err(err). c.logger.Error().Err(err).
Str("svc_name", svc.Spec.Name). Str("svc_name", svc.Spec.Name).

View File

@@ -10,18 +10,18 @@ import (
// Client represents an active swarm provider object // Client represents an active swarm provider object
type Client struct { type Client struct {
*provider.Client *provider.Client
config *model.PrdSwarm config *model.PrdSwarm
logger zerolog.Logger logger zerolog.Logger
imageDefaults *model.ImageDefaults defaults *model.Defaults
} }
// New creates new swarm provider instance // New creates new swarm provider instance
func New(config *model.PrdSwarm, imageDefaults *model.ImageDefaults) *provider.Client { func New(config *model.PrdSwarm, defaults *model.Defaults) *provider.Client {
return &provider.Client{ return &provider.Client{
Handler: &Client{ Handler: &Client{
config: config, config: config,
logger: log.With().Str("provider", "swarm").Logger(), logger: log.With().Str("provider", "swarm").Logger(),
imageDefaults: imageDefaults, defaults: defaults,
}, },
} }
} }

View File

@@ -1,11 +1,12 @@
watch: watch:
workers: 20 workers: 20
schedule: "0 */6 * * *" schedule: "0 */6 * * *"
imageDefaults:
watchRepo: true defaults:
notifyOn: watchRepo: true
- new notifyOn:
maxTags: 5 - new
maxTags: 5
providers: providers:
docker: {} docker: {}