delete upstream healthcheck annotation
This commit is contained in:
parent
9cf4f9e7ae
commit
78f12c25c5
16 changed files with 25 additions and 481 deletions
|
|
@ -33,7 +33,6 @@ import (
|
|||
clientset "k8s.io/client-go/kubernetes"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/healthcheck"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/proxy"
|
||||
ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config"
|
||||
"k8s.io/ingress-nginx/internal/k8s"
|
||||
|
|
@ -237,7 +236,7 @@ func (n *NGINXController) getDefaultUpstream() *ingress.Backend {
|
|||
return upstream
|
||||
}
|
||||
|
||||
endps := getEndpoints(svc, &svc.Spec.Ports[0], apiv1.ProtocolTCP, &healthcheck.Config{}, n.store.GetServiceEndpoints)
|
||||
endps := getEndpoints(svc, &svc.Spec.Ports[0], apiv1.ProtocolTCP, n.store.GetServiceEndpoints)
|
||||
if len(endps) == 0 {
|
||||
glog.Warningf("Service %q does not have any active Endpoint", svcKey)
|
||||
endps = []ingress.Endpoint{n.DefaultEndpoint()}
|
||||
|
|
@ -434,7 +433,7 @@ func (n *NGINXController) getBackendServers(ingresses []*extensions.Ingress) ([]
|
|||
// check if the location contains endpoints and a custom default backend
|
||||
if location.DefaultBackend != nil {
|
||||
sp := location.DefaultBackend.Spec.Ports[0]
|
||||
endps := getEndpoints(location.DefaultBackend, &sp, apiv1.ProtocolTCP, &healthcheck.Config{}, n.store.GetServiceEndpoints)
|
||||
endps := getEndpoints(location.DefaultBackend, &sp, apiv1.ProtocolTCP, n.store.GetServiceEndpoints)
|
||||
if len(endps) > 0 {
|
||||
glog.V(3).Infof("Using custom default backend for location %q in server %q (Service \"%v/%v\")",
|
||||
location.Path, server.Hostname, location.DefaultBackend.Namespace, location.DefaultBackend.Name)
|
||||
|
|
@ -544,7 +543,7 @@ func (n *NGINXController) createUpstreams(data []*extensions.Ingress, du *ingres
|
|||
}
|
||||
|
||||
if len(upstreams[defBackend].Endpoints) == 0 {
|
||||
endps, err := n.serviceEndpoints(svcKey, ing.Spec.Backend.ServicePort.String(), &anns.HealthCheck)
|
||||
endps, err := n.serviceEndpoints(svcKey, ing.Spec.Backend.ServicePort.String())
|
||||
upstreams[defBackend].Endpoints = append(upstreams[defBackend].Endpoints, endps...)
|
||||
if err != nil {
|
||||
glog.Warningf("Error creating upstream %q: %v", defBackend, err)
|
||||
|
|
@ -597,7 +596,7 @@ func (n *NGINXController) createUpstreams(data []*extensions.Ingress, du *ingres
|
|||
}
|
||||
|
||||
if len(upstreams[name].Endpoints) == 0 {
|
||||
endp, err := n.serviceEndpoints(svcKey, path.Backend.ServicePort.String(), &anns.HealthCheck)
|
||||
endp, err := n.serviceEndpoints(svcKey, path.Backend.ServicePort.String())
|
||||
if err != nil {
|
||||
glog.Warningf("Error obtaining Endpoints for Service %q: %v", svcKey, err)
|
||||
continue
|
||||
|
|
@ -654,10 +653,8 @@ func (n *NGINXController) getServiceClusterEndpoint(svcKey string, backend *exte
|
|||
return endpoint, err
|
||||
}
|
||||
|
||||
// serviceEndpoints returns the upstream servers (Endpoints) associated with a
|
||||
// Service.
|
||||
func (n *NGINXController) serviceEndpoints(svcKey, backendPort string,
|
||||
hz *healthcheck.Config) ([]ingress.Endpoint, error) {
|
||||
// serviceEndpoints returns the upstream servers (Endpoints) associated with a Service.
|
||||
func (n *NGINXController) serviceEndpoints(svcKey, backendPort string) ([]ingress.Endpoint, error) {
|
||||
svc, err := n.store.GetService(svcKey)
|
||||
|
||||
var upstreams []ingress.Endpoint
|
||||
|
|
@ -672,7 +669,7 @@ func (n *NGINXController) serviceEndpoints(svcKey, backendPort string,
|
|||
servicePort.TargetPort.String() == backendPort ||
|
||||
servicePort.Name == backendPort {
|
||||
|
||||
endps := getEndpoints(svc, &servicePort, apiv1.ProtocolTCP, hz, n.store.GetServiceEndpoints)
|
||||
endps := getEndpoints(svc, &servicePort, apiv1.ProtocolTCP, n.store.GetServiceEndpoints)
|
||||
if len(endps) == 0 {
|
||||
glog.Warningf("Service %q does not have any active Endpoint.", svcKey)
|
||||
}
|
||||
|
|
@ -706,7 +703,7 @@ func (n *NGINXController) serviceEndpoints(svcKey, backendPort string,
|
|||
Port: int32(externalPort),
|
||||
TargetPort: intstr.FromString(backendPort),
|
||||
}
|
||||
endps := getEndpoints(svc, &servicePort, apiv1.ProtocolTCP, hz, n.store.GetServiceEndpoints)
|
||||
endps := getEndpoints(svc, &servicePort, apiv1.ProtocolTCP, n.store.GetServiceEndpoints)
|
||||
if len(endps) == 0 {
|
||||
glog.Warningf("Service %q does not have any active Endpoint.", svcKey)
|
||||
return upstreams, nil
|
||||
|
|
|
|||
|
|
@ -27,12 +27,11 @@ import (
|
|||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/healthcheck"
|
||||
"k8s.io/ingress-nginx/internal/k8s"
|
||||
)
|
||||
|
||||
// getEndpoints returns a list of Endpoint structs for a given service/target port combination.
|
||||
func getEndpoints(s *corev1.Service, port *corev1.ServicePort, proto corev1.Protocol, hz *healthcheck.Config,
|
||||
func getEndpoints(s *corev1.Service, port *corev1.ServicePort, proto corev1.Protocol,
|
||||
getServiceEndpoints func(string) (*corev1.Endpoints, error)) []ingress.Endpoint {
|
||||
|
||||
upsServers := []ingress.Endpoint{}
|
||||
|
|
@ -66,10 +65,8 @@ func getEndpoints(s *corev1.Service, port *corev1.ServicePort, proto corev1.Prot
|
|||
}
|
||||
|
||||
return append(upsServers, ingress.Endpoint{
|
||||
Address: s.Spec.ExternalName,
|
||||
Port: fmt.Sprintf("%v", targetPort),
|
||||
MaxFails: hz.MaxFails,
|
||||
FailTimeout: hz.FailTimeout,
|
||||
Address: s.Spec.ExternalName,
|
||||
Port: fmt.Sprintf("%v", targetPort),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -106,11 +103,9 @@ func getEndpoints(s *corev1.Service, port *corev1.ServicePort, proto corev1.Prot
|
|||
continue
|
||||
}
|
||||
ups := ingress.Endpoint{
|
||||
Address: epAddress.IP,
|
||||
Port: fmt.Sprintf("%v", targetPort),
|
||||
MaxFails: hz.MaxFails,
|
||||
FailTimeout: hz.FailTimeout,
|
||||
Target: epAddress.TargetRef,
|
||||
Address: epAddress.IP,
|
||||
Port: fmt.Sprintf("%v", targetPort),
|
||||
Target: epAddress.TargetRef,
|
||||
}
|
||||
upsServers = append(upsServers, ups)
|
||||
processedUpstreamServers[ep] = struct{}{}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import (
|
|||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/healthcheck"
|
||||
)
|
||||
|
||||
func TestGetEndpoints(t *testing.T) {
|
||||
|
|
@ -32,7 +31,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
svc *corev1.Service
|
||||
port *corev1.ServicePort
|
||||
proto corev1.Protocol
|
||||
hz *healthcheck.Config
|
||||
fn func(string) (*corev1.Endpoints, error)
|
||||
result []ingress.Endpoint
|
||||
}{
|
||||
|
|
@ -41,7 +39,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
nil,
|
||||
nil,
|
||||
corev1.ProtocolTCP,
|
||||
nil,
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
return nil, nil
|
||||
},
|
||||
|
|
@ -52,7 +49,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
&corev1.Service{},
|
||||
nil,
|
||||
corev1.ProtocolTCP,
|
||||
nil,
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
return nil, nil
|
||||
},
|
||||
|
|
@ -63,7 +59,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
&corev1.Service{},
|
||||
&corev1.ServicePort{Name: "default"},
|
||||
corev1.ProtocolTCP,
|
||||
nil,
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
return &corev1.Endpoints{}, nil
|
||||
},
|
||||
|
|
@ -78,7 +73,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
},
|
||||
&corev1.ServicePort{Name: "default"},
|
||||
corev1.ProtocolTCP,
|
||||
nil,
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
return &corev1.Endpoints{}, nil
|
||||
},
|
||||
|
|
@ -103,19 +97,13 @@ func TestGetEndpoints(t *testing.T) {
|
|||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
corev1.ProtocolTCP,
|
||||
&healthcheck.Config{
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
},
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
return &corev1.Endpoints{}, nil
|
||||
},
|
||||
[]ingress.Endpoint{
|
||||
{
|
||||
Address: "10.0.0.1.xip.io",
|
||||
Port: "80",
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
Address: "10.0.0.1.xip.io",
|
||||
Port: "80",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -138,10 +126,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
corev1.ProtocolTCP,
|
||||
&healthcheck.Config{
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
},
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
return &corev1.Endpoints{}, nil
|
||||
},
|
||||
|
|
@ -166,10 +150,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
corev1.ProtocolTCP,
|
||||
&healthcheck.Config{
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
},
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
return nil, fmt.Errorf("unexpected error")
|
||||
},
|
||||
|
|
@ -194,10 +174,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
corev1.ProtocolTCP,
|
||||
&healthcheck.Config{
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
},
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
nodeName := "dummy"
|
||||
return &corev1.Endpoints{
|
||||
|
|
@ -239,10 +215,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
corev1.ProtocolTCP,
|
||||
&healthcheck.Config{
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
},
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
nodeName := "dummy"
|
||||
return &corev1.Endpoints{
|
||||
|
|
@ -284,10 +256,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
corev1.ProtocolTCP,
|
||||
&healthcheck.Config{
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
},
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
nodeName := "dummy"
|
||||
return &corev1.Endpoints{
|
||||
|
|
@ -331,10 +299,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
corev1.ProtocolTCP,
|
||||
&healthcheck.Config{
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
},
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
nodeName := "dummy"
|
||||
return &corev1.Endpoints{
|
||||
|
|
@ -359,10 +323,8 @@ func TestGetEndpoints(t *testing.T) {
|
|||
},
|
||||
[]ingress.Endpoint{
|
||||
{
|
||||
Address: "1.1.1.1",
|
||||
Port: "80",
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
Address: "1.1.1.1",
|
||||
Port: "80",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -385,10 +347,6 @@ func TestGetEndpoints(t *testing.T) {
|
|||
TargetPort: intstr.FromString("port-1"),
|
||||
},
|
||||
corev1.ProtocolTCP,
|
||||
&healthcheck.Config{
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
},
|
||||
func(string) (*corev1.Endpoints, error) {
|
||||
nodeName := "dummy"
|
||||
return &corev1.Endpoints{
|
||||
|
|
@ -418,10 +376,8 @@ func TestGetEndpoints(t *testing.T) {
|
|||
},
|
||||
[]ingress.Endpoint{
|
||||
{
|
||||
Address: "1.1.1.1",
|
||||
Port: "80",
|
||||
MaxFails: 0,
|
||||
FailTimeout: 0,
|
||||
Address: "1.1.1.1",
|
||||
Port: "80",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -429,7 +385,7 @@ func TestGetEndpoints(t *testing.T) {
|
|||
|
||||
for _, testCase := range tests {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
result := getEndpoints(testCase.svc, testCase.port, testCase.proto, testCase.hz, testCase.fn)
|
||||
result := getEndpoints(testCase.svc, testCase.port, testCase.proto, testCase.fn)
|
||||
if len(testCase.result) != len(result) {
|
||||
t.Errorf("Expected %d Endpoints but got %d", len(testCase.result), len(result))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -773,10 +773,8 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif
|
|||
var endpoints []ingress.Endpoint
|
||||
for _, endpoint := range backend.Endpoints {
|
||||
endpoints = append(endpoints, ingress.Endpoint{
|
||||
Address: endpoint.Address,
|
||||
FailTimeout: endpoint.FailTimeout,
|
||||
MaxFails: endpoint.MaxFails,
|
||||
Port: endpoint.Port,
|
||||
Address: endpoint.Address,
|
||||
Port: endpoint.Port,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue