Skip to content

Commit

Permalink
Merge pull request #1242 from spencerhance/cherry-pick-1239-release-1-10
Browse files Browse the repository at this point in the history
Cherry-pick #1239 [Add HTTPS Redirects to Metrics] into release-1-10
  • Loading branch information
k8s-ci-robot committed Aug 31, 2020
2 parents 0a651f4 + a0ebf39 commit ac2dfcc
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 15 deletions.
12 changes: 9 additions & 3 deletions pkg/metrics/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const (
customHealthChecks = feature("CustomHealthChecks")

// FrontendConfig Features
sslPolicy = feature("SSLPolicy")
sslPolicy = feature("SSLPolicy")
httpsRedirects = feature("HTTPSRedirects")

standaloneNeg = feature("StandaloneNEG")
ingressNeg = feature("IngressNEG")
Expand Down Expand Up @@ -216,8 +217,13 @@ func featuresForIngress(ing *v1beta1.Ingress, fc *frontendconfigv1beta1.Frontend
}

// FrontendConfig Features
if fc != nil && fc.Spec.SslPolicy != nil && *fc.Spec.SslPolicy != "" {
features = append(features, sslPolicy)
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)
Expand Down
86 changes: 74 additions & 12 deletions pkg/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ var (
nil,
},
{
"empty sslpolicy and tls termination with pre-shared certs",
"HTTPS Redirects and tls termination with pre-shared certs",
&v1beta1.Ingress{
ObjectMeta: v1.ObjectMeta{
Namespace: defaultNamespace,
Expand All @@ -592,6 +592,64 @@ var (
Rules: []v1beta1.IngressRule{},
},
},
&frontendconfigv1beta1.FrontendConfig{
Spec: frontendconfigv1beta1.FrontendConfigSpec{
RedirectToHttps: &frontendconfigv1beta1.HttpsRedirectConfig{Enabled: true},
},
},
[]feature{ingress, externalIngress, httpEnabled,
tlsTermination, preSharedCertsForTLS, httpsRedirects},
[]utils.ServicePort{},
nil,
},
{
"HTTPS Redirects Disabled and tls termination with pre-shared certs",
&v1beta1.Ingress{
ObjectMeta: v1.ObjectMeta{
Namespace: defaultNamespace,
Name: "ingress17",
Annotations: map[string]string{
preSharedCertKey: "pre-shared-cert1,pre-shared-cert2",
SSLCertKey: "pre-shared-cert1,pre-shared-cert2",
},
},
Spec: v1beta1.IngressSpec{
Backend: &v1beta1.IngressBackend{
ServiceName: "dummy-service",
ServicePort: intstr.FromInt(80),
},
Rules: []v1beta1.IngressRule{},
},
},
&frontendconfigv1beta1.FrontendConfig{
Spec: frontendconfigv1beta1.FrontendConfigSpec{
RedirectToHttps: &frontendconfigv1beta1.HttpsRedirectConfig{Enabled: false},
},
},
[]feature{ingress, externalIngress, httpEnabled,
tlsTermination, preSharedCertsForTLS},
[]utils.ServicePort{},
nil,
},
{
"empty sslpolicy and tls termination with pre-shared certs",
&v1beta1.Ingress{
ObjectMeta: v1.ObjectMeta{
Namespace: defaultNamespace,
Name: "ingress18",
Annotations: map[string]string{
preSharedCertKey: "pre-shared-cert1,pre-shared-cert2",
SSLCertKey: "pre-shared-cert1,pre-shared-cert2",
},
},
Spec: v1beta1.IngressSpec{
Backend: &v1beta1.IngressBackend{
ServiceName: "dummy-service",
ServicePort: intstr.FromInt(80),
},
Rules: []v1beta1.IngressRule{},
},
},
&frontendconfigv1beta1.FrontendConfig{
Spec: frontendconfigv1beta1.FrontendConfigSpec{
SslPolicy: utils.NewStringPointer(""),
Expand Down Expand Up @@ -658,7 +716,8 @@ func TestComputeIngressMetrics(t *testing.T) {
NewIngressState(ingressStates[1].ing, nil, ingressStates[1].svcPorts),
NewIngressState(ingressStates[3].ing, nil, ingressStates[3].svcPorts),
NewIngressState(ingressStates[13].ing, nil, ingressStates[13].svcPorts),
NewIngressState(ingressStates[14].ing, ingressStates[14].fc, ingressStates[14].svcPorts),
NewIngressState(ingressStates[14].ing, ingressStates[14].fc, ingressStates[13].svcPorts),
NewIngressState(ingressStates[16].ing, ingressStates[16].fc, ingressStates[16].svcPorts),
},
map[feature]int{
backendConnectionDraining: 0,
Expand All @@ -669,21 +728,22 @@ func TestComputeIngressMetrics(t *testing.T) {
cloudIAP: 0,
cookieAffinity: 0,
customRequestHeaders: 0,
externalIngress: 5,
httpEnabled: 4,
externalIngress: 6,
httpEnabled: 5,
hostBasedRouting: 1,
ingress: 5,
ingress: 6,
internalIngress: 0,
managedCertsForTLS: 0,
managedStaticGlobalIP: 0,
neg: 0,
pathBasedRouting: 0,
preSharedCertsForTLS: 1,
preSharedCertsForTLS: 2,
secretBasedCertsForTLS: 0,
specifiedStaticGlobalIP: 1,
staticGlobalIP: 1,
tlsTermination: 1,
tlsTermination: 2,
sslPolicy: 1,
httpsRedirects: 1,
},
map[feature]int{
backendConnectionDraining: 0,
Expand Down Expand Up @@ -820,6 +880,7 @@ func TestComputeIngressMetrics(t *testing.T) {
NewIngressState(ingressStates[13].ing, nil, ingressStates[13].svcPorts),
NewIngressState(ingressStates[14].ing, ingressStates[14].fc, ingressStates[14].svcPorts),
NewIngressState(ingressStates[15].ing, nil, ingressStates[15].svcPorts),
NewIngressState(ingressStates[16].ing, ingressStates[16].fc, ingressStates[16].svcPorts),
},
map[feature]int{
backendConnectionDraining: 7,
Expand All @@ -831,22 +892,23 @@ func TestComputeIngressMetrics(t *testing.T) {
cookieAffinity: 7,
customRequestHeaders: 3,
customHealthChecks: 6,
externalIngress: 14,
httpEnabled: 15,
externalIngress: 15,
httpEnabled: 16,
hostBasedRouting: 5,
ingress: 16,
ingress: 17,
internalIngress: 2,
managedCertsForTLS: 2,
managedStaticGlobalIP: 1,
neg: 4,
pathBasedRouting: 4,
preSharedCertsForTLS: 5,
preSharedCertsForTLS: 6,
secretBasedCertsForTLS: 1,
specifiedStaticGlobalIP: 1,
specifiedStaticRegionalIP: 1,
staticGlobalIP: 2,
tlsTermination: 6,
tlsTermination: 7,
sslPolicy: 1,
httpsRedirects: 1,
},
map[feature]int{
backendConnectionDraining: 2,
Expand Down

0 comments on commit ac2dfcc

Please sign in to comment.