in pkg/metrics/features.go [124:241]
func featuresForIngress(ing *v1.Ingress, fc *frontendconfigv1beta1.FrontendConfig) []feature {
features := []feature{ingress}
ingKey := fmt.Sprintf("%s/%s", ing.Namespace, ing.Name)
klog.V(4).Infof("Listing features for Ingress %s", ingKey)
ingAnnotations := ing.Annotations
// Determine the type of ingress based on ingress class.
ingClass := ingAnnotations[ingressClassKey]
klog.V(6).Infof("Ingress class value for ingress %s: %s", ingKey, ingClass)
switch ingClass {
case "", gceIngressClass, gceMultiIngressClass:
features = append(features, externalIngress)
case gceL7ILBIngressClass:
features = append(features, internalIngress)
}
// Determine if http is enabled.
if val, ok := ingAnnotations[allowHTTPKey]; !ok {
klog.V(6).Infof("Annotation %s does not exist for ingress %s", allowHTTPKey, ingKey)
features = append(features, httpEnabled)
} else {
klog.V(6).Infof("User specified value for annotation %s on ingress %s: %s", allowHTTPKey, ingKey, val)
v, err := strconv.ParseBool(val)
if err != nil {
klog.Errorf("Failed to parse %s for annotation %s on ingress %s", val, allowHTTPKey, ingKey)
}
if err == nil && v {
features = append(features, httpEnabled)
}
}
// An ingress without a host or http-path is ignored.
hostBased, pathBased := false, false
if len(ing.Spec.Rules) == 0 {
klog.V(6).Infof("Neither host-based nor path-based routing rules are setup for ingress %s", ingKey)
}
for _, rule := range ing.Spec.Rules {
if rule.HTTP != nil && len(rule.HTTP.Paths) > 0 {
klog.V(6).Infof("User specified http paths for ingress %s: %v", ingKey, rule.HTTP.Paths)
pathBased = true
}
if rule.Host != "" {
klog.V(6).Infof("User specified host for ingress %s: %v", ingKey, rule.Host)
hostBased = true
}
if pathBased && hostBased {
break
}
}
if hostBased {
features = append(features, hostBasedRouting)
}
if pathBased {
features = append(features, pathBasedRouting)
}
// SSL certificate based features.
// If user specifies a SSL certificate and controller does not add SSL certificate
// annotation on ingress, then SSL cert is invalid in some sense. Ignore reporting
// these SSL certificates.
if cert, ok := ingAnnotations[SSLCertKey]; ok {
klog.V(6).Infof("Configured SSL certificate for ingress %s: %v", ingKey, cert)
features = append(features, tlsTermination)
certSpecified := false
if val, ok := ingAnnotations[preSharedCertKey]; ok {
klog.V(6).Infof("Specified pre-shared certs for ingress %s: %v", ingKey, val)
certSpecified = true
features = append(features, preSharedCertsForTLS)
}
if val, ok := ingAnnotations[managedCertKey]; ok {
klog.V(6).Infof("Specified google managed certs for ingress %s: %v", ingKey, val)
certSpecified = true
features = append(features, managedCertsForTLS)
}
if hasSecretBasedCerts(ing) {
certSpecified = true
features = append(features, secretBasedCertsForTLS)
}
if !certSpecified {
klog.Errorf("Unexpected TLS termination(cert: %s) for ingress %s", cert, ingKey)
}
}
// Both user specified and ingress controller managed global static ips are reported.
if val, ok := ingAnnotations[staticIPKey]; ok && val != "" {
klog.V(6).Infof("Static IP for ingress %s: %s", ingKey, val)
features = append(features, staticGlobalIP)
// Check if user specified static ip annotation exists.
if val, ok = ingAnnotations[StaticGlobalIPNameKey]; ok {
klog.V(6).Infof("User specified static IP for ingress %s: %s", ingKey, val)
features = append(features, specifiedStaticGlobalIP)
} else {
features = append(features, managedStaticGlobalIP)
}
}
// Check for regional static IP
// We do this separately from the global static IP because Controller does not
// populate StaticIPKey annotation when processing Regional static IP.
if val, ok := ingAnnotations[annotations.RegionalStaticIPNameKey]; ok && val != "" {
features = append(features, specifiedStaticRegionalIP)
}
// FrontendConfig Features
if fc != nil {
if fc.Spec.SslPolicy != nil && *fc.Spec.SslPolicy != "" {
features = append(features, sslPolicy)
}
if fc.Spec.RedirectToHttps != nil && fc.Spec.RedirectToHttps.Enabled {
features = append(features, httpsRedirects)
}
}
klog.V(4).Infof("Features for ingress %s: %v", ingKey, features)
return features
}