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:
Ricardo Katz 2021-06-23 18:20:10 -03:00 committed by GitHub
parent a8408cdb51
commit 78afe7e389
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
159 changed files with 1217 additions and 1008 deletions

View file

@ -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

View file

@ -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