@@ -57,10 +57,25 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
57
57
58
58
image , err := k .Image ().Get (ctx , e .Data ()["namespace" ].(string ), e .Data ()["image" ].(string ))
59
59
defer func () {
60
+ // Add delay to avoid conflicts
61
+ time .Sleep (500 * time .Millisecond )
62
+
60
63
// update the status of the image
61
64
image .SetStatusTime (time .Now ().Format (time .RFC3339 ))
62
- err := k .Image ().UpdateStatus (ctx , image )
65
+
66
+ // Need to get image again to avoid conflicts
67
+ imageRefreshed , err := k .Image ().Get (ctx , e .Data ()["namespace" ].(string ), e .Data ()["image" ].(string ))
63
68
if err != nil {
69
+ log .WithError (err ).
70
+ WithFields (log.Fields {
71
+ "Namespace" : e .Data ()["namespace" ],
72
+ "Image" : e .Data ()["image" ],
73
+ }).Error ("Error getting image" )
74
+ return
75
+ }
76
+ imageRefreshed .Status = image .Status
77
+
78
+ if err := k .Image ().UpdateStatus (ctx , imageRefreshed ); err != nil {
64
79
log .WithError (err ).
65
80
WithFields (log.Fields {
66
81
"Namespace" : e .Data ()["namespace" ],
@@ -77,6 +92,9 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
77
92
}
78
93
k .Image ().Event (& image , corev1 .EventTypeNormal , "Image update triggered" , "" )
79
94
95
+ // Set Status to Scheduled permit in the execution of the refresh if the image have a error or not
96
+ image .SetStatusResult (v1alpha1 .ImageStatusLastSyncScheduled )
97
+
80
98
var auths kubeclient.K8sDockerRegistrySecretData
81
99
82
100
if image .Spec .ImagePullSecrets != nil {
@@ -125,6 +143,7 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
125
143
if err != nil {
126
144
// Prometheus metrics - Increment the counter for the tags with error
127
145
metrics .Tags ().RequestErrorTotal .Inc ()
146
+ image .SetStatusResult (v1alpha1 .ImageStatusLastSyncErrorTags )
128
147
k .Image ().Event (& image , corev1 .EventTypeWarning , "Fetch image tags" , fmt .Sprintf ("Error fetching tags: %v" , err ))
129
148
log .WithError (err ).Error ("Error fetching tags" )
130
149
return err
@@ -173,8 +192,9 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
173
192
if match {
174
193
for _ , action := range rule .Actions {
175
194
a , err := actions .GetActionWithUntypedName (action .Type )
176
- image .SetStatusResult (v1alpha1 .ImageStatusLastSyncErrorAction )
177
195
if err != nil {
196
+ image .SetStatusResult (v1alpha1 .ImageStatusLastSyncErrorAction )
197
+ k .Image ().Event (& image , corev1 .EventTypeWarning , "Get action" , fmt .Sprintf ("Error getting action %s: %v" , action .Type , err ))
178
198
log .Errorf ("Error getting action: %v" , err )
179
199
continue
180
200
}
@@ -208,7 +228,9 @@ func initScheduler(ctx context.Context, k kubeclient.Interface) {
208
228
}
209
229
}
210
230
211
- image .SetStatusResult (v1alpha1 .ImageStatusLastSyncSuccess )
231
+ if image .Status .Result == v1alpha1 .ImageStatusLastSyncScheduled {
232
+ image .SetStatusResult (v1alpha1 .ImageStatusLastSyncSuccess )
233
+ }
212
234
return k .Image ().Update (ctx , image )
213
235
})
214
236
0 commit comments