Skip to content

Commit b6928af

Browse files
authored
Merge pull request kubernetes#135208 from SergeyKanzhelev/automated-cherry-pick-of-#135153-upstream-release-1.33
Automated cherry pick of kubernetes#135153: mark device manager as haelthy before it started for the first time
2 parents 15f3d2d + 148362c commit b6928af

File tree

1 file changed

+11
-10
lines changed
  • pkg/kubelet/cm/devicemanager/plugin/v1beta1

1 file changed

+11
-10
lines changed

pkg/kubelet/cm/devicemanager/plugin/v1beta1/server.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ type server struct {
5757
chandler ClientHandler
5858
clients map[string]Client
5959

60-
// isStarted indicates whether the service has started successfully.
61-
isStarted bool
60+
// lastError records the last runtime error. A server is considered healthy till an actual error occurs.
61+
lastError error
6262
}
6363

6464
// NewServer returns an initialized device plugin registration server.
@@ -117,7 +117,7 @@ func (s *server) Start() error {
117117
defer s.wg.Done()
118118
s.setHealthy()
119119
if err = s.grpc.Serve(ln); err != nil {
120-
s.setUnhealthy()
120+
s.setUnhealthy(err)
121121
klog.ErrorS(err, "Error while serving device plugin registration grpc server")
122122
}
123123
}()
@@ -208,18 +208,19 @@ func (s *server) Name() string {
208208
}
209209

210210
func (s *server) Check(_ *http.Request) error {
211-
if s.isStarted {
212-
return nil
213-
}
214-
return fmt.Errorf("device plugin registration gRPC server failed and no device plugins can register")
211+
return s.lastError
215212
}
216213

217214
// setHealthy sets the health status of the gRPC server.
218215
func (s *server) setHealthy() {
219-
s.isStarted = true
216+
s.lastError = nil
220217
}
221218

222219
// setUnhealthy sets the health status of the gRPC server to unhealthy.
223-
func (s *server) setUnhealthy() {
224-
s.isStarted = false
220+
func (s *server) setUnhealthy(err error) {
221+
if err == nil {
222+
s.lastError = fmt.Errorf("device registration error: device plugin registration gRPC server failed and no device plugins can register")
223+
return
224+
}
225+
s.lastError = fmt.Errorf("device registration error: device plugin registration gRPC server failed and no device plugins can register: %w", err)
225226
}

0 commit comments

Comments
 (0)