Fix diff execution

This commit is contained in:
Manuel de Brito Fontes 2017-11-05 22:22:49 -03:00
parent 81dde562e9
commit 754cc6a665
5 changed files with 27 additions and 31 deletions

View file

@ -58,9 +58,8 @@ func parseFlags() (bool, *controller.Configuration, error) {
`Name of the ConfigMap that contains the custom configuration to use`)
publishSvc = flags.String("publish-service", "",
`Service fronting the ingress controllers. Takes the form
namespace/name. The controller will set the endpoint records on the
ingress objects to reflect those on the service.`)
`Service fronting the ingress controllers. Takes the form namespace/name.
The controller will set the endpoint records on the ingress objects to reflect those on the service.`)
tcpConfigMapName = flags.String("tcp-services-configmap", "",
`Name of the ConfigMap that contains the definition of the TCP services to expose.

View file

@ -121,13 +121,13 @@ func NewNGINXController(config *Configuration) *NGINXController {
if config.UpdateStatus {
n.syncStatus = status.NewStatusSyncer(status.Config{
Client: config.Client,
PublishService: n.cfg.PublishService,
PublishService: config.PublishService,
IngressLister: n.listers.Ingress,
ElectionID: config.ElectionID,
IngressClass: config.IngressClass,
DefaultIngressClass: config.DefaultIngressClass,
UpdateStatusOnShutdown: config.UpdateStatusOnShutdown,
UseNodeInternalIP: n.cfg.UseNodeInternalIP,
UseNodeInternalIP: config.UseNodeInternalIP,
})
} else {
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
timer := time.NewTicker(time.Second * 1)
for t := range timer.C {
glog.V(3).Infof("tick at", t)
for _ = range timer.C {
if !process.IsNginxRunning() {
glog.Info("NGINX process has stopped")
timer.Stop()
@ -632,10 +631,8 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
return err
}
diffOutput, err := exec.Command("diff", "-u", cfgPath, tmpfile.Name()).CombinedOutput()
if err != nil {
return err
}
// executing diff can return exit code != 0
diffOutput, _ := exec.Command("diff", "-u", cfgPath, tmpfile.Name()).CombinedOutput()
glog.Infof("NGINX configuration diff\n")
glog.Infof("%v\n", string(diffOutput))

View file

@ -234,6 +234,8 @@ func NewStatusSyncer(config Config) Sync {
// runningAddresses returns a list of IP addresses and/or FQDN where the
// ingress controller is currently running
func (s *statusSync) runningAddresses() ([]string, error) {
addrs := []string{}
if s.PublishService != "" {
ns, name, _ := k8s.ParseNameNS(s.PublishService)
svc, err := s.Client.CoreV1().Services(ns).Get(name, metav1.GetOptions{})
@ -241,7 +243,6 @@ func (s *statusSync) runningAddresses() ([]string, error) {
return nil, err
}
addrs := []string{}
for _, ip := range svc.Status.LoadBalancer.Ingress {
if ip.IP == "" {
addrs = append(addrs, ip.Hostname)
@ -251,7 +252,6 @@ func (s *statusSync) runningAddresses() ([]string, error) {
}
addrs = append(addrs, svc.Spec.ExternalIPs...)
return addrs, nil
}
@ -263,13 +263,13 @@ func (s *statusSync) runningAddresses() ([]string, error) {
return nil, err
}
addrs := []string{}
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) {
addrs = append(addrs, name)
}
}
return addrs, nil
}
@ -332,13 +332,12 @@ func runUpdate(ing *extensions.Ingress, status []apiv1.LoadBalancerIngress,
return nil, nil
}
addrs := status
sort.SliceStable(addrs, lessLoadBalancerIngress(addrs))
sort.SliceStable(status, lessLoadBalancerIngress(status))
curIPs := ing.Status.LoadBalancer.Ingress
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)
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))
}
glog.Infof("updating Ingress %v/%v status to %v", currIng.Namespace, currIng.Name, addrs)
currIng.Status.LoadBalancer.Ingress = addrs
glog.Infof("updating Ingress %v/%v status to %v", currIng.Namespace, currIng.Name, status)
currIng.Status.LoadBalancer.Ingress = status
_, err = ingClient.UpdateStatus(currIng)
if err != nil {
glog.Warningf("error updating ingress rule: %v", err)

View file

@ -36,26 +36,27 @@ func ParseNameNS(input string) (string, string, error) {
return nsName[0], nsName[1], nil
}
// GetNodeIP returns the IP address of a node in the cluster
func GetNodeIP(kubeClient clientset.Interface, name string, useInternalIP bool) string {
// GetNodeIPOrName returns the IP address or the name of a node in the cluster
func GetNodeIPOrName(kubeClient clientset.Interface, name string, useInternalIP bool) string {
node, err := kubeClient.Core().Nodes().Get(name, metav1.GetOptions{})
if err != nil {
return ""
}
for _, address := range node.Status.Addresses {
if useInternalIP {
if useInternalIP {
for _, address := range node.Status.Addresses {
if address.Type == apiv1.NodeInternalIP {
if address.Address != "" {
return address.Address
}
}
continue
}
if address.Type == apiv1.NodeExternalIP {
if address.Address != "" {
return address.Address
} else {
for _, address := range node.Status.Addresses {
if address.Type == apiv1.NodeExternalIP {
if address.Address != "" {
return address.Address
}
}
}
}
@ -91,7 +92,7 @@ func GetPodDetails(kubeClient clientset.Interface) (*PodInfo, error) {
return &PodInfo{
Name: podName,
Namespace: podNs,
NodeIP: GetNodeIP(kubeClient, pod.Spec.NodeName, true),
NodeIP: GetNodeIPOrName(kubeClient, pod.Spec.NodeName, true),
Labels: pod.GetLabels(),
}, nil
}

View file

@ -164,7 +164,7 @@ func TestGetNodeIP(t *testing.T) {
}
for _, fk := range fKNodes {
address := GetNodeIP(fk.cs, fk.n, fk.i)
address := GetNodeIPOrName(fk.cs, fk.n, fk.i)
if address != fk.ea {
t.Errorf("expected %s, but returned %s", fk.ea, address)
}