generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add health gRPC server and refactors main()
- Introduced a health gRPC server to handle liveness and readiness probes. - Refactored main() to manage server goroutines. - Added graceful shutdown for servers and controller manager. - Improved logging consistency and ensured. - Validates CLI flags. Signed-off-by: Daneyon Hansen <[email protected]>
- Loading branch information
Showing
3 changed files
with
192 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"google.golang.org/grpc/codes" | ||
healthPb "google.golang.org/grpc/health/grpc_health_v1" | ||
"google.golang.org/grpc/status" | ||
"inference.networking.x-k8s.io/gateway-api-inference-extension/api/v1alpha1" | ||
klog "k8s.io/klog/v2" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type healthServer struct { | ||
client.Client | ||
} | ||
|
||
func (s *healthServer) Check(ctx context.Context, in *healthPb.HealthCheckRequest) (*healthPb.HealthCheckResponse, error) { | ||
if err := s.checkResources(); err != nil { | ||
klog.Infof("gRPC health check not serving: %s", in.String()) | ||
return &healthPb.HealthCheckResponse{Status: healthPb.HealthCheckResponse_NOT_SERVING}, nil | ||
} | ||
klog.Infof("gRPC health check serving: %s", in.String()) | ||
return &healthPb.HealthCheckResponse{Status: healthPb.HealthCheckResponse_SERVING}, nil | ||
} | ||
|
||
func (s *healthServer) Watch(in *healthPb.HealthCheckRequest, srv healthPb.Health_WatchServer) error { | ||
return status.Error(codes.Unimplemented, "Watch is not implemented") | ||
} | ||
|
||
// checkResources uses a client to list all InferenceModels in the configured namespace | ||
// and gets the configured InferencePool by name and namespace. | ||
func (s *healthServer) checkResources() error { | ||
ctx := context.Background() | ||
var infPool v1alpha1.InferencePool | ||
if err := s.Client.Get( | ||
ctx, | ||
client.ObjectKey{Name: *poolName, Namespace: *poolNamespace}, | ||
&infPool, | ||
); err != nil { | ||
return fmt.Errorf("failed to get InferencePool %s/%s: %v", *poolNamespace, *poolName, err) | ||
} | ||
klog.Infof("Successfully retrieved InferencePool %s/%s", *poolNamespace, *poolName) | ||
|
||
var modelList v1alpha1.InferenceModelList | ||
if err := s.Client.List(ctx, &modelList, client.InNamespace(*poolNamespace)); err != nil { | ||
return fmt.Errorf("failed to list InferenceModels in namespace %s: %v", *poolNamespace, err) | ||
} | ||
klog.Infof("Found %d InferenceModels in namespace %s", len(modelList.Items), *poolNamespace) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters