-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingress_endpoints.go
66 lines (54 loc) · 1.74 KB
/
ingress_endpoints.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
package endpoints
import (
"strings"
workloadutil "github.com/rancher/rancher/pkg/controllers/user/workload"
"github.com/rancher/types/apis/extensions/v1beta1"
managementv3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
)
type IngressEndpointsController struct {
workloadController workloadutil.CommonController
ingressInterface v1beta1.IngressInterface
machinesLister managementv3.NodeLister
isRKE bool
clusterName string
}
func (c *IngressEndpointsController) sync(key string, obj *extensionsv1beta1.Ingress) error {
namespace := ""
if obj != nil {
namespace = obj.Namespace
} else {
split := strings.Split(key, "/")
if len(split) == 2 {
namespace = split[0]
}
}
c.workloadController.EnqueueAllWorkloads(namespace)
if obj == nil || obj.DeletionTimestamp != nil {
return nil
}
if _, err := c.reconcileEndpointsForIngress(obj); err != nil {
return err
}
return nil
}
func (c *IngressEndpointsController) reconcileEndpointsForIngress(obj *extensionsv1beta1.Ingress) (bool, error) {
fromObj := convertIngressToPublicEndpoints(obj, c.isRKE)
fromAnnotation := getPublicEndpointsFromAnnotations(obj.Annotations)
if areEqualEndpoints(fromAnnotation, fromObj) {
return false, nil
}
epsToUpdate, err := publicEndpointsToString(fromObj)
if err != nil {
return false, err
}
logrus.Infof("Updating ingress [%s:%s] with public endpoints [%v]", obj.Namespace, obj.Name, epsToUpdate)
toUpdate := obj.DeepCopy()
if toUpdate.Annotations == nil {
toUpdate.Annotations = make(map[string]string)
}
toUpdate.Annotations[endpointsAnnotation] = epsToUpdate
_, err = c.ingressInterface.Update(toUpdate)
return false, err
}