@@ -18,19 +18,25 @@ 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.Image ) (img model.Image , err error ) {
21+ func ValidateImage (image string , metadata , labels map [string ]string , watchByDef bool , imageDefaults * model.ImageDefaults ) (img model.Image , err error ) {
2222 img = model.Image {
2323 Name : image ,
2424 }
2525
26- if err := mergo .Merge (& img , imageDefaults ); err != nil {
27- return img , & invalidLabelError {errors .Wrapf (err , "failed to merge image defaults for image %s" , image )}
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
2834 }
2935
3036 if enableStr , ok := labels ["diun.enable" ]; ok {
3137 enable , err := strconv .ParseBool (enableStr )
3238 if err != nil {
33- return img , & invalidLabelError { errors .Wrapf (err , "cannot parse %q value of label diun.enable" , enableStr )}
39+ return img , errors .Wrapf (err , "cannot parse %q value of label diun.enable" , enableStr )
3440 }
3541 if ! enable {
3642 return model.Image {}, nil
@@ -47,7 +53,7 @@ func ValidateImage(image string, metadata, labels map[string]string, watchByDef
4753 if watchRepo , err := strconv .ParseBool (value ); err == nil {
4854 img .WatchRepo = & watchRepo
4955 } else {
50- return img , & invalidLabelError { errors .Wrapf (err , "cannot parse %q value of label %s" , value , key )}
56+ return img , errors .Wrapf (err , "cannot parse %q value of label %s" , value , key )
5157 }
5258 case key == "diun.notify_on" :
5359 if len (value ) == 0 {
@@ -57,7 +63,7 @@ func ValidateImage(image string, metadata, labels map[string]string, watchByDef
5763 for _ , no := range strings .Split (value , ";" ) {
5864 notifyOn := model .NotifyOn (no )
5965 if ! notifyOn .Valid () {
60- return img , & invalidLabelError { errors .Errorf ("unknown notify status %q" , value )}
66+ return img , errors .Errorf ("unknown notify status %q" , value )
6167 }
6268 img .NotifyOn = append (img .NotifyOn , notifyOn )
6369 }
@@ -67,12 +73,12 @@ func ValidateImage(image string, metadata, labels map[string]string, watchByDef
6773 }
6874 sortTags := registry .SortTag (value )
6975 if ! sortTags .Valid () {
70- return img , & invalidLabelError { errors .Errorf ("unknown sort tags type %q" , value )}
76+ return img , errors .Errorf ("unknown sort tags type %q" , value )
7177 }
7278 img .SortTags = sortTags
7379 case key == "diun.max_tags" :
7480 if img .MaxTags , err = strconv .Atoi (value ); err != nil {
75- return img , & invalidLabelError { errors .Wrapf (err , "cannot parse %q value of label %s" , value , key )}
81+ return img , errors .Wrapf (err , "cannot parse %q value of label %s" , value , key )
7682 }
7783 case key == "diun.include_tags" :
7884 img .IncludeTags = strings .Split (value , ";" )
@@ -85,7 +91,7 @@ func ValidateImage(image string, metadata, labels map[string]string, watchByDef
8591 case key == "diun.platform" :
8692 platform , err := platforms .Parse (value )
8793 if err != nil {
88- return img , & invalidLabelError { errors .Wrapf (err , "cannot parse %q platform of label %s" , value , key )}
94+ return img , errors .Wrapf (err , "cannot parse %q platform of label %s" , value , key )
8995 }
9096 img .Platform = model.ImagePlatform {
9197 OS : platform .OS ,
@@ -98,7 +104,7 @@ func ValidateImage(image string, metadata, labels map[string]string, watchByDef
98104 break
99105 }
100106 if err := validateMetadataKey (mkey ); err != nil {
101- return img , & invalidLabelError { errors .Wrapf (err , "invalid metadata key %q" , mkey )}
107+ return img , errors .Wrapf (err , "invalid metadata key %q" , mkey )
102108 }
103109 if img .Metadata == nil {
104110 img .Metadata = map [string ]string {}
@@ -121,15 +127,3 @@ func validateMetadataKey(key string) error {
121127 }
122128 return nil
123129}
124-
125- type invalidLabelError struct {
126- error
127- }
128-
129- func (e * invalidLabelError ) Error () string {
130- return e .Error ()
131- }
132-
133- func (e * invalidLabelError ) Unwrap () error {
134- return e
135- }
0 commit comments