Drop v1beta1 from ingress nginx (#7156)
* Drop v1beta1 from ingress nginx Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com> * Fix intorstr logic in controller Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com> * fixing admission Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com> * more intorstr fixing * correct template rendering Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com> * Fix e2e tests for v1 api Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com> * Fix gofmt errors * This is finally working...almost there... Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com> * Re-add removed validation of AdmissionReview
This commit is contained in:
parent
a8408cdb51
commit
78afe7e389
159 changed files with 1217 additions and 1008 deletions
|
|
@ -25,7 +25,7 @@ import (
|
|||
|
||||
"github.com/mitchellh/hashstructure"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
networking "k8s.io/api/networking/v1"
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
|
|
@ -229,7 +229,7 @@ func (n *NGINXController) CheckIngress(ing *networking.Ingress) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if n.cfg.DisableCatchAll && ing.Spec.Backend != nil {
|
||||
if n.cfg.DisableCatchAll && ing.Spec.DefaultBackend != nil {
|
||||
return fmt.Errorf("This deployment is trying to create a catch-all ingress while DisableCatchAll flag is set to true. Remove '.spec.backend' or set DisableCatchAll flag to false.")
|
||||
}
|
||||
|
||||
|
|
@ -571,7 +571,7 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in
|
|||
}
|
||||
|
||||
for _, path := range rule.HTTP.Paths {
|
||||
upsName := upstreamName(ing.Namespace, path.Backend.ServiceName, path.Backend.ServicePort)
|
||||
upsName := upstreamName(ing.Namespace, path.Backend.Service)
|
||||
|
||||
ups := upstreams[upsName]
|
||||
|
||||
|
|
@ -789,8 +789,8 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
|||
anns := ing.ParsedAnnotations
|
||||
|
||||
var defBackend string
|
||||
if ing.Spec.Backend != nil {
|
||||
defBackend = upstreamName(ing.Namespace, ing.Spec.Backend.ServiceName, ing.Spec.Backend.ServicePort)
|
||||
if ing.Spec.DefaultBackend != nil && ing.Spec.DefaultBackend.Service != nil {
|
||||
defBackend = upstreamName(ing.Namespace, ing.Spec.DefaultBackend.Service)
|
||||
|
||||
klog.V(3).Infof("Creating upstream %q", defBackend)
|
||||
upstreams[defBackend] = newUpstream(defBackend)
|
||||
|
|
@ -804,11 +804,11 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
|||
upstreams[defBackend].LoadBalancing = n.store.GetBackendConfiguration().LoadBalancing
|
||||
}
|
||||
|
||||
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, ing.Spec.Backend.ServiceName)
|
||||
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, ing.Spec.DefaultBackend.Service.Name)
|
||||
|
||||
// add the service ClusterIP as a single Endpoint instead of individual Endpoints
|
||||
if anns.ServiceUpstream {
|
||||
endpoint, err := n.getServiceClusterEndpoint(svcKey, ing.Spec.Backend)
|
||||
endpoint, err := n.getServiceClusterEndpoint(svcKey, ing.Spec.DefaultBackend)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to determine a suitable ClusterIP Endpoint for Service %q: %v", svcKey, err)
|
||||
} else {
|
||||
|
|
@ -829,7 +829,8 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
|||
}
|
||||
|
||||
if len(upstreams[defBackend].Endpoints) == 0 {
|
||||
endps, err := n.serviceEndpoints(svcKey, ing.Spec.Backend.ServicePort.String())
|
||||
_, port := upstreamServiceNameAndPort(ing.Spec.DefaultBackend.Service)
|
||||
endps, err := n.serviceEndpoints(svcKey, port.String())
|
||||
upstreams[defBackend].Endpoints = append(upstreams[defBackend].Endpoints, endps...)
|
||||
if err != nil {
|
||||
klog.Warningf("Error creating upstream %q: %v", defBackend, err)
|
||||
|
|
@ -849,15 +850,15 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
|||
}
|
||||
|
||||
for _, path := range rule.HTTP.Paths {
|
||||
name := upstreamName(ing.Namespace, path.Backend.ServiceName, path.Backend.ServicePort)
|
||||
|
||||
name := upstreamName(ing.Namespace, path.Backend.Service)
|
||||
svcName, svcPort := upstreamServiceNameAndPort(path.Backend.Service)
|
||||
if _, ok := upstreams[name]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
klog.V(3).Infof("Creating upstream %q", name)
|
||||
upstreams[name] = newUpstream(name)
|
||||
upstreams[name].Port = path.Backend.ServicePort
|
||||
upstreams[name].Port = svcPort
|
||||
|
||||
upstreams[name].UpstreamHashBy.UpstreamHashBy = anns.UpstreamHashBy.UpstreamHashBy
|
||||
upstreams[name].UpstreamHashBy.UpstreamHashBySubset = anns.UpstreamHashBy.UpstreamHashBySubset
|
||||
|
|
@ -868,7 +869,7 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
|||
upstreams[name].LoadBalancing = n.store.GetBackendConfiguration().LoadBalancing
|
||||
}
|
||||
|
||||
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, path.Backend.ServiceName)
|
||||
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, svcName)
|
||||
|
||||
// add the service ClusterIP as a single Endpoint instead of individual Endpoints
|
||||
if anns.ServiceUpstream {
|
||||
|
|
@ -893,7 +894,8 @@ func (n *NGINXController) createUpstreams(data []*ingress.Ingress, du *ingress.B
|
|||
}
|
||||
|
||||
if len(upstreams[name].Endpoints) == 0 {
|
||||
endp, err := n.serviceEndpoints(svcKey, path.Backend.ServicePort.String())
|
||||
_, port := upstreamServiceNameAndPort(path.Backend.Service)
|
||||
endp, err := n.serviceEndpoints(svcKey, port.String())
|
||||
if err != nil {
|
||||
klog.Warningf("Error obtaining Endpoints for Service %q: %v", svcKey, err)
|
||||
continue
|
||||
|
|
@ -931,20 +933,23 @@ func (n *NGINXController) getServiceClusterEndpoint(svcKey string, backend *netw
|
|||
|
||||
// if the Service port is referenced by name in the Ingress, lookup the
|
||||
// actual port in the service spec
|
||||
if backend.ServicePort.Type == intstr.String {
|
||||
var port int32 = -1
|
||||
for _, svcPort := range svc.Spec.Ports {
|
||||
if svcPort.Name == backend.ServicePort.String() {
|
||||
port = svcPort.Port
|
||||
break
|
||||
if backend.Service != nil {
|
||||
_, svcportintorstr := upstreamServiceNameAndPort(backend.Service)
|
||||
if svcportintorstr.Type == intstr.String {
|
||||
var port int32 = -1
|
||||
for _, svcPort := range svc.Spec.Ports {
|
||||
if svcPort.Name == svcportintorstr.String() {
|
||||
port = svcPort.Port
|
||||
break
|
||||
}
|
||||
}
|
||||
if port == -1 {
|
||||
return endpoint, fmt.Errorf("service %q does not have a port named %q", svc.Name, svcportintorstr.String())
|
||||
}
|
||||
endpoint.Port = fmt.Sprintf("%d", port)
|
||||
} else {
|
||||
endpoint.Port = svcportintorstr.String()
|
||||
}
|
||||
if port == -1 {
|
||||
return endpoint, fmt.Errorf("service %q does not have a port named %q", svc.Name, backend.ServicePort)
|
||||
}
|
||||
endpoint.Port = fmt.Sprintf("%d", port)
|
||||
} else {
|
||||
endpoint.Port = backend.ServicePort.String()
|
||||
}
|
||||
|
||||
return endpoint, err
|
||||
|
|
@ -1071,8 +1076,8 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
|
|||
continue
|
||||
}
|
||||
|
||||
if ing.Spec.Backend != nil {
|
||||
defUpstream := upstreamName(ing.Namespace, ing.Spec.Backend.ServiceName, ing.Spec.Backend.ServicePort)
|
||||
if ing.Spec.DefaultBackend != nil && ing.Spec.DefaultBackend.Service != nil {
|
||||
defUpstream := upstreamName(ing.Namespace, ing.Spec.DefaultBackend.Service)
|
||||
|
||||
if backendUpstream, ok := upstreams[defUpstream]; ok {
|
||||
// use backend specified in Ingress as the default backend for all its rules
|
||||
|
|
@ -1337,8 +1342,8 @@ func mergeAlternativeBackends(ing *ingress.Ingress, upstreams map[string]*ingres
|
|||
servers map[string]*ingress.Server) {
|
||||
|
||||
// merge catch-all alternative backends
|
||||
if ing.Spec.Backend != nil {
|
||||
upsName := upstreamName(ing.Namespace, ing.Spec.Backend.ServiceName, ing.Spec.Backend.ServicePort)
|
||||
if ing.Spec.DefaultBackend != nil {
|
||||
upsName := upstreamName(ing.Namespace, ing.Spec.DefaultBackend.Service)
|
||||
|
||||
altUps := upstreams[upsName]
|
||||
|
||||
|
|
@ -1380,7 +1385,7 @@ func mergeAlternativeBackends(ing *ingress.Ingress, upstreams map[string]*ingres
|
|||
}
|
||||
|
||||
for _, path := range rule.HTTP.Paths {
|
||||
upsName := upstreamName(ing.Namespace, path.Backend.ServiceName, path.Backend.ServicePort)
|
||||
upsName := upstreamName(ing.Namespace, path.Backend.Service)
|
||||
|
||||
altUps := upstreams[upsName]
|
||||
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ import (
|
|||
"github.com/eapache/channels"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
networking "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
|
|
@ -257,7 +256,7 @@ func TestCheckIngress(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("When a new catch-all ingress is being created despite catch-alls being disabled ", func(t *testing.T) {
|
||||
backendBefore := ing.Spec.Backend
|
||||
backendBefore := ing.Spec.DefaultBackend
|
||||
disableCatchAllBefore := nginx.cfg.DisableCatchAll
|
||||
|
||||
nginx.command = testNginxTestCommand{
|
||||
|
|
@ -266,10 +265,12 @@ func TestCheckIngress(t *testing.T) {
|
|||
}
|
||||
nginx.cfg.DisableCatchAll = true
|
||||
|
||||
ing.Spec.Backend = &networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
ing.Spec.DefaultBackend = &networking.IngressBackend{
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -278,7 +279,7 @@ func TestCheckIngress(t *testing.T) {
|
|||
}
|
||||
|
||||
// reset backend and catch-all flag
|
||||
ing.Spec.Backend = backendBefore
|
||||
ing.Spec.DefaultBackend = backendBefore
|
||||
nginx.cfg.DisableCatchAll = disableCatchAllBefore
|
||||
})
|
||||
|
||||
|
|
@ -331,10 +332,11 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
Path: "/",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -415,10 +417,11 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
Path: "/",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "foo-http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "foo-http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -435,10 +438,11 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
Path: "/",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -553,10 +557,11 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
Path: "/",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -588,10 +593,12 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
Namespace: "example",
|
||||
},
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
DefaultBackend: &networking.IngressBackend{
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -656,10 +663,12 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
Namespace: "example",
|
||||
},
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
DefaultBackend: &networking.IngressBackend{
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -720,9 +729,11 @@ func TestMergeAlternativeBackends(t *testing.T) {
|
|||
Path: "/",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1001,10 +1012,12 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Namespace: "example",
|
||||
},
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
DefaultBackend: &networking.IngressBackend{
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1044,10 +1057,12 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Namespace: "example",
|
||||
},
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
DefaultBackend: &networking.IngressBackend{
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1064,10 +1079,12 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Namespace: "example",
|
||||
},
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.IntOrString{
|
||||
IntVal: 80,
|
||||
DefaultBackend: &networking.IngressBackend{
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1117,10 +1134,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1177,10 +1195,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1214,10 +1233,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-canary",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-canary",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1283,10 +1303,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/a",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-1",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-1",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1320,10 +1341,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/a",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-2",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-2",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1357,10 +1379,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/b",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-2",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-2",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1394,10 +1417,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/b",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-1",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-1",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1431,10 +1455,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/c",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-1",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-1",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1468,10 +1493,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/c",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc-2",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc-2",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1553,10 +1579,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/path1",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "path1-svc",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "path1-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1593,10 +1620,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/path2",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "path2-svc",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "path2-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1658,10 +1686,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/path1",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "path1-svc",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "path1-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1698,10 +1727,11 @@ func TestGetBackendServers(t *testing.T) {
|
|||
Path: "/path2",
|
||||
PathType: &pathTypePrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "path2-svc",
|
||||
ServicePort: intstr.IntOrString{
|
||||
Type: intstr.Int,
|
||||
IntVal: 80,
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "path2-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/mitchellh/copystructure"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
networking "k8s.io/api/networking/v1"
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
networking "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
package store
|
||||
|
||||
import (
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
networking "k8s.io/api/networking/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import (
|
|||
|
||||
"github.com/eapache/channels"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
networkingv1beta1 "k8s.io/api/networking/v1beta1"
|
||||
networkingv1 "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
k8sruntime "k8s.io/apimachinery/pkg/runtime"
|
||||
|
|
@ -293,7 +293,7 @@ func New(
|
|||
informers.WithTweakListOptions(secretsTweakListOptionsFunc),
|
||||
)
|
||||
|
||||
store.informers.Ingress = infFactory.Networking().V1beta1().Ingresses().Informer()
|
||||
store.informers.Ingress = infFactory.Networking().V1().Ingresses().Informer()
|
||||
store.listers.Ingress.Store = store.informers.Ingress.GetStore()
|
||||
|
||||
store.informers.Endpoint = infFactory.Core().V1().Endpoints().Informer()
|
||||
|
|
@ -317,7 +317,7 @@ func New(
|
|||
klog.ErrorS(nil, "Error obtaining object from tombstone", "key", obj)
|
||||
return
|
||||
}
|
||||
ing, ok = tombstone.Obj.(*networkingv1beta1.Ingress)
|
||||
ing, ok = tombstone.Obj.(*networkingv1.Ingress)
|
||||
if !ok {
|
||||
klog.Errorf("Tombstone contained object that is not an Ingress: %#v", obj)
|
||||
return
|
||||
|
|
@ -626,17 +626,17 @@ func New(
|
|||
|
||||
// hasCatchAllIngressRule returns whether or not an ingress produces a
|
||||
// catch-all server, and so should be ignored when --disable-catch-all is set
|
||||
func hasCatchAllIngressRule(spec networkingv1beta1.IngressSpec) bool {
|
||||
return spec.Backend != nil
|
||||
func hasCatchAllIngressRule(spec networkingv1.IngressSpec) bool {
|
||||
return spec.DefaultBackend != nil
|
||||
}
|
||||
|
||||
// syncIngress parses ingress annotations converting the value of the
|
||||
// annotation to a go struct
|
||||
func (s *k8sStore) syncIngress(ing *networkingv1beta1.Ingress) {
|
||||
func (s *k8sStore) syncIngress(ing *networkingv1.Ingress) {
|
||||
key := k8s.MetaNamespaceKey(ing)
|
||||
klog.V(3).Infof("updating annotations information for ingress %v", key)
|
||||
|
||||
copyIng := &networkingv1beta1.Ingress{}
|
||||
copyIng := &networkingv1.Ingress{}
|
||||
ing.ObjectMeta.DeepCopyInto(©Ing.ObjectMeta)
|
||||
ing.Spec.DeepCopyInto(©Ing.Spec)
|
||||
ing.Status.DeepCopyInto(©Ing.Status)
|
||||
|
|
@ -666,7 +666,7 @@ func (s *k8sStore) syncIngress(ing *networkingv1beta1.Ingress) {
|
|||
|
||||
// updateSecretIngressMap takes an Ingress and updates all Secret objects it
|
||||
// references in secretIngressMap.
|
||||
func (s *k8sStore) updateSecretIngressMap(ing *networkingv1beta1.Ingress) {
|
||||
func (s *k8sStore) updateSecretIngressMap(ing *networkingv1.Ingress) {
|
||||
key := k8s.MetaNamespaceKey(ing)
|
||||
klog.V(3).Infof("updating references to secrets for ingress %v", key)
|
||||
|
||||
|
|
@ -710,7 +710,7 @@ func (s *k8sStore) updateSecretIngressMap(ing *networkingv1beta1.Ingress) {
|
|||
|
||||
// objectRefAnnotationNsKey returns an object reference formatted as a
|
||||
// 'namespace/name' key from the given annotation name.
|
||||
func objectRefAnnotationNsKey(ann string, ing *networkingv1beta1.Ingress) (string, error) {
|
||||
func objectRefAnnotationNsKey(ann string, ing *networkingv1.Ingress) (string, error) {
|
||||
annValue, err := parser.GetStringAnnotation(ann, ing)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -729,7 +729,7 @@ func objectRefAnnotationNsKey(ann string, ing *networkingv1beta1.Ingress) (strin
|
|||
|
||||
// syncSecrets synchronizes data from all Secrets referenced by the given
|
||||
// Ingress with the local store and file system.
|
||||
func (s *k8sStore) syncSecrets(ing *networkingv1beta1.Ingress) {
|
||||
func (s *k8sStore) syncSecrets(ing *networkingv1.Ingress) {
|
||||
key := k8s.MetaNamespaceKey(ing)
|
||||
for _, secrKey := range s.secretIngressMap.ReferencedBy(key) {
|
||||
s.syncSecret(secrKey)
|
||||
|
|
@ -759,7 +759,7 @@ func (s *k8sStore) GetService(key string) (*corev1.Service, error) {
|
|||
}
|
||||
|
||||
// getIngress returns the Ingress matching key.
|
||||
func (s *k8sStore) getIngress(key string) (*networkingv1beta1.Ingress, error) {
|
||||
func (s *k8sStore) getIngress(key string) (*networkingv1.Ingress, error) {
|
||||
ing, err := s.listers.IngressWithAnnotation.ByKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -900,11 +900,11 @@ func (s *k8sStore) Run(stopCh chan struct{}) {
|
|||
var runtimeScheme = k8sruntime.NewScheme()
|
||||
|
||||
func init() {
|
||||
utilruntime.Must(networkingv1beta1.AddToScheme(runtimeScheme))
|
||||
utilruntime.Must(networkingv1.AddToScheme(runtimeScheme))
|
||||
}
|
||||
|
||||
func toIngress(obj interface{}) (*networkingv1beta1.Ingress, bool) {
|
||||
if ing, ok := obj.(*networkingv1beta1.Ingress); ok {
|
||||
func toIngress(obj interface{}) (*networkingv1.Ingress, bool) {
|
||||
if ing, ok := obj.(*networkingv1.Ingress); ok {
|
||||
k8s.SetDefaultNGINXPathType(ing)
|
||||
return ing, true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,10 +29,9 @@ import (
|
|||
|
||||
"github.com/eapache/channels"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
networking "k8s.io/api/networking/v1"
|
||||
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
||||
|
|
@ -43,10 +42,14 @@ import (
|
|||
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||
)
|
||||
|
||||
var pathPrefix networking.PathType = networking.PathTypePrefix
|
||||
|
||||
func TestStore(t *testing.T) {
|
||||
//TODO: move env definition to docker image?
|
||||
os.Setenv("KUBEBUILDER_ASSETS", "/usr/local/bin")
|
||||
|
||||
pathPrefix = networking.PathTypePrefix
|
||||
|
||||
te := &envtest.Environment{}
|
||||
cfg, err := te.Start()
|
||||
if err != nil {
|
||||
|
|
@ -109,7 +112,7 @@ func TestStore(t *testing.T) {
|
|||
t.Errorf("expected an error but none returned")
|
||||
}
|
||||
if svc != nil {
|
||||
t.Errorf("expected an Ingres but none returned")
|
||||
t.Errorf("expected an Ingress but none returned")
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -177,10 +180,15 @@ func TestStore(t *testing.T) {
|
|||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Path: "/",
|
||||
PathType: &pathPrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -214,10 +222,15 @@ func TestStore(t *testing.T) {
|
|||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Path: "/",
|
||||
PathType: &pathPrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -238,7 +251,7 @@ func TestStore(t *testing.T) {
|
|||
// Secret takes a bit to update
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
err = clientSet.NetworkingV1beta1().Ingresses(ni.Namespace).Delete(context.TODO(), ni.Name, metav1.DeleteOptions{})
|
||||
err = clientSet.NetworkingV1().Ingresses(ni.Namespace).Delete(context.TODO(), ni.Name, metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("error creating ingress: %v", err)
|
||||
}
|
||||
|
|
@ -328,10 +341,15 @@ func TestStore(t *testing.T) {
|
|||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Path: "/",
|
||||
PathType: &pathPrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -514,9 +532,13 @@ func TestStore(t *testing.T) {
|
|||
SecretName: secretName,
|
||||
},
|
||||
},
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
DefaultBackend: &networking.IngressBackend{
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, clientSet, t)
|
||||
|
|
@ -630,10 +652,15 @@ func TestStore(t *testing.T) {
|
|||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/",
|
||||
Path: "/",
|
||||
PathType: &pathPrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "http-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "http-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -725,13 +752,13 @@ func createConfigMap(clientSet kubernetes.Interface, ns string, t *testing.T) st
|
|||
|
||||
func ensureIngress(ingress *networking.Ingress, clientSet kubernetes.Interface, t *testing.T) *networking.Ingress {
|
||||
t.Helper()
|
||||
ing, err := clientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Update(context.TODO(), ingress, metav1.UpdateOptions{})
|
||||
ing, err := clientSet.NetworkingV1().Ingresses(ingress.Namespace).Update(context.TODO(), ingress, metav1.UpdateOptions{})
|
||||
|
||||
if err != nil {
|
||||
if k8sErrors.IsNotFound(err) {
|
||||
t.Logf("Ingress %v not found, creating", ingress)
|
||||
|
||||
ing, err = clientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
|
||||
ing, err = clientSet.NetworkingV1().Ingresses(ingress.Namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("error creating ingress %+v: %v", ingress, err)
|
||||
}
|
||||
|
|
@ -748,7 +775,7 @@ func ensureIngress(ingress *networking.Ingress, clientSet kubernetes.Interface,
|
|||
|
||||
func deleteIngress(ingress *networking.Ingress, clientSet kubernetes.Interface, t *testing.T) {
|
||||
t.Helper()
|
||||
err := clientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Delete(context.TODO(), ingress.Name, metav1.DeleteOptions{})
|
||||
err := clientSet.NetworkingV1().Ingresses(ingress.Namespace).Delete(context.TODO(), ingress.Name, metav1.DeleteOptions{})
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("failed to delete ingress %+v: %v", ingress, err)
|
||||
|
|
@ -852,9 +879,13 @@ func TestListIngresses(t *testing.T) {
|
|||
CreationTimestamp: metav1.NewTime(time.Now()),
|
||||
},
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "demo",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
DefaultBackend: &networking.IngressBackend{
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "demo",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -877,8 +908,12 @@ func TestListIngresses(t *testing.T) {
|
|||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "demo",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "demo",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -909,10 +944,15 @@ func TestListIngresses(t *testing.T) {
|
|||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/demo",
|
||||
Path: "/demo",
|
||||
PathType: &pathPrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "demo",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "demo",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -32,13 +32,14 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
text_template "text/template"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
networkingv1beta1 "k8s.io/api/networking/v1beta1"
|
||||
networkingv1 "k8s.io/api/networking/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
|
|
@ -435,7 +436,7 @@ func buildLocation(input interface{}, enforceRegex bool) string {
|
|||
return fmt.Sprintf(`~* "^%s"`, path)
|
||||
}
|
||||
|
||||
if location.PathType != nil && *location.PathType == networkingv1beta1.PathTypeExact {
|
||||
if location.PathType != nil && *location.PathType == networkingv1.PathTypeExact {
|
||||
return fmt.Sprintf(`= %s`, path)
|
||||
}
|
||||
|
||||
|
|
@ -899,10 +900,10 @@ func getIngressInformation(i, h, p interface{}) *ingressInformation {
|
|||
info.Path = "/"
|
||||
}
|
||||
|
||||
if ing.Spec.Backend != nil {
|
||||
info.Service = ing.Spec.Backend.ServiceName
|
||||
if ing.Spec.Backend.ServicePort.String() != "0" {
|
||||
info.ServicePort = ing.Spec.Backend.ServicePort.String()
|
||||
if ing.Spec.DefaultBackend != nil && ing.Spec.DefaultBackend.Service != nil {
|
||||
info.Service = ing.Spec.DefaultBackend.Service.Name
|
||||
if ing.Spec.DefaultBackend.Service.Port.Number > 0 {
|
||||
info.ServicePort = strconv.Itoa(int(ing.Spec.DefaultBackend.Service.Port.Number))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -929,14 +930,14 @@ func getIngressInformation(i, h, p interface{}) *ingressInformation {
|
|||
continue
|
||||
}
|
||||
|
||||
if info.Service != "" && rPath.Backend.ServiceName == "" {
|
||||
if info.Service != "" && rPath.Backend.Service.Name == "" {
|
||||
// empty rule. Only contains a Path and PathType
|
||||
return info
|
||||
}
|
||||
|
||||
info.Service = rPath.Backend.ServiceName
|
||||
if rPath.Backend.ServicePort.String() != "0" {
|
||||
info.ServicePort = rPath.Backend.ServicePort.String()
|
||||
info.Service = rPath.Backend.Service.Name
|
||||
if rPath.Backend.Service.Port.Number > 0 {
|
||||
info.ServicePort = strconv.Itoa(int(rPath.Backend.Service.Port.Number))
|
||||
}
|
||||
|
||||
return info
|
||||
|
|
|
|||
|
|
@ -30,9 +30,8 @@ import (
|
|||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
networking "k8s.io/api/networking/v1beta1"
|
||||
networking "k8s.io/api/networking/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/authreq"
|
||||
|
|
@ -55,6 +54,8 @@ func init() {
|
|||
}
|
||||
|
||||
var (
|
||||
pathPrefix networking.PathType = networking.PathTypePrefix
|
||||
|
||||
// TODO: add tests for SSLPassthrough
|
||||
tmplFuncTestcases = map[string]struct {
|
||||
Path string
|
||||
|
|
@ -197,11 +198,11 @@ func TestBuildLuaSharedDictionaries(t *testing.T) {
|
|||
servers := []*ingress.Server{
|
||||
{
|
||||
Hostname: "foo.bar",
|
||||
Locations: []*ingress.Location{{Path: "/"}},
|
||||
Locations: []*ingress.Location{{Path: "/", PathType: &pathPrefix}},
|
||||
},
|
||||
{
|
||||
Hostname: "another.host",
|
||||
Locations: []*ingress.Location{{Path: "/"}},
|
||||
Locations: []*ingress.Location{{Path: "/", PathType: &pathPrefix}},
|
||||
},
|
||||
}
|
||||
// returns value from config
|
||||
|
|
@ -283,8 +284,9 @@ func TestBuildLocation(t *testing.T) {
|
|||
|
||||
for k, tc := range tmplFuncTestcases {
|
||||
loc := &ingress.Location{
|
||||
Path: tc.Path,
|
||||
Rewrite: rewrite.Config{Target: tc.Target},
|
||||
Path: tc.Path,
|
||||
PathType: &pathPrefix,
|
||||
Rewrite: rewrite.Config{Target: tc.Target},
|
||||
}
|
||||
|
||||
newLoc := buildLocation(loc, tc.enforceRegex)
|
||||
|
|
@ -301,6 +303,7 @@ func TestBuildProxyPass(t *testing.T) {
|
|||
for k, tc := range tmplFuncTestcases {
|
||||
loc := &ingress.Location{
|
||||
Path: tc.Path,
|
||||
PathType: &pathPrefix,
|
||||
Rewrite: rewrite.Config{Target: tc.Target},
|
||||
Backend: defaultBackend,
|
||||
XForwardedPrefix: tc.XForwardedPrefix,
|
||||
|
|
@ -828,6 +831,7 @@ func TestBuildUpstreamName(t *testing.T) {
|
|||
for k, tc := range tmplFuncTestcases {
|
||||
loc := &ingress.Location{
|
||||
Path: tc.Path,
|
||||
PathType: &pathPrefix,
|
||||
Rewrite: rewrite.Config{Target: tc.Target},
|
||||
Backend: defaultBackend,
|
||||
XForwardedPrefix: tc.XForwardedPrefix,
|
||||
|
|
@ -937,8 +941,10 @@ func TestGetIngressInformation(t *testing.T) {
|
|||
},
|
||||
},
|
||||
Spec: networking.IngressSpec{
|
||||
Backend: &networking.IngressBackend{
|
||||
ServiceName: "a-svc",
|
||||
DefaultBackend: &networking.IngressBackend{
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "a-svc",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -948,6 +954,7 @@ func TestGetIngressInformation(t *testing.T) {
|
|||
&ingressInformation{
|
||||
Namespace: "default",
|
||||
Rule: "validIng",
|
||||
Path: "/",
|
||||
Annotations: map[string]string{
|
||||
"ingress.annotation": "ok",
|
||||
},
|
||||
|
|
@ -972,10 +979,15 @@ func TestGetIngressInformation(t *testing.T) {
|
|||
HTTP: &networking.HTTPIngressRuleValue{
|
||||
Paths: []networking.HTTPIngressPath{
|
||||
{
|
||||
Path: "/ok",
|
||||
Path: "/ok",
|
||||
PathType: &pathPrefix,
|
||||
Backend: networking.IngressBackend{
|
||||
ServiceName: "b-svc",
|
||||
ServicePort: intstr.FromInt(80),
|
||||
Service: &networking.IngressServiceBackend{
|
||||
Name: "b-svc",
|
||||
Port: networking.ServiceBackendPort{
|
||||
Number: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1249,7 +1261,8 @@ func TestEnforceRegexModifier(t *testing.T) {
|
|||
Target: "/alright",
|
||||
UseRegex: true,
|
||||
},
|
||||
Path: "/ok",
|
||||
Path: "/ok",
|
||||
PathType: &pathPrefix,
|
||||
},
|
||||
}
|
||||
expected = true
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"syscall"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
networking "k8s.io/api/networking/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/ingress-nginx/internal/ingress"
|
||||
"k8s.io/klog/v2"
|
||||
|
|
@ -47,8 +48,30 @@ func newUpstream(name string) *ingress.Backend {
|
|||
}
|
||||
|
||||
// upstreamName returns a formatted upstream name based on namespace, service, and port
|
||||
func upstreamName(namespace string, service string, port intstr.IntOrString) string {
|
||||
return fmt.Sprintf("%v-%v-%v", namespace, service, port.String())
|
||||
func upstreamName(namespace string, service *networking.IngressServiceBackend) string {
|
||||
if service != nil {
|
||||
if service.Port.Number > 0 {
|
||||
return fmt.Sprintf("%s-%s-%d", namespace, service.Name, service.Port.Number)
|
||||
}
|
||||
if service.Port.Name != "" {
|
||||
return fmt.Sprintf("%s-%s-%s", namespace, service.Name, service.Port.Name)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s-INVALID", namespace)
|
||||
}
|
||||
|
||||
// upstreamServiceNameAndPort verifies if service is not nil, and then return the
|
||||
// correct serviceName and Port
|
||||
func upstreamServiceNameAndPort(service *networking.IngressServiceBackend) (string, intstr.IntOrString) {
|
||||
if service != nil {
|
||||
if service.Port.Number > 0 {
|
||||
return service.Name, intstr.FromInt(int(service.Port.Number))
|
||||
}
|
||||
if service.Port.Name != "" {
|
||||
return service.Name, intstr.FromString(service.Port.Name)
|
||||
}
|
||||
}
|
||||
return "", intstr.IntOrString{}
|
||||
}
|
||||
|
||||
// sysctlSomaxconn returns the maximum number of connections that can be queued
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue