Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
enhance health scope with informative health condition (#194)
Browse files Browse the repository at this point in the history
* use merging instead of overriding

add unit test

Signed-off-by: roy wang <seiwy2010@gmail.com>

* move AddLabel func into oam/helper

Signed-off-by: roy wang <seiwy2010@gmail.com>

* Make health condition of HealthScope more informative

Add CheckByHealthCheckTrait interface

Signed-off-by: roy wang <seiwy2010@gmail.com>

* fix e2e-test

Signed-off-by: roy wang <seiwy2010@gmail.com>

* modify health scope condition

modify e2e-test & unit test

Signed-off-by: roy wang <seiwy2010@gmail.com>

* fix typo

Signed-off-by: roy wang <seiwy2010@gmail.com>

* add unit test for health scope

Signed-off-by: roy wang <seiwy2010@gmail.com>
  • Loading branch information
captainroy-hy authored Sep 9, 2020
1 parent 9cd664a commit 78b84f2
Show file tree
Hide file tree
Showing 9 changed files with 545 additions and 210 deletions.
38 changes: 37 additions & 1 deletion apis/core/v1alpha2/core_scope_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ import (
"github.com/crossplane/oam-kubernetes-runtime/pkg/oam"
)

// HealthStatus represents health status strings.
type HealthStatus string

const (
// StatusHealthy represents healthy status.
StatusHealthy HealthStatus = "HEALTHY"
// StatusUnhealthy represents unhealthy status.
StatusUnhealthy = "UNHEALTHY"
// StatusUnknown represents unknown status.
StatusUnknown = "UNKNOWN"
)

var _ oam.Scope = &HealthScope{}

// A HealthScopeSpec defines the desired state of a HealthScope.
Expand All @@ -41,7 +53,31 @@ type HealthScopeSpec struct {
type HealthScopeStatus struct {
runtimev1alpha1.ConditionedStatus `json:",inline"`

Health string `json:"health"`
// ScopeHealthCondition represents health condition summary of the scope
ScopeHealthCondition ScopeHealthCondition `json:"scopeHealthCondition"`

// WorkloadHealthConditions represents health condition of workloads in the scope
WorkloadHealthConditions []*WorkloadHealthCondition `json:"healthConditions,omitempty"`
}

// ScopeHealthCondition represents health condition summary of a scope.
type ScopeHealthCondition struct {
HealthStatus HealthStatus `json:"healthStatus"`
Total int64 `json:"total,omitempty"`
HealthyWorkloads int64 `json:"healthyWorkloads,omitempty"`
UnhealthyWorkloads int64 `json:"unhealthyWorkloads,omitempty"`
UnknownWorkloads int64 `json:"unknownWorkloads,omitempty"`
}

// WorkloadHealthCondition represents informative health condition.
type WorkloadHealthCondition struct {
// ComponentName represents the component name if target is a workload
ComponentName string `json:"componentName,omitempty"`
TargetWorkload runtimev1alpha1.TypedReference `json:"targetWorkload,omitempty"`
HealthStatus HealthStatus `json:"healthStatus"`
Diagnosis string `json:"diagnosis,omitempty"`
// WorkloadStatus represents status of workloads whose HealthStatus is UNKNOWN.
WorkloadStatus string `json:"workloadStatus,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
43 changes: 43 additions & 0 deletions apis/core/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 69 additions & 3 deletions charts/oam-kubernetes-runtime/crds/core.oam.dev_healthscopes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,76 @@ spec:
- type
type: object
type: array
health:
type: string
healthConditions:
description: WorkloadHealthConditions represents health condition
of workloads in the scope
items:
description: WorkloadHealthCondition represents informative health
condition.
properties:
componentName:
description: ComponentName represents the component name if
target is a workload
type: string
diagnosis:
type: string
healthStatus:
description: HealthStatus represents health status strings.
type: string
targetWorkload:
description: A TypedReference refers to an object by Name, Kind,
and APIVersion. It is commonly used to reference cluster-scoped
objects or objects where the namespace is already known.
properties:
apiVersion:
description: APIVersion of the referenced object.
type: string
kind:
description: Kind of the referenced object.
type: string
name:
description: Name of the referenced object.
type: string
uid:
description: UID of the referenced object.
type: string
required:
- apiVersion
- kind
- name
type: object
workloadStatus:
description: WorkloadStatus represents status of workloads whose
HealthStatus is UNKNOWN.
type: string
required:
- healthStatus
type: object
type: array
scopeHealthCondition:
description: ScopeHealthCondition represents health condition summary
of the scope
properties:
healthStatus:
description: HealthStatus represents health status strings.
type: string
healthyWorkloads:
format: int64
type: integer
total:
format: int64
type: integer
unhealthyWorkloads:
format: int64
type: integer
unknownWorkloads:
format: int64
type: integer
required:
- healthStatus
type: object
required:
- health
- scopeHealthCondition
type: object
type: object
served: true
Expand Down
Loading

0 comments on commit 78b84f2

Please sign in to comment.