Skip to content

Commit

Permalink
Relax ingress/service health check to accept non-empty ingress list (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesuen committed Feb 15, 2019
1 parent bdeecc2 commit 5af774d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 13 deletions.
23 changes: 10 additions & 13 deletions util/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package health
import (
"fmt"

"k8s.io/api/apps/v1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
coreV1 "k8s.io/api/core/v1"
extv1beta1 "k8s.io/api/extensions/v1beta1"
Expand Down Expand Up @@ -137,12 +137,11 @@ func getIngressHealth(obj *unstructured.Unstructured) (*appv1.HealthStatus, erro
if err != nil {
return nil, fmt.Errorf("failed to convert %T to %T: %v", obj, ingress, err)
}
health := appv1.HealthStatus{Status: appv1.HealthStatusProgressing}
for _, ingress := range ingress.Status.LoadBalancer.Ingress {
if ingress.Hostname != "" || ingress.IP != "" {
health.Status = appv1.HealthStatusHealthy
break
}
health := appv1.HealthStatus{}
if len(ingress.Status.LoadBalancer.Ingress) > 0 {
health.Status = appv1.HealthStatusHealthy
} else {
health.Status = appv1.HealthStatusProgressing
}
return &health, nil
}
Expand All @@ -155,12 +154,10 @@ func getServiceHealth(obj *unstructured.Unstructured) (*appv1.HealthStatus, erro
}
health := appv1.HealthStatus{Status: appv1.HealthStatusHealthy}
if service.Spec.Type == coreV1.ServiceTypeLoadBalancer {
health.Status = appv1.HealthStatusProgressing
for _, ingress := range service.Status.LoadBalancer.Ingress {
if ingress.Hostname != "" || ingress.IP != "" {
health.Status = appv1.HealthStatusHealthy
break
}
if len(service.Status.LoadBalancer.Ingress) > 0 {
health.Status = appv1.HealthStatusHealthy
} else {
health.Status = appv1.HealthStatusProgressing
}
}
return &health, nil
Expand Down
2 changes: 2 additions & 0 deletions util/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ func TestServiceHealth(t *testing.T) {
assertAppHealth(t, "./testdata/svc-clusterip.yaml", appv1.HealthStatusHealthy)
assertAppHealth(t, "./testdata/svc-loadbalancer.yaml", appv1.HealthStatusHealthy)
assertAppHealth(t, "./testdata/svc-loadbalancer-unassigned.yaml", appv1.HealthStatusProgressing)
assertAppHealth(t, "./testdata/svc-loadbalancer-nonemptylist.yaml", appv1.HealthStatusHealthy)
}

func TestIngressHealth(t *testing.T) {
assertAppHealth(t, "./testdata/ingress.yaml", appv1.HealthStatusHealthy)
assertAppHealth(t, "./testdata/ingress-unassigned.yaml", appv1.HealthStatusProgressing)
assertAppHealth(t, "./testdata/ingress-nonemptylist.yaml", appv1.HealthStatusHealthy)
}

func TestCRD(t *testing.T) {
Expand Down
29 changes: 29 additions & 0 deletions util/health/testdata/ingress-nonemptylist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
generation: 1
labels:
app: grafana
app.kubernetes.io/instance: grafana
chart: grafana-1.12.0
heritage: Tiller
release: grafana
name: grafana
namespace: test-ops
spec:
rules:
- host: grafana.com
http:
paths:
- backend:
serviceName: grafana
servicePort: 80
path: /
tls:
- hosts:
- grafana.com
secretName: my-secret
status:
loadBalancer:
ingress:
- {}
35 changes: 35 additions & 0 deletions util/health/testdata/svc-loadbalancer-nonemptylist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "600"
creationTimestamp: 2018-06-05T23:34:58Z
labels:
app.kubernetes.io/instance: argocd-cdp
name: argocd-server
namespace: argocd
resourceVersion: "32559487"
selfLink: /api/v1/namespaces/argocd/services/argocd-server
uid: 0f5885a9-6919-11e8-ad29-020124679688
spec:
clusterIP: 100.69.46.185
externalTrafficPolicy: Cluster
ports:
- name: http
nodePort: 30354
port: 80
protocol: TCP
targetPort: 8080
- name: https
nodePort: 31866
port: 443
protocol: TCP
targetPort: 8080
selector:
app: argocd-server
sessionAffinity: None
type: LoadBalancer
status:
loadBalancer:
ingress:
- {}

0 comments on commit 5af774d

Please sign in to comment.