-
Notifications
You must be signed in to change notification settings - Fork 69
/
status.go
77 lines (71 loc) · 2.4 KB
/
status.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) Red Hat, Inc.
// Copyright Contributors to the Open Cluster Management project
// Licensed under the Apache License 2.0
package placementrule
import (
"context"
"reflect"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
mcov1beta1 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta1"
"github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/pkg/util"
addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
)
var (
statusMap = map[string]string{
"Available": "Available",
"Progressing": "Progressing",
"Deployed": "Progressing",
"Disabled": "Degraded",
"Degraded": "Degraded",
"NotSupported": "Degraded",
}
)
func updateAddonStatus(c client.Client, addonList mcov1beta1.ObservabilityAddonList) error {
for _, addon := range addonList.Items {
if addon.Status.Conditions == nil || len(addon.Status.Conditions) == 0 {
continue
}
conditions := []metav1.Condition{}
for _, c := range addon.Status.Conditions {
condition := metav1.Condition{
Type: statusMap[c.Type],
Status: c.Status,
LastTransitionTime: c.LastTransitionTime,
Reason: c.Reason,
Message: c.Message,
}
conditions = append(conditions, condition)
}
managedclusteraddon := &addonv1alpha1.ManagedClusterAddOn{}
err := c.Get(context.TODO(), types.NamespacedName{
Name: util.ManagedClusterAddonName,
Namespace: addon.ObjectMeta.Namespace,
}, managedclusteraddon)
if err != nil {
if errors.IsNotFound(err) {
log.Info("managedclusteraddon does not exist", "namespace", addon.ObjectMeta.Namespace)
continue
}
log.Error(err, "Failed to get managedclusteraddon", "namespace", addon.ObjectMeta.Namespace)
return err
}
if !reflect.DeepEqual(conditions, managedclusteraddon.Status.Conditions) {
managedclusteraddon.Status.Conditions = conditions
err = c.Status().Update(context.TODO(), managedclusteraddon)
if err != nil {
log.Error(
err,
"Failed to update status for managedclusteraddon",
"namespace",
addon.ObjectMeta.Namespace,
)
return err
}
log.Info("Updated status for managedclusteraddon", "namespace", addon.ObjectMeta.Namespace)
}
}
return nil
}