Skip to content

Commit

Permalink
fix: stop relying on imported types for ingress health check (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesuen committed Oct 20, 2021
1 parent 23f41cb commit e8d9803
Showing 1 changed file with 2 additions and 57 deletions.
59 changes: 2 additions & 57 deletions pkg/health/health_ingress.go
Original file line number Diff line number Diff line change
@@ -1,68 +1,13 @@
package health

import (
"fmt"

"github.com/argoproj/gitops-engine/pkg/utils/kube"
extv1beta1 "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)

func getIngressHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
gvk := obj.GroupVersionKind()
switch gvk {
case networkingv1.SchemeGroupVersion.WithKind(kube.IngressKind):
var ingress networkingv1.Ingress
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &ingress)
if err != nil {
return nil, fmt.Errorf("failed to convert unstructured Ingress to typed: %v", err)
}
return getNetworkingv1IngressHealth(&ingress)
case networkingv1beta1.SchemeGroupVersion.WithKind(kube.IngressKind):
var ingress networkingv1beta1.Ingress
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &ingress)
if err != nil {
return nil, fmt.Errorf("failed to convert unstructured Ingress to typed: %v", err)
}
return getNetworkingv1beta1IngressHealth(&ingress)
case extv1beta1.SchemeGroupVersion.WithKind(kube.IngressKind):
var ingress extv1beta1.Ingress
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &ingress)
if err != nil {
return nil, fmt.Errorf("failed to convert unstructured Ingress to typed: %v", err)
}
return getExtv1beta1IngressHealth(&ingress)
default:
return nil, fmt.Errorf("unsupported Ingress GVK: %s", gvk)
}
}

func getNetworkingv1IngressHealth(ingress *networkingv1.Ingress) (*HealthStatus, error) {
health := HealthStatus{}
if len(ingress.Status.LoadBalancer.Ingress) > 0 {
health.Status = HealthStatusHealthy
} else {
health.Status = HealthStatusProgressing
}
return &health, nil
}

func getNetworkingv1beta1IngressHealth(ingress *networkingv1beta1.Ingress) (*HealthStatus, error) {
health := HealthStatus{}
if len(ingress.Status.LoadBalancer.Ingress) > 0 {
health.Status = HealthStatusHealthy
} else {
health.Status = HealthStatusProgressing
}
return &health, nil
}

func getExtv1beta1IngressHealth(ingress *extv1beta1.Ingress) (*HealthStatus, error) {
ingresses, _, _ := unstructured.NestedSlice(obj.Object, "status", "loadBalancer", "ingress")
health := HealthStatus{}
if len(ingress.Status.LoadBalancer.Ingress) > 0 {
if len(ingresses) > 0 {
health.Status = HealthStatusHealthy
} else {
health.Status = HealthStatusProgressing
Expand Down

0 comments on commit e8d9803

Please sign in to comment.