Merge pull request #1042 from aledbf/custom-status
Add function to allow custom values in Ingress status
This commit is contained in:
commit
65e8cecbac
6 changed files with 39 additions and 4 deletions
|
@ -35,6 +35,7 @@ import (
|
||||||
|
|
||||||
proxyproto "github.com/armon/go-proxyproto"
|
proxyproto "github.com/armon/go-proxyproto"
|
||||||
api_v1 "k8s.io/api/core/v1"
|
api_v1 "k8s.io/api/core/v1"
|
||||||
|
extensions "k8s.io/api/extensions/v1beta1"
|
||||||
|
|
||||||
"k8s.io/ingress/controllers/nginx/pkg/config"
|
"k8s.io/ingress/controllers/nginx/pkg/config"
|
||||||
ngx_template "k8s.io/ingress/controllers/nginx/pkg/template"
|
ngx_template "k8s.io/ingress/controllers/nginx/pkg/template"
|
||||||
|
@ -373,6 +374,11 @@ func (n *NGINXController) SetListers(lister ingress.StoreLister) {
|
||||||
n.storeLister = lister
|
n.storeLister = lister
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateIngressStatus custom Ingress status update
|
||||||
|
func (n *NGINXController) UpdateIngressStatus(*extensions.Ingress) []api_v1.LoadBalancerIngress {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// OnUpdate is called by syncQueue in https://github.com/aledbf/ingress-controller/blob/master/pkg/ingress/controller/controller.go#L82
|
// OnUpdate is called by syncQueue in https://github.com/aledbf/ingress-controller/blob/master/pkg/ingress/controller/controller.go#L82
|
||||||
// periodically to keep the configuration in sync.
|
// periodically to keep the configuration in sync.
|
||||||
//
|
//
|
||||||
|
|
|
@ -299,6 +299,7 @@ func newIngressController(config *Configuration) *GenericController {
|
||||||
IngressClass: config.IngressClass,
|
IngressClass: config.IngressClass,
|
||||||
DefaultIngressClass: config.DefaultIngressClass,
|
DefaultIngressClass: config.DefaultIngressClass,
|
||||||
UpdateStatusOnShutdown: config.UpdateStatusOnShutdown,
|
UpdateStatusOnShutdown: config.UpdateStatusOnShutdown,
|
||||||
|
CustomIngressStatus: ic.cfg.Backend.UpdateIngressStatus,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
glog.Warning("Update of ingress status is disabled (flag --update-status=false was specified)")
|
glog.Warning("Update of ingress status is disabled (flag --update-status=false was specified)")
|
||||||
|
|
|
@ -66,6 +66,9 @@ type Config struct {
|
||||||
|
|
||||||
DefaultIngressClass string
|
DefaultIngressClass string
|
||||||
IngressClass string
|
IngressClass string
|
||||||
|
|
||||||
|
// CustomIngressStatus allows to set custom values in Ingress status
|
||||||
|
CustomIngressStatus func(*extensions.Ingress) []v1.LoadBalancerIngress
|
||||||
}
|
}
|
||||||
|
|
||||||
// statusSync keeps the status IP in each Ingress rule updated executing a periodic check
|
// statusSync keeps the status IP in each Ingress rule updated executing a periodic check
|
||||||
|
@ -315,7 +318,10 @@ func sliceToStatus(endpoints []string) []v1.LoadBalancerIngress {
|
||||||
return lbi
|
return lbi
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *statusSync) updateStatus(newIPs []v1.LoadBalancerIngress) {
|
// updateStatus changes the status information of Ingress rules
|
||||||
|
// If the backend function CustomIngressStatus returns a value different
|
||||||
|
// of nil then it uses the returned value or the newIngressPoint values
|
||||||
|
func (s *statusSync) updateStatus(newIngressPoint []v1.LoadBalancerIngress) {
|
||||||
ings := s.IngressLister.List()
|
ings := s.IngressLister.List()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(ings))
|
wg.Add(len(ings))
|
||||||
|
@ -336,15 +342,21 @@ func (s *statusSync) updateStatus(newIPs []v1.LoadBalancerIngress) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addrs := newIngressPoint
|
||||||
|
ca := s.CustomIngressStatus(currIng)
|
||||||
|
if ca != nil {
|
||||||
|
addrs = ca
|
||||||
|
}
|
||||||
|
|
||||||
curIPs := currIng.Status.LoadBalancer.Ingress
|
curIPs := currIng.Status.LoadBalancer.Ingress
|
||||||
sort.Sort(loadBalancerIngressByIP(curIPs))
|
sort.Sort(loadBalancerIngressByIP(curIPs))
|
||||||
if ingressSliceEqual(newIPs, curIPs) {
|
if ingressSliceEqual(addrs, curIPs) {
|
||||||
glog.V(3).Infof("skipping update of Ingress %v/%v (no change)", currIng.Namespace, currIng.Name)
|
glog.V(3).Infof("skipping update of Ingress %v/%v (no change)", currIng.Namespace, currIng.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("updating Ingress %v/%v status to %v", currIng.Namespace, currIng.Name, newIPs)
|
glog.Infof("updating Ingress %v/%v status to %v", currIng.Namespace, currIng.Name, addrs)
|
||||||
currIng.Status.LoadBalancer.Ingress = newIPs
|
currIng.Status.LoadBalancer.Ingress = addrs
|
||||||
_, err = ingClient.UpdateStatus(currIng)
|
_, err = ingClient.UpdateStatus(currIng)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("error updating ingress rule: %v", err)
|
glog.Warningf("error updating ingress rule: %v", err)
|
||||||
|
|
|
@ -251,6 +251,9 @@ func buildStatusSync() statusSync {
|
||||||
Client: buildSimpleClientSet(),
|
Client: buildSimpleClientSet(),
|
||||||
PublishService: api_v1.NamespaceDefault + "/" + "foo",
|
PublishService: api_v1.NamespaceDefault + "/" + "foo",
|
||||||
IngressLister: buildIngressListener(),
|
IngressLister: buildIngressListener(),
|
||||||
|
CustomIngressStatus: func(*extensions.Ingress) []api_v1.LoadBalancerIngress {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,6 +269,9 @@ func TestStatusActions(t *testing.T) {
|
||||||
DefaultIngressClass: "nginx",
|
DefaultIngressClass: "nginx",
|
||||||
IngressClass: "",
|
IngressClass: "",
|
||||||
UpdateStatusOnShutdown: true,
|
UpdateStatusOnShutdown: true,
|
||||||
|
CustomIngressStatus: func(*extensions.Ingress) []api_v1.LoadBalancerIngress {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
// create object
|
// create object
|
||||||
fkSync := NewStatusSyncer(c)
|
fkSync := NewStatusSyncer(c)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
api "k8s.io/api/core/v1"
|
api "k8s.io/api/core/v1"
|
||||||
|
extensions "k8s.io/api/extensions/v1beta1"
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
"k8s.io/apiserver/pkg/server/healthz"
|
"k8s.io/apiserver/pkg/server/healthz"
|
||||||
|
|
||||||
|
@ -92,6 +93,10 @@ type Controller interface {
|
||||||
OverrideFlags(*pflag.FlagSet)
|
OverrideFlags(*pflag.FlagSet)
|
||||||
// DefaultIngressClass just return the default ingress class
|
// DefaultIngressClass just return the default ingress class
|
||||||
DefaultIngressClass() string
|
DefaultIngressClass() string
|
||||||
|
// UpdateIngressStatus custom callback used to update the status in an Ingress rule
|
||||||
|
// This allows custom implementations
|
||||||
|
// If the function returns nil the standard functions will be executed.
|
||||||
|
UpdateIngressStatus(*extensions.Ingress) []api.LoadBalancerIngress
|
||||||
}
|
}
|
||||||
|
|
||||||
// StoreLister returns the configured stores for ingresses, services,
|
// StoreLister returns the configured stores for ingresses, services,
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
api "k8s.io/api/core/v1"
|
api "k8s.io/api/core/v1"
|
||||||
|
extensions "k8s.io/api/extensions/v1beta1"
|
||||||
|
|
||||||
nginxconfig "k8s.io/ingress/controllers/nginx/pkg/config"
|
nginxconfig "k8s.io/ingress/controllers/nginx/pkg/config"
|
||||||
"k8s.io/ingress/core/pkg/ingress"
|
"k8s.io/ingress/core/pkg/ingress"
|
||||||
|
@ -105,3 +106,7 @@ func (n DummyController) SetListers(lister ingress.StoreLister) {
|
||||||
func (n DummyController) DefaultIngressClass() string {
|
func (n DummyController) DefaultIngressClass() string {
|
||||||
return "dummy"
|
return "dummy"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n DummyController) UpdateIngressStatus(*extensions.Ingress) []api.LoadBalancerIngress {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue