Adding PathType to Ingress

Co-authored-by: Christopher M. Luciano <cmluciano@us.ibm.com>
This commit is contained in:
Rob Scott
2020-02-23 14:40:32 -08:00
parent 62e993ce09
commit f38904d6f4
39 changed files with 1384 additions and 508 deletions

View File

@@ -19,7 +19,9 @@ go_library(
"//pkg/apis/networking/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)

View File

@@ -57,6 +57,7 @@ var (
defaultBackendPort = intstr.FromInt(80)
defaultLoadBalancer = "127.0.0.1"
defaultPath = "/foo"
defaultPathType = networking.PathTypeImplementationSpecific
defaultPathMap = map[string]string{defaultPath: defaultBackendName}
defaultTLS = []networking.IngressTLS{
{Hosts: []string{"foo.bar.com", "*.bar.com"}, SecretName: "fooSecret"},
@@ -69,7 +70,8 @@ func toHTTPIngressPaths(pathMap map[string]string) []networking.HTTPIngressPath
httpPaths := []networking.HTTPIngressPath{}
for path, backend := range pathMap {
httpPaths = append(httpPaths, networking.HTTPIngressPath{
Path: path,
Path: path,
PathType: &defaultPathType,
Backend: networking.IngressBackend{
ServiceName: backend,
ServicePort: defaultBackendPort,
@@ -130,16 +132,16 @@ func TestCreate(t *testing.T) {
defer storage.Store.DestroyFunc()
test := genericregistrytest.New(t, storage.Store)
ingress := validIngress()
noDefaultBackendAndRules := validIngress()
noDefaultBackendAndRules.Spec.Backend = &networking.IngressBackend{}
noDefaultBackendAndRules.Spec.Rules = []networking.IngressRule{}
noBackendAndRules := validIngress()
noBackendAndRules.Spec.Backend = &networking.IngressBackend{}
noBackendAndRules.Spec.Rules = []networking.IngressRule{}
badPath := validIngress()
badPath.Spec.Rules = toIngressRules(map[string]IngressRuleValues{
"foo.bar.com": {"/invalid[": "svc"}})
test.TestCreate(
// valid
ingress,
noDefaultBackendAndRules,
noBackendAndRules,
badPath,
)
}

View File

@@ -18,10 +18,11 @@ package ingress
import (
"context"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/networking"
@@ -67,11 +68,14 @@ func (ingressStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Ob
}
// Validate validates a new Ingress.
// Validate validates ingresses on create.
func (ingressStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
var requestGV schema.GroupVersion
if requestInfo, ok := request.RequestInfoFrom(ctx); ok {
requestGV = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
}
ingress := obj.(*networking.Ingress)
err := validation.ValidateIngress(ingress)
return err
return validation.ValidateIngressCreate(ingress, requestGV)
}
// Canonicalize normalizes the object after validation.
@@ -83,11 +87,13 @@ func (ingressStrategy) AllowCreateOnUpdate() bool {
return false
}
// ValidateUpdate is the default update validation for an end user.
// ValidateUpdate validates ingresses on update.
func (ingressStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
validationErrorList := validation.ValidateIngress(obj.(*networking.Ingress))
updateErrorList := validation.ValidateIngressUpdate(obj.(*networking.Ingress), old.(*networking.Ingress))
return append(validationErrorList, updateErrorList...)
var requestGV schema.GroupVersion
if requestInfo, ok := request.RequestInfoFrom(ctx); ok {
requestGV = schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
}
return validation.ValidateIngressUpdate(obj.(*networking.Ingress), old.(*networking.Ingress), requestGV)
}
// AllowUnconditionalUpdate is the default update policy for Ingress objects.

View File

@@ -31,6 +31,7 @@ func newIngress() networking.Ingress {
ServiceName: "default-backend",
ServicePort: intstr.FromInt(80),
}
implementationPathType := networking.PathTypeImplementationSpecific
return networking.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
@@ -48,8 +49,9 @@ func newIngress() networking.Ingress {
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{
Path: "/foo",
Backend: defaultBackend,
Path: "/foo",
PathType: &implementationPathType,
Backend: defaultBackend,
},
},
},
@@ -69,6 +71,11 @@ func newIngress() networking.Ingress {
func TestIngressStrategy(t *testing.T) {
ctx := genericapirequest.NewDefaultContext()
apiRequest := genericapirequest.RequestInfo{APIGroup: "networking.k8s.io",
APIVersion: "v1beta1",
Resource: "ingresses",
}
ctx = genericapirequest.WithRequestInfo(ctx, &apiRequest)
if !Strategy.NamespaceScoped() {
t.Errorf("Ingress must be namespace scoped")
}