From 5af774dad079f9f1b108cf0e685d59b195cb9ab6 Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Tue, 22 Jan 2019 16:40:26 -0800 Subject: [PATCH] Relax ingress/service health check to accept non-empty ingress list (#1053) --- util/health/health.go | 23 ++++++------ util/health/health_test.go | 2 ++ .../health/testdata/ingress-nonemptylist.yaml | 29 +++++++++++++++ .../svc-loadbalancer-nonemptylist.yaml | 35 +++++++++++++++++++ 4 files changed, 76 insertions(+), 13 deletions(-) create mode 100644 util/health/testdata/ingress-nonemptylist.yaml create mode 100644 util/health/testdata/svc-loadbalancer-nonemptylist.yaml diff --git a/util/health/health.go b/util/health/health.go index cbd5e030be214..c6422fd7a983c 100644 --- a/util/health/health.go +++ b/util/health/health.go @@ -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" @@ -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 } @@ -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 diff --git a/util/health/health_test.go b/util/health/health_test.go index e9628d0cb1d0b..1743d995cd8b0 100644 --- a/util/health/health_test.go +++ b/util/health/health_test.go @@ -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) { diff --git a/util/health/testdata/ingress-nonemptylist.yaml b/util/health/testdata/ingress-nonemptylist.yaml new file mode 100644 index 0000000000000..f36d4b81c0757 --- /dev/null +++ b/util/health/testdata/ingress-nonemptylist.yaml @@ -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: + - {} diff --git a/util/health/testdata/svc-loadbalancer-nonemptylist.yaml b/util/health/testdata/svc-loadbalancer-nonemptylist.yaml new file mode 100644 index 0000000000000..273bd2ccb5ac1 --- /dev/null +++ b/util/health/testdata/svc-loadbalancer-nonemptylist.yaml @@ -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: + - {}