@@ -95,13 +95,25 @@ func (in *instrumentedService) checkInitialized() error {
9595// GRPC service request handlers should return error before server is fully
9696// initialized.
9797// NOTE(random-liu): All following functions MUST check initialized at the beginning.
98- func (in * instrumentedAlphaService ) checkInitialized () error {
98+ func (in * instrumentedAlphaService ) checkInitialized (ctx context.Context ) error {
99+ in .emitUsageWarning (ctx )
99100 if in .c .IsInitialized () {
100101 return nil
101102 }
102103 return errors .New ("server is not initialized yet" )
103104}
104105
106+ // emitUsageWarning emits a warning when v1alpha2 cri-api is called.
107+ func (in * instrumentedAlphaService ) emitUsageWarning (ctx context.Context ) {
108+ // Only emit the warning the first time an v1alpha2 api is called
109+ in .emitWarning .Do (func () {
110+ log .G (ctx ).Warning ("CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead." )
111+ if in .warn != nil {
112+ in .warn .Emit (ctx , deprecation .CRIAPIV1Alpha2 )
113+ }
114+ })
115+ }
116+
105117func (in * instrumentedService ) RunPodSandbox (ctx context.Context , r * runtime.RunPodSandboxRequest ) (res * runtime.RunPodSandboxResponse , err error ) {
106118 if err := in .checkInitialized (); err != nil {
107119 return nil , err
@@ -119,7 +131,7 @@ func (in *instrumentedService) RunPodSandbox(ctx context.Context, r *runtime.Run
119131}
120132
121133func (in * instrumentedAlphaService ) RunPodSandbox (ctx context.Context , r * runtime_alpha.RunPodSandboxRequest ) (res * runtime_alpha.RunPodSandboxResponse , err error ) {
122- if err := in .checkInitialized (); err != nil {
134+ if err := in .checkInitialized (ctx ); err != nil {
123135 return nil , err
124136 }
125137 log .G (ctx ).Infof ("RunPodSandbox for %+v" , r .GetConfig ().GetMetadata ())
@@ -172,7 +184,7 @@ func (in *instrumentedService) ListPodSandbox(ctx context.Context, r *runtime.Li
172184}
173185
174186func (in * instrumentedAlphaService ) ListPodSandbox (ctx context.Context , r * runtime_alpha.ListPodSandboxRequest ) (res * runtime_alpha.ListPodSandboxResponse , err error ) {
175- if err := in .checkInitialized (); err != nil {
187+ if err := in .checkInitialized (ctx ); err != nil {
176188 return nil , err
177189 }
178190 log .G (ctx ).Tracef ("ListPodSandbox with filter %+v" , r .GetFilter ())
@@ -225,7 +237,7 @@ func (in *instrumentedService) PodSandboxStatus(ctx context.Context, r *runtime.
225237}
226238
227239func (in * instrumentedAlphaService ) PodSandboxStatus (ctx context.Context , r * runtime_alpha.PodSandboxStatusRequest ) (res * runtime_alpha.PodSandboxStatusResponse , err error ) {
228- if err := in .checkInitialized (); err != nil {
240+ if err := in .checkInitialized (ctx ); err != nil {
229241 return nil , err
230242 }
231243 log .G (ctx ).Tracef ("PodSandboxStatus for %q" , r .GetPodSandboxId ())
@@ -278,7 +290,7 @@ func (in *instrumentedService) StopPodSandbox(ctx context.Context, r *runtime.St
278290}
279291
280292func (in * instrumentedAlphaService ) StopPodSandbox (ctx context.Context , r * runtime_alpha.StopPodSandboxRequest ) (res * runtime_alpha.StopPodSandboxResponse , err error ) {
281- if err := in .checkInitialized (); err != nil {
293+ if err := in .checkInitialized (ctx ); err != nil {
282294 return nil , err
283295 }
284296 log .G (ctx ).Infof ("StopPodSandbox for %q" , r .GetPodSandboxId ())
@@ -331,7 +343,7 @@ func (in *instrumentedService) RemovePodSandbox(ctx context.Context, r *runtime.
331343}
332344
333345func (in * instrumentedAlphaService ) RemovePodSandbox (ctx context.Context , r * runtime_alpha.RemovePodSandboxRequest ) (res * runtime_alpha.RemovePodSandboxResponse , err error ) {
334- if err := in .checkInitialized (); err != nil {
346+ if err := in .checkInitialized (ctx ); err != nil {
335347 return nil , err
336348 }
337349 log .G (ctx ).Infof ("RemovePodSandbox for %q" , r .GetPodSandboxId ())
@@ -384,7 +396,7 @@ func (in *instrumentedService) PortForward(ctx context.Context, r *runtime.PortF
384396}
385397
386398func (in * instrumentedAlphaService ) PortForward (ctx context.Context , r * runtime_alpha.PortForwardRequest ) (res * runtime_alpha.PortForwardResponse , err error ) {
387- if err := in .checkInitialized (); err != nil {
399+ if err := in .checkInitialized (ctx ); err != nil {
388400 return nil , err
389401 }
390402 log .G (ctx ).Infof ("Portforward for %q port %v" , r .GetPodSandboxId (), r .GetPort ())
@@ -440,7 +452,7 @@ func (in *instrumentedService) CreateContainer(ctx context.Context, r *runtime.C
440452}
441453
442454func (in * instrumentedAlphaService ) CreateContainer (ctx context.Context , r * runtime_alpha.CreateContainerRequest ) (res * runtime_alpha.CreateContainerResponse , err error ) {
443- if err := in .checkInitialized (); err != nil {
455+ if err := in .checkInitialized (ctx ); err != nil {
444456 return nil , err
445457 }
446458 log .G (ctx ).Infof ("CreateContainer within sandbox %q for container %+v" ,
@@ -497,7 +509,7 @@ func (in *instrumentedService) StartContainer(ctx context.Context, r *runtime.St
497509}
498510
499511func (in * instrumentedAlphaService ) StartContainer (ctx context.Context , r * runtime_alpha.StartContainerRequest ) (res * runtime_alpha.StartContainerResponse , err error ) {
500- if err := in .checkInitialized (); err != nil {
512+ if err := in .checkInitialized (ctx ); err != nil {
501513 return nil , err
502514 }
503515 log .G (ctx ).Infof ("StartContainer for %q" , r .GetContainerId ())
@@ -551,7 +563,7 @@ func (in *instrumentedService) ListContainers(ctx context.Context, r *runtime.Li
551563}
552564
553565func (in * instrumentedAlphaService ) ListContainers (ctx context.Context , r * runtime_alpha.ListContainersRequest ) (res * runtime_alpha.ListContainersResponse , err error ) {
554- if err := in .checkInitialized (); err != nil {
566+ if err := in .checkInitialized (ctx ); err != nil {
555567 return nil , err
556568 }
557569 log .G (ctx ).Tracef ("ListContainers with filter %+v" , r .GetFilter ())
@@ -605,7 +617,7 @@ func (in *instrumentedService) ContainerStatus(ctx context.Context, r *runtime.C
605617}
606618
607619func (in * instrumentedAlphaService ) ContainerStatus (ctx context.Context , r * runtime_alpha.ContainerStatusRequest ) (res * runtime_alpha.ContainerStatusResponse , err error ) {
608- if err := in .checkInitialized (); err != nil {
620+ if err := in .checkInitialized (ctx ); err != nil {
609621 return nil , err
610622 }
611623 log .G (ctx ).Tracef ("ContainerStatus for %q" , r .GetContainerId ())
@@ -658,7 +670,7 @@ func (in *instrumentedService) StopContainer(ctx context.Context, r *runtime.Sto
658670}
659671
660672func (in * instrumentedAlphaService ) StopContainer (ctx context.Context , r * runtime_alpha.StopContainerRequest ) (res * runtime_alpha.StopContainerResponse , err error ) {
661- if err := in .checkInitialized (); err != nil {
673+ if err := in .checkInitialized (ctx ); err != nil {
662674 return nil , err
663675 }
664676 log .G (ctx ).Infof ("StopContainer for %q with timeout %d (s)" , r .GetContainerId (), r .GetTimeout ())
@@ -711,7 +723,7 @@ func (in *instrumentedService) RemoveContainer(ctx context.Context, r *runtime.R
711723}
712724
713725func (in * instrumentedAlphaService ) RemoveContainer (ctx context.Context , r * runtime_alpha.RemoveContainerRequest ) (res * runtime_alpha.RemoveContainerResponse , err error ) {
714- if err := in .checkInitialized (); err != nil {
726+ if err := in .checkInitialized (ctx ); err != nil {
715727 return nil , err
716728 }
717729 log .G (ctx ).Infof ("RemoveContainer for %q" , r .GetContainerId ())
@@ -764,7 +776,7 @@ func (in *instrumentedService) ExecSync(ctx context.Context, r *runtime.ExecSync
764776}
765777
766778func (in * instrumentedAlphaService ) ExecSync (ctx context.Context , r * runtime_alpha.ExecSyncRequest ) (res * runtime_alpha.ExecSyncResponse , err error ) {
767- if err := in .checkInitialized (); err != nil {
779+ if err := in .checkInitialized (ctx ); err != nil {
768780 return nil , err
769781 }
770782 log .G (ctx ).Debugf ("ExecSync for %q with command %+v and timeout %d (s)" , r .GetContainerId (), r .GetCmd (), r .GetTimeout ())
@@ -818,7 +830,7 @@ func (in *instrumentedService) Exec(ctx context.Context, r *runtime.ExecRequest)
818830}
819831
820832func (in * instrumentedAlphaService ) Exec (ctx context.Context , r * runtime_alpha.ExecRequest ) (res * runtime_alpha.ExecResponse , err error ) {
821- if err := in .checkInitialized (); err != nil {
833+ if err := in .checkInitialized (ctx ); err != nil {
822834 return nil , err
823835 }
824836 log .G (ctx ).Debugf ("Exec for %q with command %+v, tty %v and stdin %v" ,
@@ -872,7 +884,7 @@ func (in *instrumentedService) Attach(ctx context.Context, r *runtime.AttachRequ
872884}
873885
874886func (in * instrumentedAlphaService ) Attach (ctx context.Context , r * runtime_alpha.AttachRequest ) (res * runtime_alpha.AttachResponse , err error ) {
875- if err := in .checkInitialized (); err != nil {
887+ if err := in .checkInitialized (ctx ); err != nil {
876888 return nil , err
877889 }
878890 log .G (ctx ).Debugf ("Attach for %q with tty %v and stdin %v" , r .GetContainerId (), r .GetTty (), r .GetStdin ())
@@ -925,7 +937,7 @@ func (in *instrumentedService) UpdateContainerResources(ctx context.Context, r *
925937}
926938
927939func (in * instrumentedAlphaService ) UpdateContainerResources (ctx context.Context , r * runtime_alpha.UpdateContainerResourcesRequest ) (res * runtime_alpha.UpdateContainerResourcesResponse , err error ) {
928- if err := in .checkInitialized (); err != nil {
940+ if err := in .checkInitialized (ctx ); err != nil {
929941 return nil , err
930942 }
931943 log .G (ctx ).Infof ("UpdateContainerResources for %q with Linux: %+v / Windows: %+v" , r .GetContainerId (), r .GetLinux (), r .GetWindows ())
@@ -982,7 +994,7 @@ func (in *instrumentedService) PullImage(ctx context.Context, r *runtime.PullIma
982994}
983995
984996func (in * instrumentedAlphaService ) PullImage (ctx context.Context , r * runtime_alpha.PullImageRequest ) (res * runtime_alpha.PullImageResponse , err error ) {
985- if err := in .checkInitialized (); err != nil {
997+ if err := in .checkInitialized (ctx ); err != nil {
986998 return nil , err
987999 }
9881000 ctx , span := tracing .StartSpan (ctx , tracing .Name (criSpanPrefix , "PullImage" ))
@@ -1043,7 +1055,7 @@ func (in *instrumentedService) ListImages(ctx context.Context, r *runtime.ListIm
10431055}
10441056
10451057func (in * instrumentedAlphaService ) ListImages (ctx context.Context , r * runtime_alpha.ListImagesRequest ) (res * runtime_alpha.ListImagesResponse , err error ) {
1046- if err := in .checkInitialized (); err != nil {
1058+ if err := in .checkInitialized (ctx ); err != nil {
10471059 return nil , err
10481060 }
10491061 ctx , span := tracing .StartSpan (ctx , tracing .Name (criSpanPrefix , "ListImages" ))
@@ -1104,7 +1116,7 @@ func (in *instrumentedService) ImageStatus(ctx context.Context, r *runtime.Image
11041116}
11051117
11061118func (in * instrumentedAlphaService ) ImageStatus (ctx context.Context , r * runtime_alpha.ImageStatusRequest ) (res * runtime_alpha.ImageStatusResponse , err error ) {
1107- if err := in .checkInitialized (); err != nil {
1119+ if err := in .checkInitialized (ctx ); err != nil {
11081120 return nil , err
11091121 }
11101122 ctx , span := tracing .StartSpan (ctx , tracing .Name (criSpanPrefix , "ImageStatus" ))
@@ -1164,7 +1176,7 @@ func (in *instrumentedService) RemoveImage(ctx context.Context, r *runtime.Remov
11641176}
11651177
11661178func (in * instrumentedAlphaService ) RemoveImage (ctx context.Context , r * runtime_alpha.RemoveImageRequest ) (res * runtime_alpha.RemoveImageResponse , err error ) {
1167- if err := in .checkInitialized (); err != nil {
1179+ if err := in .checkInitialized (ctx ); err != nil {
11681180 return nil , err
11691181 }
11701182 ctx , span := tracing .StartSpan (ctx , tracing .Name (criSpanPrefix , "RemoveImage" ))
@@ -1223,7 +1235,7 @@ func (in *instrumentedService) ImageFsInfo(ctx context.Context, r *runtime.Image
12231235}
12241236
12251237func (in * instrumentedAlphaService ) ImageFsInfo (ctx context.Context , r * runtime_alpha.ImageFsInfoRequest ) (res * runtime_alpha.ImageFsInfoResponse , err error ) {
1226- if err := in .checkInitialized (); err != nil {
1238+ if err := in .checkInitialized (ctx ); err != nil {
12271239 return nil , err
12281240 }
12291241 ctx , span := tracing .StartSpan (ctx , tracing .Name (criSpanPrefix , "ImageFsInfo" ))
@@ -1279,7 +1291,7 @@ func (in *instrumentedService) PodSandboxStats(ctx context.Context, r *runtime.P
12791291}
12801292
12811293func (in * instrumentedAlphaService ) PodSandboxStats (ctx context.Context , r * runtime_alpha.PodSandboxStatsRequest ) (res * runtime_alpha.PodSandboxStatsResponse , err error ) {
1282- if err := in .checkInitialized (); err != nil {
1294+ if err := in .checkInitialized (ctx ); err != nil {
12831295 return nil , err
12841296 }
12851297 log .G (ctx ).Debugf ("PodSandboxStats for %q" , r .GetPodSandboxId ())
@@ -1332,7 +1344,7 @@ func (in *instrumentedService) ContainerStats(ctx context.Context, r *runtime.Co
13321344}
13331345
13341346func (in * instrumentedAlphaService ) ContainerStats (ctx context.Context , r * runtime_alpha.ContainerStatsRequest ) (res * runtime_alpha.ContainerStatsResponse , err error ) {
1335- if err := in .checkInitialized (); err != nil {
1347+ if err := in .checkInitialized (ctx ); err != nil {
13361348 return nil , err
13371349 }
13381350 log .G (ctx ).Debugf ("ContainerStats for %q" , r .GetContainerId ())
@@ -1385,7 +1397,7 @@ func (in *instrumentedService) ListPodSandboxStats(ctx context.Context, r *runti
13851397}
13861398
13871399func (in * instrumentedAlphaService ) ListPodSandboxStats (ctx context.Context , r * runtime_alpha.ListPodSandboxStatsRequest ) (res * runtime_alpha.ListPodSandboxStatsResponse , err error ) {
1388- if err := in .checkInitialized (); err != nil {
1400+ if err := in .checkInitialized (ctx ); err != nil {
13891401 return nil , err
13901402 }
13911403 log .G (ctx ).Tracef ("ListPodSandboxStats with filter %+v" , r .GetFilter ())
@@ -1438,7 +1450,7 @@ func (in *instrumentedService) ListContainerStats(ctx context.Context, r *runtim
14381450}
14391451
14401452func (in * instrumentedAlphaService ) ListContainerStats (ctx context.Context , r * runtime_alpha.ListContainerStatsRequest ) (res * runtime_alpha.ListContainerStatsResponse , err error ) {
1441- if err := in .checkInitialized (); err != nil {
1453+ if err := in .checkInitialized (ctx ); err != nil {
14421454 return nil , err
14431455 }
14441456 log .G (ctx ).Tracef ("ListContainerStats with filter %+v" , r .GetFilter ())
@@ -1491,14 +1503,7 @@ func (in *instrumentedService) Status(ctx context.Context, r *runtime.StatusRequ
14911503}
14921504
14931505func (in * instrumentedAlphaService ) Status (ctx context.Context , r * runtime_alpha.StatusRequest ) (res * runtime_alpha.StatusResponse , err error ) {
1494- // Only emit the warning the first time an v1alpha2 api is called
1495- in .emitWarning .Do (func () {
1496- log .G (ctx ).Warning ("CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead." )
1497- if in .warn != nil {
1498- in .warn .Emit (ctx , deprecation .CRIAPIV1Alpha2 )
1499- }
1500- })
1501- if err := in .checkInitialized (); err != nil {
1506+ if err := in .checkInitialized (ctx ); err != nil {
15021507 return nil , err
15031508 }
15041509 log .G (ctx ).Tracef ("Status" )
@@ -1551,14 +1556,7 @@ func (in *instrumentedService) Version(ctx context.Context, r *runtime.VersionRe
15511556}
15521557
15531558func (in * instrumentedAlphaService ) Version (ctx context.Context , r * runtime_alpha.VersionRequest ) (res * runtime_alpha.VersionResponse , err error ) {
1554- // Only emit the warning the first time the v1alpha2 api is called
1555- in .emitWarning .Do (func () {
1556- log .G (ctx ).Warning ("CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead." )
1557- if in .warn != nil {
1558- in .warn .Emit (ctx , deprecation .CRIAPIV1Alpha2 )
1559- }
1560- })
1561- if err := in .checkInitialized (); err != nil {
1559+ if err := in .checkInitialized (ctx ); err != nil {
15621560 return nil , err
15631561 }
15641562 log .G (ctx ).Tracef ("Version with client side version %q" , r .GetVersion ())
@@ -1590,7 +1588,7 @@ func (in *instrumentedService) UpdateRuntimeConfig(ctx context.Context, r *runti
15901588}
15911589
15921590func (in * instrumentedAlphaService ) UpdateRuntimeConfig (ctx context.Context , r * runtime_alpha.UpdateRuntimeConfigRequest ) (res * runtime_alpha.UpdateRuntimeConfigResponse , err error ) {
1593- if err := in .checkInitialized (); err != nil {
1591+ if err := in .checkInitialized (ctx ); err != nil {
15941592 return nil , err
15951593 }
15961594 log .G (ctx ).Debugf ("UpdateRuntimeConfig with config %+v" , r .GetRuntimeConfig ())
@@ -1643,7 +1641,7 @@ func (in *instrumentedService) ReopenContainerLog(ctx context.Context, r *runtim
16431641}
16441642
16451643func (in * instrumentedAlphaService ) ReopenContainerLog (ctx context.Context , r * runtime_alpha.ReopenContainerLogRequest ) (res * runtime_alpha.ReopenContainerLogResponse , err error ) {
1646- if err := in .checkInitialized (); err != nil {
1644+ if err := in .checkInitialized (ctx ); err != nil {
16471645 return nil , err
16481646 }
16491647 log .G (ctx ).Debugf ("ReopenContainerLog for %q" , r .GetContainerId ())
0 commit comments