Merge pull request #118999 from cezarygerard/health-service
kube-proxy service health: add new header with number of local endpoints
This commit is contained in:
		@@ -21,13 +21,16 @@ import (
 | 
				
			|||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"net/http/httptest"
 | 
						"net/http/httptest"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/google/go-cmp/cmp"
 | 
				
			||||||
	"k8s.io/api/core/v1"
 | 
						"k8s.io/api/core/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/types"
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/dump"
 | 
						"k8s.io/apimachinery/pkg/util/dump"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/sets"
 | 
						"k8s.io/apimachinery/pkg/util/sets"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	proxyutil "k8s.io/kubernetes/pkg/proxy/util"
 | 
						proxyutil "k8s.io/kubernetes/pkg/proxy/util"
 | 
				
			||||||
	testingclock "k8s.io/utils/clock/testing"
 | 
						testingclock "k8s.io/utils/clock/testing"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -412,6 +415,15 @@ func tHandler(hcs *server, nsn types.NamespacedName, status int, endpoints int,
 | 
				
			|||||||
		if payload.ServiceProxyHealthy != kubeProxyHealthy {
 | 
							if payload.ServiceProxyHealthy != kubeProxyHealthy {
 | 
				
			||||||
			t.Errorf("expected %v kubeProxyHealthy, got %v", kubeProxyHealthy, payload.ServiceProxyHealthy)
 | 
								t.Errorf("expected %v kubeProxyHealthy, got %v", kubeProxyHealthy, payload.ServiceProxyHealthy)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if !cmp.Equal(resp.Header()["Content-Type"], []string{"application/json"}) {
 | 
				
			||||||
 | 
								t.Errorf("expected 'Content-Type: application/json' respose header, got: %v", resp.Header()["Content-Type"])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if !cmp.Equal(resp.Header()["X-Content-Type-Options"], []string{"nosniff"}) {
 | 
				
			||||||
 | 
								t.Errorf("expected 'X-Content-Type-Options: nosniff' respose header, got: %v", resp.Header()["X-Content-Type-Options"])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if !cmp.Equal(resp.Header()["X-Load-Balancing-Endpoint-Weight"], []string{strconv.Itoa(endpoints)}) {
 | 
				
			||||||
 | 
								t.Errorf("expected 'X-Load-Balancing-Endpoint-Weight: %d' respose header, got: %v", endpoints, resp.Header()["X-Load-Balancing-Endpoint-Weight"])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -233,6 +234,8 @@ func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	resp.Header().Set("Content-Type", "application/json")
 | 
						resp.Header().Set("Content-Type", "application/json")
 | 
				
			||||||
	resp.Header().Set("X-Content-Type-Options", "nosniff")
 | 
						resp.Header().Set("X-Content-Type-Options", "nosniff")
 | 
				
			||||||
 | 
						resp.Header().Set("X-Load-Balancing-Endpoint-Weight", strconv.Itoa(count))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if count != 0 && kubeProxyHealthy {
 | 
						if count != 0 && kubeProxyHealthy {
 | 
				
			||||||
		resp.WriteHeader(http.StatusOK)
 | 
							resp.WriteHeader(http.StatusOK)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user