Skip to content

Commit

Permalink
Return health status for V1 CRDs (#1675)
Browse files Browse the repository at this point in the history
The v1 CRD API is available since Kubernetes 1.16 and should be supported in addition to the v1beta1 API that's deprecated beginning with Kubernetes 1.19.

Signed-off-by: Jan Schlicht <jan@d2iq.com>
  • Loading branch information
Jan Schlicht committed Sep 7, 2020
1 parent 8c30604 commit 8b8a68a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/engine/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -62,9 +63,18 @@ func IsHealthy(obj runtime.Object) error {

objUnstructured := &unstructured.Unstructured{Object: unstructMap}
switch obj := obj.(type) {
case *v1beta1.CustomResourceDefinition:
case *apiextv1beta1.CustomResourceDefinition:
for _, c := range obj.Status.Conditions {
if c.Type == v1beta1.Established && c.Status == v1beta1.ConditionTrue {
if c.Type == apiextv1beta1.Established && c.Status == apiextv1beta1.ConditionTrue {
log.Printf("CRD %s is now healthy", obj.Name)
return nil
}
}
msg := fmt.Sprintf("CRD %s is not healthy ( Conditions: %v )", obj.Name, obj.Status.Conditions)
return errors.New(msg)
case *apiextv1.CustomResourceDefinition:
for _, c := range obj.Status.Conditions {
if c.Type == apiextv1.Established && c.Status == apiextv1.ConditionTrue {
log.Printf("CRD %s is now healthy", obj.Name)
return nil
}
Expand Down

0 comments on commit 8b8a68a

Please sign in to comment.