Skip to content

Commit a79519d

Browse files
authored
Merge pull request #1521 from oiooj/pr-cri-error
refactor: return CRI services error
2 parents 3f0c62f + 766a4ce commit a79519d

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

cri/criservice.go

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,23 @@ func runv1alpha1(daemonconfig *config.Config, containerMgr mgr.ContainerMgr, ima
4848
return fmt.Errorf("failed to start CRI service with error: %v", err)
4949
}
5050

51-
// TODO: Stop the whole CRI service if any of the critical service exits
52-
grpcServerCloseCh := make(chan struct{})
51+
errChan := make(chan error, 2)
5352
go func() {
54-
if err := service.Serve(); err != nil {
55-
logrus.Errorf("failed to start grpc server: %v", err)
56-
}
57-
close(grpcServerCloseCh)
53+
errChan <- service.Serve()
54+
logrus.Infof("CRI GRPC server stopped")
5855
}()
5956

60-
streamServerCloseCh := make(chan struct{})
6157
go func() {
62-
if err := criMgr.StreamServerStart(); err != nil {
63-
logrus.Errorf("failed to start stream server: %v", err)
64-
}
65-
close(streamServerCloseCh)
58+
errChan <- criMgr.StreamServerStart()
59+
logrus.Infof("CRI Stream server stopped")
6660
}()
6761

68-
// TODO: refactor it with select
69-
<-streamServerCloseCh
70-
logrus.Infof("CRI Stream server stopped")
71-
<-grpcServerCloseCh
72-
logrus.Infof("CRI GRPC server stopped")
62+
// Check for error
63+
for i := 0; i < cap(errChan); i++ {
64+
if err := <-errChan; err != nil {
65+
return err
66+
}
67+
}
7368

7469
logrus.Infof("CRI service stopped")
7570
return nil
@@ -87,27 +82,24 @@ func runv1alpha2(daemonconfig *config.Config, containerMgr mgr.ContainerMgr, ima
8782
if err != nil {
8883
return fmt.Errorf("failed to start CRI service with error: %v", err)
8984
}
90-
// TODO: Stop the whole CRI service if any of the critical service exits
91-
grpcServerCloseCh := make(chan struct{})
85+
86+
errChan := make(chan error, 2)
9287
go func() {
93-
if err := service.Serve(); err != nil {
94-
logrus.Errorf("failed to start grpc server: %v", err)
95-
}
96-
close(grpcServerCloseCh)
88+
errChan <- service.Serve()
89+
logrus.Infof("CRI GRPC server stopped")
9790
}()
9891

99-
streamServerCloseCh := make(chan struct{})
10092
go func() {
101-
if err := criMgr.StreamServerStart(); err != nil {
102-
logrus.Errorf("failed to start stream server: %v", err)
103-
}
104-
close(streamServerCloseCh)
93+
errChan <- criMgr.StreamServerStart()
94+
logrus.Infof("CRI Stream server stopped")
10595
}()
106-
// TODO: refactor it with select
107-
<-streamServerCloseCh
108-
logrus.Infof("CRI Stream server stopped")
109-
<-grpcServerCloseCh
110-
logrus.Infof("CRI GRPC server stopped")
96+
97+
// Check for error
98+
for i := 0; i < cap(errChan); i++ {
99+
if err := <-errChan; err != nil {
100+
return err
101+
}
102+
}
111103

112104
logrus.Infof("CRI service stopped")
113105
return nil

0 commit comments

Comments
 (0)