-
Notifications
You must be signed in to change notification settings - Fork 53
/
health.go
50 lines (44 loc) · 1.21 KB
/
health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package management
import (
"context"
corev1 "github.com/rancher/opni/pkg/apis/core/v1"
managementv1 "github.com/rancher/opni/pkg/apis/management/v1"
"github.com/rancher/opni/pkg/validation"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
)
func (m *Server) GetClusterHealthStatus(
_ context.Context,
ref *corev1.Reference,
) (*corev1.HealthStatus, error) {
if m.healthStatusDataSource == nil {
return nil, status.Error(codes.Unavailable, "health API not configured")
}
if err := validation.Validate(ref); err != nil {
return nil, err
}
return m.healthStatusDataSource.GetClusterHealthStatus(ref)
}
func (m *Server) WatchClusterHealthStatus(
_ *emptypb.Empty,
stream managementv1.Management_WatchClusterHealthStatusServer,
) error {
if m.healthStatusDataSource == nil {
return status.Error(codes.Unavailable, "health API not configured")
}
healthStatusC := m.healthStatusDataSource.WatchClusterHealthStatus(stream.Context())
for {
select {
case <-stream.Context().Done():
return nil
case healthStatus, ok := <-healthStatusC:
if !ok {
return nil
}
if err := stream.Send(healthStatus); err != nil {
return err
}
}
}
}