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

Commit

Permalink
fix typo
Browse files Browse the repository at this point in the history
Signed-off-by: roy wang <seiwy2010@gmail.com>
  • Loading branch information
captainroy-hy committed Sep 5, 2020
1 parent 8a5852a commit 8b62ad5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
36 changes: 18 additions & 18 deletions pkg/controller/v1alpha2/core/scopes/healthscope/healthscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,33 @@ var (
kindDaemonSet = reflect.TypeOf(apps.DaemonSet{}).Name()
)

// HealthCondition holds health status of any resource
type HealthCondition = v1alpha2.WorkloadHealthCondition
// WorkloadHealthCondition holds health status of any resource
type WorkloadHealthCondition = v1alpha2.WorkloadHealthCondition

// ScopeHealthCondition holds health condition of a scope
type ScopeHealthCondition = v1alpha2.ScopeHealthCondition

// A WorloadHealthChecker checks health status of specified resource
// and saves status into an HealthCondition object.
type WorloadHealthChecker interface {
Check(context.Context, client.Client, runtimev1alpha1.TypedReference, string) *HealthCondition
Check(context.Context, client.Client, runtimev1alpha1.TypedReference, string) *WorkloadHealthCondition
}

// WorkloadHealthCheckFn checks health status of specified resource
// and saves status into an HealthCondition object.
type WorkloadHealthCheckFn func(context.Context, client.Client, runtimev1alpha1.TypedReference, string) *HealthCondition
type WorkloadHealthCheckFn func(context.Context, client.Client, runtimev1alpha1.TypedReference, string) *WorkloadHealthCondition

// Check the health status of specified resource
func (fn WorkloadHealthCheckFn) Check(ctx context.Context, c client.Client, tr runtimev1alpha1.TypedReference, ns string) *HealthCondition {
func (fn WorkloadHealthCheckFn) Check(ctx context.Context, c client.Client, tr runtimev1alpha1.TypedReference, ns string) *WorkloadHealthCondition {
return fn(ctx, c, tr, ns)
}

// CheckContainerziedWorkloadHealth check health condition of ContainerizedWorkload
func CheckContainerziedWorkloadHealth(ctx context.Context, c client.Client, ref runtimev1alpha1.TypedReference, namespace string) *HealthCondition {
func CheckContainerziedWorkloadHealth(ctx context.Context, c client.Client, ref runtimev1alpha1.TypedReference, namespace string) *WorkloadHealthCondition {
if ref.GroupVersionKind() != corev1alpha2.SchemeGroupVersion.WithKind(kindContainerizedWorkload) {
return nil
}
r := &HealthCondition{
r := &WorkloadHealthCondition{
HealthStatus: StatusHealthy,
TargetWorkload: ref,
}
Expand All @@ -108,7 +108,7 @@ func CheckContainerziedWorkloadHealth(ctx context.Context, c client.Client, ref
r.ComponentName = getComponentNameFromLabel(&cwObj)
r.TargetWorkload.UID = cwObj.GetUID()

subConditions := []*HealthCondition{}
subConditions := []*WorkloadHealthCondition{}
childRefs := cwObj.Status.Resources
if len(childRefs) != 2 {
// one deployment and one svc are required by containerizedworkload
Expand All @@ -124,7 +124,7 @@ func CheckContainerziedWorkloadHealth(ctx context.Context, c client.Client, ref
childCondition := CheckDeploymentHealth(ctx, c, childRef, namespace)
subConditions = append(subConditions, childCondition)
case kindService:
childCondition := &HealthCondition{
childCondition := &WorkloadHealthCondition{
TargetWorkload: childRef,
HealthStatus: StatusHealthy,
}
Expand All @@ -149,11 +149,11 @@ func CheckContainerziedWorkloadHealth(ctx context.Context, c client.Client, ref
}

// CheckDeploymentHealth checks health condition of Deployment
func CheckDeploymentHealth(ctx context.Context, client client.Client, ref runtimev1alpha1.TypedReference, namespace string) *HealthCondition {
func CheckDeploymentHealth(ctx context.Context, client client.Client, ref runtimev1alpha1.TypedReference, namespace string) *WorkloadHealthCondition {
if ref.GroupVersionKind() != apps.SchemeGroupVersion.WithKind(kindDeployment) {
return nil
}
r := &HealthCondition{
r := &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
TargetWorkload: ref,
}
Expand Down Expand Up @@ -183,11 +183,11 @@ func CheckDeploymentHealth(ctx context.Context, client client.Client, ref runtim
}

// CheckStatefulsetHealth checks health condition of StatefulSet
func CheckStatefulsetHealth(ctx context.Context, client client.Client, ref runtimev1alpha1.TypedReference, namespace string) *HealthCondition {
func CheckStatefulsetHealth(ctx context.Context, client client.Client, ref runtimev1alpha1.TypedReference, namespace string) *WorkloadHealthCondition {
if ref.GroupVersionKind() != apps.SchemeGroupVersion.WithKind(kindStatefulSet) {
return nil
}
r := &HealthCondition{
r := &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
TargetWorkload: ref,
}
Expand Down Expand Up @@ -216,11 +216,11 @@ func CheckStatefulsetHealth(ctx context.Context, client client.Client, ref runti
}

// CheckDaemonsetHealth checks health condition of DaemonSet
func CheckDaemonsetHealth(ctx context.Context, client client.Client, ref runtimev1alpha1.TypedReference, namespace string) *HealthCondition {
func CheckDaemonsetHealth(ctx context.Context, client client.Client, ref runtimev1alpha1.TypedReference, namespace string) *WorkloadHealthCondition {
if ref.GroupVersionKind() != apps.SchemeGroupVersion.WithKind(kindDaemonSet) {
return nil
}
r := &HealthCondition{
r := &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
TargetWorkload: ref,
}
Expand All @@ -245,14 +245,14 @@ func CheckDaemonsetHealth(ctx context.Context, client client.Client, ref runtime
}

// CheckByHealthCheckTrait checks health condition through HealthCheckTrait.
func CheckByHealthCheckTrait(ctx context.Context, c client.Client, wlRef runtimev1alpha1.TypedReference, ns string) *HealthCondition {
func CheckByHealthCheckTrait(ctx context.Context, c client.Client, wlRef runtimev1alpha1.TypedReference, ns string) *WorkloadHealthCondition {
//TODO(roywang) implement HealthCheckTrait feature
return nil
}

// CheckUnknownWorkload handles unknown type workloads.
func CheckUnknownWorkload(ctx context.Context, c client.Client, wlRef runtimev1alpha1.TypedReference, ns string) *HealthCondition {
healthCondition := &HealthCondition{
func CheckUnknownWorkload(ctx context.Context, c client.Client, wlRef runtimev1alpha1.TypedReference, ns string) *WorkloadHealthCondition {
healthCondition := &WorkloadHealthCondition{
TargetWorkload: wlRef,
HealthStatus: StatusUnknown,
Diagnosis: fmt.Sprintf(infoFmtUnknownWorkload, wlRef.APIVersion, wlRef.Kind),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ func (r *Reconciler) Reconcile(req reconcile.Request) (reconcile.Result, error)
}

// GetScopeHealthStatus get the status of the healthscope based on workload resources.
func (r *Reconciler) GetScopeHealthStatus(ctx context.Context, healthScope *v1alpha2.HealthScope) (ScopeHealthCondition, []*HealthCondition) {
func (r *Reconciler) GetScopeHealthStatus(ctx context.Context, healthScope *v1alpha2.HealthScope) (ScopeHealthCondition, []*WorkloadHealthCondition) {
log := r.log.WithValues("get scope health status", healthScope.GetName())
scopeCondition := ScopeHealthCondition{
HealthStatus: StatusHealthy, //if no workload referenced, scope is healthy by default
}
scopeWLRefs := healthScope.Spec.WorkloadReferences
if len(scopeWLRefs) == 0 {
return scopeCondition, []*HealthCondition{}
return scopeCondition, []*WorkloadHealthCondition{}
}

timeout := defaultTimeout
Expand All @@ -193,14 +193,14 @@ func (r *Reconciler) GetScopeHealthStatus(ctx context.Context, healthScope *v1al
defer cancel()

// process workloads concurrently
workloadHealthConditionsC := make(chan *HealthCondition, len(scopeWLRefs))
workloadHealthConditionsC := make(chan *WorkloadHealthCondition, len(scopeWLRefs))
var wg sync.WaitGroup
wg.Add(len(scopeWLRefs))

for _, workloadRef := range scopeWLRefs {
go func(resRef runtimev1alpha1.TypedReference) {
defer wg.Done()
var wlHealthCondition *HealthCondition
var wlHealthCondition *WorkloadHealthCondition

wlHealthCondition = r.traitChecker.Check(ctx, r.client, resRef, healthScope.GetNamespace())
if wlHealthCondition != nil {
Expand Down Expand Up @@ -231,7 +231,7 @@ func (r *Reconciler) GetScopeHealthStatus(ctx context.Context, healthScope *v1al
}()

var healthyCount, unhealthyCount, unknownCount int64
workloadHealthConditions := []*HealthCondition{}
workloadHealthConditions := []*WorkloadHealthCondition{}
for wlC := range workloadHealthConditionsC {
workloadHealthConditions = append(workloadHealthConditions, wlC)
switch wlC.HealthStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ var _ = Describe("HealthScope Controller Reconcile Test", func() {
Client: &test.MockClient{},
}
MockHealthyChecker := WorkloadHealthCheckFn(
func(context.Context, client.Client, v1alpha1.TypedReference, string) *HealthCondition {
func(context.Context, client.Client, v1alpha1.TypedReference, string) *WorkloadHealthCondition {

return &HealthCondition{HealthStatus: StatusHealthy}
return &WorkloadHealthCondition{HealthStatus: StatusHealthy}
})
MockUnhealthyChecker := WorkloadHealthCheckFn(
func(context.Context, client.Client, v1alpha1.TypedReference, string) *HealthCondition {
return &HealthCondition{HealthStatus: StatusUnhealthy}
func(context.Context, client.Client, v1alpha1.TypedReference, string) *WorkloadHealthCondition {
return &WorkloadHealthCondition{HealthStatus: StatusUnhealthy}
})
reconciler := NewReconciler(mockMgr,
WithLogger(logging.NewNopLogger().WithValues("HealthScopeReconciler")),
Expand Down
36 changes: 18 additions & 18 deletions pkg/controller/v1alpha2/core/scopes/healthscope/healthscope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestCheckContainerziedWorkloadHealth(t *testing.T) {
caseName string
mockGetFn test.MockGetFn
wlRef runtimev1alpha1.TypedReference
expect *HealthCondition
expect *WorkloadHealthCondition
}{
{
caseName: "not matched checker",
Expand All @@ -89,7 +89,7 @@ func TestCheckContainerziedWorkloadHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusHealthy,
},
},
Expand All @@ -113,7 +113,7 @@ func TestCheckContainerziedWorkloadHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand All @@ -123,7 +123,7 @@ func TestCheckContainerziedWorkloadHealth(t *testing.T) {
mockGetFn: func(ctx context.Context, key types.NamespacedName, obj runtime.Object) error {
return errMockErr
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand All @@ -140,7 +140,7 @@ func TestCheckContainerziedWorkloadHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand All @@ -162,7 +162,7 @@ func TestCheckContainerziedWorkloadHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestCheckDeploymentHealth(t *testing.T) {
caseName string
mockGetFn test.MockGetFn
wlRef runtimev1alpha1.TypedReference
expect *HealthCondition
expect *WorkloadHealthCondition
}{
{
caseName: "not matched checker",
Expand All @@ -214,7 +214,7 @@ func TestCheckDeploymentHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusHealthy,
},
},
Expand All @@ -234,7 +234,7 @@ func TestCheckDeploymentHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand All @@ -244,7 +244,7 @@ func TestCheckDeploymentHealth(t *testing.T) {
mockGetFn: func(ctx context.Context, key types.NamespacedName, obj runtime.Object) error {
return errMockErr
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestCheckStatefulsetHealth(t *testing.T) {
caseName string
mockGetFn test.MockGetFn
wlRef runtimev1alpha1.TypedReference
expect *HealthCondition
expect *WorkloadHealthCondition
}{
{
caseName: "not matched checker",
Expand All @@ -295,7 +295,7 @@ func TestCheckStatefulsetHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusHealthy,
},
},
Expand All @@ -315,7 +315,7 @@ func TestCheckStatefulsetHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand All @@ -325,7 +325,7 @@ func TestCheckStatefulsetHealth(t *testing.T) {
mockGetFn: func(ctx context.Context, key types.NamespacedName, obj runtime.Object) error {
return errMockErr
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestCheckDaemonsetHealth(t *testing.T) {
caseName string
mockGetFn test.MockGetFn
wlRef runtimev1alpha1.TypedReference
expect *HealthCondition
expect *WorkloadHealthCondition
}{
{
caseName: "not matched checker",
Expand All @@ -373,7 +373,7 @@ func TestCheckDaemonsetHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusHealthy,
},
},
Expand All @@ -390,7 +390,7 @@ func TestCheckDaemonsetHealth(t *testing.T) {
}
return nil
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand All @@ -400,7 +400,7 @@ func TestCheckDaemonsetHealth(t *testing.T) {
mockGetFn: func(ctx context.Context, key types.NamespacedName, obj runtime.Object) error {
return errMockErr
},
expect: &HealthCondition{
expect: &WorkloadHealthCondition{
HealthStatus: StatusUnhealthy,
},
},
Expand Down

0 comments on commit 8b62ad5

Please sign in to comment.