[go: nahoru, domu]

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

Enhance HealthScope #160

Merged
merged 4 commits into from
Aug 27, 2020
Merged

Conversation

captainroy-hy
Copy link
Contributor

#68

  • Use adaptable HeathChecker to check different types workload' health status
  • Show scope diagnosis info in HealthScope's condition message
  • Add built-in checkers for ContainerizedWorkload, Deployment, StatefulSet, and DaemonSet
  • Add general check for any type workloads ,e.g OpenKruise CloneSet, except built-in ones, based on status.availableReplicas and status.readyReplicas
  • Add unit tests

Signed-off-by: roy wang <seiwy2010@gmail.com>
// why tc.hsWorkloadRefs passed into It func
// shared the same address?
// for _, tc := range tests {
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tc is a local variable in loop, and the address behind it is an iterator. So when the loop iterated, the value of iterator which is tc will change while the address keep the same. Generally, add such line in loop will fix:

tc := tc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I used tc:=tc originally but it didn't work because I put tc:=tc inside It("",func(){tc:=tc ...}). It should put it before It otherwise the scope of It will always get the same address of tc. Fixed. Thx!

Signed-off-by: roy wang <seiwy2010@gmail.com>
@wonderflow
Copy link
Member

ping @artursouza @ryanzhang-oss , could you help review this PR, thanks!

Copy link
Member
@artursouza artursouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for the known K8s resources but this is not extensible. We had discussed about having a HealthCheckTrait to decouple health check from health scope. HealthScope is the aggregation of health statuses while the health status itself is the output of one kind of health check.

@artursouza
Copy link
Member

BTW, I am not against this PR but this cannot be extended to future workloads.

IsHealthy: true,
}
}
//TODO(roywang) does every workload have status?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really

}
var (
// for general check on worload's replicas
generalReplicaCheckFiled = []string{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not all resources have these two fields

for _, fp := range generalReplicaCheckFiled {
if value, err := pavedV.GetNumber(fp); err == nil {
// just check ready/available replica exists
if value != 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one replica exists doesn't mean it's healthy...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems such kind of general checking rule doesn't make sense... Maybe I should remove generalReplicaCheck and leave it to HealthCheckTrait to satisfy diverse health checking needs.

@captainroy-hy
Copy link
Contributor Author

This works for the known K8s resources but this is not extensible. We had discussed about having a HealthCheckTrait to decouple health check from health scope. HealthScope is the aggregation of health statuses while the health status itself is the output of one kind of health check.

@artursouza Yes, I agree that implementation in this PR is not extensible, and HealthCheckTrait is a good idea for adopting any kind of health check while just leave HealthScope playing a role as an aggregation of health statuses.
However, is it okay to keep several built-in health checkers in HealthScope for core workloads and native K8s resources, just like what we handled in this PR? And with further enhancement, we can make HealthCheckTrait possible to override built-in checkers according to users' config. Then, users can just put Component into HealthScope without assigning additional HealthCheckTrait every time, unless they really need custom HealthCheckTrait.

@wonderflow
Copy link
Member

@captainroy-hy Yes, I think this PR is good, and we could support HealthCheckTrait in the following PRs.

fix typo & modify unit test

Signed-off-by: roy wang <seiwy2010@gmail.com>
Signed-off-by: roy wang <seiwy2010@gmail.com>
@captainroy-hy
Copy link
Contributor Author

Hi @ryanzhang-oss I remove general health check and fix hardcode kind name issue. Could you please help review this PR, thanks!

}
r.Target.UID = deployment.GetUID()

if deployment.Status.ReadyReplicas == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something here, why is that "ReadyReplicas != 0" means healthy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I just stay in line with current logic on health checking .And a more rigorous check is x.Status.ReadyReplicas == x.Spec.Replicas

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could fix it in the following PRs

}
r.Target.UID = statefulset.GetUID()

if statefulset.Status.ReadyReplicas == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, why is that "ReadyReplicas != 0" means healthy?

Copy link
Member
@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is good, let me merge it, and fix other things in the following PRs.

@wonderflow wonderflow merged commit 0255e85 into crossplane:master Aug 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants