Fix diff execution
This commit is contained in:
parent
81dde562e9
commit
754cc6a665
5 changed files with 27 additions and 31 deletions
|
@ -58,9 +58,8 @@ func parseFlags() (bool, *controller.Configuration, error) {
|
||||||
`Name of the ConfigMap that contains the custom configuration to use`)
|
`Name of the ConfigMap that contains the custom configuration to use`)
|
||||||
|
|
||||||
publishSvc = flags.String("publish-service", "",
|
publishSvc = flags.String("publish-service", "",
|
||||||
`Service fronting the ingress controllers. Takes the form
|
`Service fronting the ingress controllers. Takes the form namespace/name.
|
||||||
namespace/name. The controller will set the endpoint records on the
|
The controller will set the endpoint records on the ingress objects to reflect those on the service.`)
|
||||||
ingress objects to reflect those on the service.`)
|
|
||||||
|
|
||||||
tcpConfigMapName = flags.String("tcp-services-configmap", "",
|
tcpConfigMapName = flags.String("tcp-services-configmap", "",
|
||||||
`Name of the ConfigMap that contains the definition of the TCP services to expose.
|
`Name of the ConfigMap that contains the definition of the TCP services to expose.
|
||||||
|
|
|
@ -121,13 +121,13 @@ func NewNGINXController(config *Configuration) *NGINXController {
|
||||||
if config.UpdateStatus {
|
if config.UpdateStatus {
|
||||||
n.syncStatus = status.NewStatusSyncer(status.Config{
|
n.syncStatus = status.NewStatusSyncer(status.Config{
|
||||||
Client: config.Client,
|
Client: config.Client,
|
||||||
PublishService: n.cfg.PublishService,
|
PublishService: config.PublishService,
|
||||||
IngressLister: n.listers.Ingress,
|
IngressLister: n.listers.Ingress,
|
||||||
ElectionID: config.ElectionID,
|
ElectionID: config.ElectionID,
|
||||||
IngressClass: config.IngressClass,
|
IngressClass: config.IngressClass,
|
||||||
DefaultIngressClass: config.DefaultIngressClass,
|
DefaultIngressClass: config.DefaultIngressClass,
|
||||||
UpdateStatusOnShutdown: config.UpdateStatusOnShutdown,
|
UpdateStatusOnShutdown: config.UpdateStatusOnShutdown,
|
||||||
UseNodeInternalIP: n.cfg.UseNodeInternalIP,
|
UseNodeInternalIP: config.UseNodeInternalIP,
|
||||||
})
|
})
|
||||||
} 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)")
|
||||||
|
@ -324,8 +324,7 @@ func (n *NGINXController) Stop() error {
|
||||||
|
|
||||||
// Wait for the Nginx process disappear
|
// Wait for the Nginx process disappear
|
||||||
timer := time.NewTicker(time.Second * 1)
|
timer := time.NewTicker(time.Second * 1)
|
||||||
for t := range timer.C {
|
for _ = range timer.C {
|
||||||
glog.V(3).Infof("tick at", t)
|
|
||||||
if !process.IsNginxRunning() {
|
if !process.IsNginxRunning() {
|
||||||
glog.Info("NGINX process has stopped")
|
glog.Info("NGINX process has stopped")
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
|
@ -632,10 +631,8 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
diffOutput, err := exec.Command("diff", "-u", cfgPath, tmpfile.Name()).CombinedOutput()
|
// executing diff can return exit code != 0
|
||||||
if err != nil {
|
diffOutput, _ := exec.Command("diff", "-u", cfgPath, tmpfile.Name()).CombinedOutput()
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.Infof("NGINX configuration diff\n")
|
glog.Infof("NGINX configuration diff\n")
|
||||||
glog.Infof("%v\n", string(diffOutput))
|
glog.Infof("%v\n", string(diffOutput))
|
||||||
|
|
|
@ -234,6 +234,8 @@ func NewStatusSyncer(config Config) Sync {
|
||||||
// runningAddresses returns a list of IP addresses and/or FQDN where the
|
// runningAddresses returns a list of IP addresses and/or FQDN where the
|
||||||
// ingress controller is currently running
|
// ingress controller is currently running
|
||||||
func (s *statusSync) runningAddresses() ([]string, error) {
|
func (s *statusSync) runningAddresses() ([]string, error) {
|
||||||
|
addrs := []string{}
|
||||||
|
|
||||||
if s.PublishService != "" {
|
if s.PublishService != "" {
|
||||||
ns, name, _ := k8s.ParseNameNS(s.PublishService)
|
ns, name, _ := k8s.ParseNameNS(s.PublishService)
|
||||||
svc, err := s.Client.CoreV1().Services(ns).Get(name, metav1.GetOptions{})
|
svc, err := s.Client.CoreV1().Services(ns).Get(name, metav1.GetOptions{})
|
||||||
|
@ -241,7 +243,6 @@ func (s *statusSync) runningAddresses() ([]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs := []string{}
|
|
||||||
for _, ip := range svc.Status.LoadBalancer.Ingress {
|
for _, ip := range svc.Status.LoadBalancer.Ingress {
|
||||||
if ip.IP == "" {
|
if ip.IP == "" {
|
||||||
addrs = append(addrs, ip.Hostname)
|
addrs = append(addrs, ip.Hostname)
|
||||||
|
@ -251,7 +252,6 @@ func (s *statusSync) runningAddresses() ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs = append(addrs, svc.Spec.ExternalIPs...)
|
addrs = append(addrs, svc.Spec.ExternalIPs...)
|
||||||
|
|
||||||
return addrs, nil
|
return addrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,13 +263,13 @@ func (s *statusSync) runningAddresses() ([]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs := []string{}
|
|
||||||
for _, pod := range pods.Items {
|
for _, pod := range pods.Items {
|
||||||
name := k8s.GetNodeIP(s.Client, pod.Spec.NodeName, s.UseNodeInternalIP)
|
name := k8s.GetNodeIPOrName(s.Client, pod.Spec.NodeName, s.UseNodeInternalIP)
|
||||||
if !sliceutils.StringInSlice(name, addrs) {
|
if !sliceutils.StringInSlice(name, addrs) {
|
||||||
addrs = append(addrs, name)
|
addrs = append(addrs, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return addrs, nil
|
return addrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,13 +332,12 @@ func runUpdate(ing *extensions.Ingress, status []apiv1.LoadBalancerIngress,
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs := status
|
sort.SliceStable(status, lessLoadBalancerIngress(status))
|
||||||
sort.SliceStable(addrs, lessLoadBalancerIngress(addrs))
|
|
||||||
|
|
||||||
curIPs := ing.Status.LoadBalancer.Ingress
|
curIPs := ing.Status.LoadBalancer.Ingress
|
||||||
sort.SliceStable(curIPs, lessLoadBalancerIngress(curIPs))
|
sort.SliceStable(curIPs, lessLoadBalancerIngress(curIPs))
|
||||||
|
|
||||||
if ingressSliceEqual(addrs, curIPs) {
|
if ingressSliceEqual(status, curIPs) {
|
||||||
glog.V(3).Infof("skipping update of Ingress %v/%v (no change)", ing.Namespace, ing.Name)
|
glog.V(3).Infof("skipping update of Ingress %v/%v (no change)", ing.Namespace, ing.Name)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
@ -350,8 +349,8 @@ func runUpdate(ing *extensions.Ingress, status []apiv1.LoadBalancerIngress,
|
||||||
return nil, errors.Wrap(err, fmt.Sprintf("unexpected error searching Ingress %v/%v", ing.Namespace, ing.Name))
|
return nil, errors.Wrap(err, fmt.Sprintf("unexpected error searching Ingress %v/%v", ing.Namespace, ing.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("updating Ingress %v/%v status to %v", currIng.Namespace, currIng.Name, addrs)
|
glog.Infof("updating Ingress %v/%v status to %v", currIng.Namespace, currIng.Name, status)
|
||||||
currIng.Status.LoadBalancer.Ingress = addrs
|
currIng.Status.LoadBalancer.Ingress = status
|
||||||
_, 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)
|
||||||
|
|
|
@ -36,26 +36,27 @@ func ParseNameNS(input string) (string, string, error) {
|
||||||
return nsName[0], nsName[1], nil
|
return nsName[0], nsName[1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNodeIP returns the IP address of a node in the cluster
|
// GetNodeIPOrName returns the IP address or the name of a node in the cluster
|
||||||
func GetNodeIP(kubeClient clientset.Interface, name string, useInternalIP bool) string {
|
func GetNodeIPOrName(kubeClient clientset.Interface, name string, useInternalIP bool) string {
|
||||||
node, err := kubeClient.Core().Nodes().Get(name, metav1.GetOptions{})
|
node, err := kubeClient.Core().Nodes().Get(name, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, address := range node.Status.Addresses {
|
if useInternalIP {
|
||||||
if useInternalIP {
|
for _, address := range node.Status.Addresses {
|
||||||
if address.Type == apiv1.NodeInternalIP {
|
if address.Type == apiv1.NodeInternalIP {
|
||||||
if address.Address != "" {
|
if address.Address != "" {
|
||||||
return address.Address
|
return address.Address
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if address.Type == apiv1.NodeExternalIP {
|
for _, address := range node.Status.Addresses {
|
||||||
if address.Address != "" {
|
if address.Type == apiv1.NodeExternalIP {
|
||||||
return address.Address
|
if address.Address != "" {
|
||||||
|
return address.Address
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +92,7 @@ func GetPodDetails(kubeClient clientset.Interface) (*PodInfo, error) {
|
||||||
return &PodInfo{
|
return &PodInfo{
|
||||||
Name: podName,
|
Name: podName,
|
||||||
Namespace: podNs,
|
Namespace: podNs,
|
||||||
NodeIP: GetNodeIP(kubeClient, pod.Spec.NodeName, true),
|
NodeIP: GetNodeIPOrName(kubeClient, pod.Spec.NodeName, true),
|
||||||
Labels: pod.GetLabels(),
|
Labels: pod.GetLabels(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ func TestGetNodeIP(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fk := range fKNodes {
|
for _, fk := range fKNodes {
|
||||||
address := GetNodeIP(fk.cs, fk.n, fk.i)
|
address := GetNodeIPOrName(fk.cs, fk.n, fk.i)
|
||||||
if address != fk.ea {
|
if address != fk.ea {
|
||||||
t.Errorf("expected %s, but returned %s", fk.ea, address)
|
t.Errorf("expected %s, but returned %s", fk.ea, address)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue