Add Ingress host, path and annotations support (#1325)

For each ingress controller, the format of ingress host,
path and annotations are different. To support different
kinds of controller, this PR adds new ingress config field
to http trigger spec. A user can set annotations, host and
path based on the type of underlying ingress controller
with CLI.

Command example:

fission route create --name foo \
    --url /foo/{bar} --function foofn --createingress \
    --ingressannotation "nginx.ingress.kubernetes.io/ssl-redirect=false" \
    --ingressannotation "nginx.ingress.kubernetes.io/use-regex=true" \
    --ingressrule "*=/foo/*"
This commit is contained in:
Ta-Ching Chen
2019-09-26 16:54:16 +08:00
committed by GitHub
parent 82a7acf408
commit 49d60b19f3
14 changed files with 1421 additions and 138 deletions
+54
View File
@@ -32,6 +32,8 @@ const (
ErrorUnsupportedType = iota
ErrorInvalidValue
ErrorInvalidObject
totalAnnotationSizeLimitB int = 256 * (1 << 10) // 256 kB
)
var (
@@ -444,6 +446,58 @@ func (spec HTTPTriggerSpec) Validate() error {
}
}
result = multierror.Append(result, spec.IngressConfig.Validate())
return result.ErrorOrNil()
}
func (config IngressConfig) Validate() error {
result := &multierror.Error{}
// Details for how to validate Ingress host rule,
// see https://github.com/kubernetes/kubernetes/blob/release-1.16/pkg/apis/networking/validation/validation.go
if len(config.Path) > 0 {
if !strings.HasPrefix(config.Path, "/") {
result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "HTTPTriggerSpec.IngressConfig.IngressRule.Path", config.Path, "must be an absolute path"))
}
_, err := regexp.CompilePOSIX(config.Path)
if err != nil {
result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "HTTPTriggerSpec.IngressConfig.IngressRule.Path", config.Path, "must be a valid regex"))
}
}
// In Ingress, to accept requests from all host, the host field will
// be an empty string instead of "*" shown in kubectl. The router replaces
// the asterisk with "" when creating/updateing the Ingress, so here we
// skip the check if the Host is equal to "*".
if len(config.Host) > 0 && config.Host != "*" {
if strings.Contains(config.Host, "*") {
for _, msg := range validation.IsWildcardDNS1123Subdomain(config.Host) {
result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "HTTPTriggerSpec.IngressConfig.IngressRule.Host", config.Host, msg))
}
}
for _, msg := range validation.IsDNS1123Subdomain(config.Host) {
result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "HTTPTriggerSpec.IngressConfig.IngressRule.Host", config.Host, msg))
}
}
// Details for how to validate annotations,
// see https://github.com/kubernetes/kubernetes/blob/512eccac1f1d72d6d1cb304bc565c50d1f2e295e/staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go#L46
var totalSize int64
for k, v := range config.Annotations {
for _, msg := range validation.IsQualifiedName(strings.ToLower(k)) {
result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "HTTPTriggerSpec.IngressConfig.Annotations.key", k, msg))
}
totalSize += (int64)(len(k)) + (int64)(len(v))
}
if totalSize > (int64)(totalAnnotationSizeLimitB) {
msg := fmt.Sprintf("must have at most %v characters", totalSize)
result = multierror.Append(result, MakeValidationErr(ErrorInvalidValue, "HTTPTriggerSpec.IngressConfig.Annotations.value", totalAnnotationSizeLimitB, msg))
}
return result.ErrorOrNil()
}