-
Notifications
You must be signed in to change notification settings - Fork 53
/
image.go
40 lines (37 loc) · 1.01 KB
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package monitoring
import (
"github.com/rancher/opni/pkg/resources"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func (r *Reconciler) updateImageStatus() (bool, error) {
lg := r.logger
var image string
var pullPolicy corev1.PullPolicy
if imgOverride := r.mc.Spec.Cortex.Image.GetImageWithDefault(""); imgOverride != "" {
image = imgOverride
} else {
var err error
image, pullPolicy, err = resources.FindManagerImage(r.ctx, r.client)
if err != nil {
return false, err
}
}
if r.mc.Status.Image != image {
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
if err := r.client.Get(r.ctx, client.ObjectKeyFromObject(r.mc), r.mc); err != nil {
return err
}
r.mc.Status.Image = image
r.mc.Status.ImagePullPolicy = pullPolicy
return r.client.Status().Update(r.ctx, r.mc)
})
if err != nil {
lg.Error(err, "failed to update monitoring cluster status")
return false, err
}
return true, nil
}
return false, nil
}