forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_handler.go
53 lines (46 loc) · 1.42 KB
/
cluster_handler.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
package istio
import (
"github.com/rancher/norman/controller"
"github.com/rancher/rancher/pkg/project"
mgmtv3 "github.com/rancher/types/apis/management.cattle.io/v3"
v3 "github.com/rancher/types/apis/project.cattle.io/v3"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
)
type clusterHandler struct {
clusterName string
appLister v3.AppLister
clusterInterface mgmtv3.ClusterInterface
projectLister mgmtv3.ProjectLister
}
func (h *clusterHandler) sync(key string, obj *mgmtv3.Cluster) (runtime.Object, error) {
if obj == nil || obj.DeletionTimestamp != nil || obj.Name != h.clusterName {
return obj, nil
}
if !mgmtv3.ClusterConditionconditionSystemProjectCreated.IsTrue(obj) {
return obj, nil
}
enabled, err := h.getIstioAppEnabled()
if err != nil {
return obj, &controller.ForgetError{Err: err, Reason: "Failed to find istio app"}
}
if obj.Status.IstioEnabled == enabled {
return obj, nil
}
newCluster := obj.DeepCopy()
newCluster.Status.IstioEnabled = enabled
return h.clusterInterface.Update(newCluster)
}
func (h *clusterHandler) getIstioAppEnabled() (bool, error) {
p, err := project.GetSystemProject(h.clusterName, h.projectLister)
if err != nil {
return false, err
}
app, err := h.appLister.Get(p.Name, istioAppName)
if errors.IsNotFound(err) || app.DeletionTimestamp != nil {
return false, nil
} else if err != nil {
return false, err
}
return true, nil
}