Skip to content

Commit 64e56bf

Browse files
committed
Add cri-api v1alpha2 usage warning to all api calls
Signed-off-by: ruiwen-zhao <ruiwen@google.com> (cherry picked from commit dc45bc8) Signed-off-by: ruiwen-zhao <ruiwen@google.com>
1 parent c566b7d commit 64e56bf

1 file changed

Lines changed: 42 additions & 44 deletions

File tree

pkg/cri/server/instrumented_service.go

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,25 @@ func (in *instrumentedService) checkInitialized() error {
6666
// GRPC service request handlers should return error before server is fully
6767
// initialized.
6868
// NOTE(random-liu): All following functions MUST check initialized at the beginning.
69-
func (in *instrumentedAlphaService) checkInitialized() error {
69+
func (in *instrumentedAlphaService) checkInitialized(ctx context.Context) error {
70+
in.emitUsageWarning(ctx)
7071
if in.c.initialized.IsSet() {
7172
return nil
7273
}
7374
return errors.New("server is not initialized yet")
7475
}
7576

77+
// emitUsageWarning emits a warning when v1alpha2 cri-api is called.
78+
func (in *instrumentedAlphaService) emitUsageWarning(ctx context.Context) {
79+
// Only emit the warning the first time an v1alpha2 api is called
80+
in.emitWarning.Do(func() {
81+
log.G(ctx).Warning("CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead.")
82+
if in.warn != nil {
83+
in.warn.Emit(ctx, deprecation.CRIAPIV1Alpha2)
84+
}
85+
})
86+
}
87+
7688
func (in *instrumentedService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (res *runtime.RunPodSandboxResponse, err error) {
7789
if err := in.checkInitialized(); err != nil {
7890
return nil, err
@@ -90,7 +102,7 @@ func (in *instrumentedService) RunPodSandbox(ctx context.Context, r *runtime.Run
90102
}
91103

92104
func (in *instrumentedAlphaService) RunPodSandbox(ctx context.Context, r *runtime_alpha.RunPodSandboxRequest) (res *runtime_alpha.RunPodSandboxResponse, err error) {
93-
if err := in.checkInitialized(); err != nil {
105+
if err := in.checkInitialized(ctx); err != nil {
94106
return nil, err
95107
}
96108
log.G(ctx).Infof("RunPodSandbox for %+v", r.GetConfig().GetMetadata())
@@ -143,7 +155,7 @@ func (in *instrumentedService) ListPodSandbox(ctx context.Context, r *runtime.Li
143155
}
144156

145157
func (in *instrumentedAlphaService) ListPodSandbox(ctx context.Context, r *runtime_alpha.ListPodSandboxRequest) (res *runtime_alpha.ListPodSandboxResponse, err error) {
146-
if err := in.checkInitialized(); err != nil {
158+
if err := in.checkInitialized(ctx); err != nil {
147159
return nil, err
148160
}
149161
log.G(ctx).Tracef("ListPodSandbox with filter %+v", r.GetFilter())
@@ -196,7 +208,7 @@ func (in *instrumentedService) PodSandboxStatus(ctx context.Context, r *runtime.
196208
}
197209

198210
func (in *instrumentedAlphaService) PodSandboxStatus(ctx context.Context, r *runtime_alpha.PodSandboxStatusRequest) (res *runtime_alpha.PodSandboxStatusResponse, err error) {
199-
if err := in.checkInitialized(); err != nil {
211+
if err := in.checkInitialized(ctx); err != nil {
200212
return nil, err
201213
}
202214
log.G(ctx).Tracef("PodSandboxStatus for %q", r.GetPodSandboxId())
@@ -249,7 +261,7 @@ func (in *instrumentedService) StopPodSandbox(ctx context.Context, r *runtime.St
249261
}
250262

251263
func (in *instrumentedAlphaService) StopPodSandbox(ctx context.Context, r *runtime_alpha.StopPodSandboxRequest) (res *runtime_alpha.StopPodSandboxResponse, err error) {
252-
if err := in.checkInitialized(); err != nil {
264+
if err := in.checkInitialized(ctx); err != nil {
253265
return nil, err
254266
}
255267
log.G(ctx).Infof("StopPodSandbox for %q", r.GetPodSandboxId())
@@ -302,7 +314,7 @@ func (in *instrumentedService) RemovePodSandbox(ctx context.Context, r *runtime.
302314
}
303315

304316
func (in *instrumentedAlphaService) RemovePodSandbox(ctx context.Context, r *runtime_alpha.RemovePodSandboxRequest) (res *runtime_alpha.RemovePodSandboxResponse, err error) {
305-
if err := in.checkInitialized(); err != nil {
317+
if err := in.checkInitialized(ctx); err != nil {
306318
return nil, err
307319
}
308320
log.G(ctx).Infof("RemovePodSandbox for %q", r.GetPodSandboxId())
@@ -355,7 +367,7 @@ func (in *instrumentedService) PortForward(ctx context.Context, r *runtime.PortF
355367
}
356368

357369
func (in *instrumentedAlphaService) PortForward(ctx context.Context, r *runtime_alpha.PortForwardRequest) (res *runtime_alpha.PortForwardResponse, err error) {
358-
if err := in.checkInitialized(); err != nil {
370+
if err := in.checkInitialized(ctx); err != nil {
359371
return nil, err
360372
}
361373
log.G(ctx).Infof("Portforward for %q port %v", r.GetPodSandboxId(), r.GetPort())
@@ -411,7 +423,7 @@ func (in *instrumentedService) CreateContainer(ctx context.Context, r *runtime.C
411423
}
412424

413425
func (in *instrumentedAlphaService) CreateContainer(ctx context.Context, r *runtime_alpha.CreateContainerRequest) (res *runtime_alpha.CreateContainerResponse, err error) {
414-
if err := in.checkInitialized(); err != nil {
426+
if err := in.checkInitialized(ctx); err != nil {
415427
return nil, err
416428
}
417429
log.G(ctx).Infof("CreateContainer within sandbox %q for container %+v",
@@ -468,7 +480,7 @@ func (in *instrumentedService) StartContainer(ctx context.Context, r *runtime.St
468480
}
469481

470482
func (in *instrumentedAlphaService) StartContainer(ctx context.Context, r *runtime_alpha.StartContainerRequest) (res *runtime_alpha.StartContainerResponse, err error) {
471-
if err := in.checkInitialized(); err != nil {
483+
if err := in.checkInitialized(ctx); err != nil {
472484
return nil, err
473485
}
474486
log.G(ctx).Infof("StartContainer for %q", r.GetContainerId())
@@ -522,7 +534,7 @@ func (in *instrumentedService) ListContainers(ctx context.Context, r *runtime.Li
522534
}
523535

524536
func (in *instrumentedAlphaService) ListContainers(ctx context.Context, r *runtime_alpha.ListContainersRequest) (res *runtime_alpha.ListContainersResponse, err error) {
525-
if err := in.checkInitialized(); err != nil {
537+
if err := in.checkInitialized(ctx); err != nil {
526538
return nil, err
527539
}
528540
log.G(ctx).Tracef("ListContainers with filter %+v", r.GetFilter())
@@ -576,7 +588,7 @@ func (in *instrumentedService) ContainerStatus(ctx context.Context, r *runtime.C
576588
}
577589

578590
func (in *instrumentedAlphaService) ContainerStatus(ctx context.Context, r *runtime_alpha.ContainerStatusRequest) (res *runtime_alpha.ContainerStatusResponse, err error) {
579-
if err := in.checkInitialized(); err != nil {
591+
if err := in.checkInitialized(ctx); err != nil {
580592
return nil, err
581593
}
582594
log.G(ctx).Tracef("ContainerStatus for %q", r.GetContainerId())
@@ -629,7 +641,7 @@ func (in *instrumentedService) StopContainer(ctx context.Context, r *runtime.Sto
629641
}
630642

631643
func (in *instrumentedAlphaService) StopContainer(ctx context.Context, r *runtime_alpha.StopContainerRequest) (res *runtime_alpha.StopContainerResponse, err error) {
632-
if err := in.checkInitialized(); err != nil {
644+
if err := in.checkInitialized(ctx); err != nil {
633645
return nil, err
634646
}
635647
log.G(ctx).Infof("StopContainer for %q with timeout %d (s)", r.GetContainerId(), r.GetTimeout())
@@ -682,7 +694,7 @@ func (in *instrumentedService) RemoveContainer(ctx context.Context, r *runtime.R
682694
}
683695

684696
func (in *instrumentedAlphaService) RemoveContainer(ctx context.Context, r *runtime_alpha.RemoveContainerRequest) (res *runtime_alpha.RemoveContainerResponse, err error) {
685-
if err := in.checkInitialized(); err != nil {
697+
if err := in.checkInitialized(ctx); err != nil {
686698
return nil, err
687699
}
688700
log.G(ctx).Infof("RemoveContainer for %q", r.GetContainerId())
@@ -735,7 +747,7 @@ func (in *instrumentedService) ExecSync(ctx context.Context, r *runtime.ExecSync
735747
}
736748

737749
func (in *instrumentedAlphaService) ExecSync(ctx context.Context, r *runtime_alpha.ExecSyncRequest) (res *runtime_alpha.ExecSyncResponse, err error) {
738-
if err := in.checkInitialized(); err != nil {
750+
if err := in.checkInitialized(ctx); err != nil {
739751
return nil, err
740752
}
741753
log.G(ctx).Debugf("ExecSync for %q with command %+v and timeout %d (s)", r.GetContainerId(), r.GetCmd(), r.GetTimeout())
@@ -789,7 +801,7 @@ func (in *instrumentedService) Exec(ctx context.Context, r *runtime.ExecRequest)
789801
}
790802

791803
func (in *instrumentedAlphaService) Exec(ctx context.Context, r *runtime_alpha.ExecRequest) (res *runtime_alpha.ExecResponse, err error) {
792-
if err := in.checkInitialized(); err != nil {
804+
if err := in.checkInitialized(ctx); err != nil {
793805
return nil, err
794806
}
795807
log.G(ctx).Debugf("Exec for %q with command %+v, tty %v and stdin %v",
@@ -843,7 +855,7 @@ func (in *instrumentedService) Attach(ctx context.Context, r *runtime.AttachRequ
843855
}
844856

845857
func (in *instrumentedAlphaService) Attach(ctx context.Context, r *runtime_alpha.AttachRequest) (res *runtime_alpha.AttachResponse, err error) {
846-
if err := in.checkInitialized(); err != nil {
858+
if err := in.checkInitialized(ctx); err != nil {
847859
return nil, err
848860
}
849861
log.G(ctx).Debugf("Attach for %q with tty %v and stdin %v", r.GetContainerId(), r.GetTty(), r.GetStdin())
@@ -896,7 +908,7 @@ func (in *instrumentedService) UpdateContainerResources(ctx context.Context, r *
896908
}
897909

898910
func (in *instrumentedAlphaService) UpdateContainerResources(ctx context.Context, r *runtime_alpha.UpdateContainerResourcesRequest) (res *runtime_alpha.UpdateContainerResourcesResponse, err error) {
899-
if err := in.checkInitialized(); err != nil {
911+
if err := in.checkInitialized(ctx); err != nil {
900912
return nil, err
901913
}
902914
log.G(ctx).Infof("UpdateContainerResources for %q with Linux: %+v / Windows: %+v", r.GetContainerId(), r.GetLinux(), r.GetWindows())
@@ -950,7 +962,7 @@ func (in *instrumentedService) PullImage(ctx context.Context, r *runtime.PullIma
950962
}
951963

952964
func (in *instrumentedAlphaService) PullImage(ctx context.Context, r *runtime_alpha.PullImageRequest) (res *runtime_alpha.PullImageResponse, err error) {
953-
if err := in.checkInitialized(); err != nil {
965+
if err := in.checkInitialized(ctx); err != nil {
954966
return nil, err
955967
}
956968
log.G(ctx).Infof("PullImage %q", r.GetImage().GetImage())
@@ -1005,7 +1017,7 @@ func (in *instrumentedService) ListImages(ctx context.Context, r *runtime.ListIm
10051017
}
10061018

10071019
func (in *instrumentedAlphaService) ListImages(ctx context.Context, r *runtime_alpha.ListImagesRequest) (res *runtime_alpha.ListImagesResponse, err error) {
1008-
if err := in.checkInitialized(); err != nil {
1020+
if err := in.checkInitialized(ctx); err != nil {
10091021
return nil, err
10101022
}
10111023
log.G(ctx).Tracef("ListImages with filter %+v", r.GetFilter())
@@ -1060,7 +1072,7 @@ func (in *instrumentedService) ImageStatus(ctx context.Context, r *runtime.Image
10601072
}
10611073

10621074
func (in *instrumentedAlphaService) ImageStatus(ctx context.Context, r *runtime_alpha.ImageStatusRequest) (res *runtime_alpha.ImageStatusResponse, err error) {
1063-
if err := in.checkInitialized(); err != nil {
1075+
if err := in.checkInitialized(ctx); err != nil {
10641076
return nil, err
10651077
}
10661078
log.G(ctx).Tracef("ImageStatus for %q", r.GetImage().GetImage())
@@ -1114,7 +1126,7 @@ func (in *instrumentedService) RemoveImage(ctx context.Context, r *runtime.Remov
11141126
}
11151127

11161128
func (in *instrumentedAlphaService) RemoveImage(ctx context.Context, r *runtime_alpha.RemoveImageRequest) (res *runtime_alpha.RemoveImageResponse, err error) {
1117-
if err := in.checkInitialized(); err != nil {
1129+
if err := in.checkInitialized(ctx); err != nil {
11181130
return nil, err
11191131
}
11201132
log.G(ctx).Infof("RemoveImage %q", r.GetImage().GetImage())
@@ -1167,7 +1179,7 @@ func (in *instrumentedService) ImageFsInfo(ctx context.Context, r *runtime.Image
11671179
}
11681180

11691181
func (in *instrumentedAlphaService) ImageFsInfo(ctx context.Context, r *runtime_alpha.ImageFsInfoRequest) (res *runtime_alpha.ImageFsInfoResponse, err error) {
1170-
if err := in.checkInitialized(); err != nil {
1182+
if err := in.checkInitialized(ctx); err != nil {
11711183
return nil, err
11721184
}
11731185
log.G(ctx).Debugf("ImageFsInfo")
@@ -1220,7 +1232,7 @@ func (in *instrumentedService) PodSandboxStats(ctx context.Context, r *runtime.P
12201232
}
12211233

12221234
func (in *instrumentedAlphaService) PodSandboxStats(ctx context.Context, r *runtime_alpha.PodSandboxStatsRequest) (res *runtime_alpha.PodSandboxStatsResponse, err error) {
1223-
if err := in.checkInitialized(); err != nil {
1235+
if err := in.checkInitialized(ctx); err != nil {
12241236
return nil, err
12251237
}
12261238
log.G(ctx).Debugf("PodSandboxStats for %q", r.GetPodSandboxId())
@@ -1273,7 +1285,7 @@ func (in *instrumentedService) ContainerStats(ctx context.Context, r *runtime.Co
12731285
}
12741286

12751287
func (in *instrumentedAlphaService) ContainerStats(ctx context.Context, r *runtime_alpha.ContainerStatsRequest) (res *runtime_alpha.ContainerStatsResponse, err error) {
1276-
if err := in.checkInitialized(); err != nil {
1288+
if err := in.checkInitialized(ctx); err != nil {
12771289
return nil, err
12781290
}
12791291
log.G(ctx).Debugf("ContainerStats for %q", r.GetContainerId())
@@ -1326,7 +1338,7 @@ func (in *instrumentedService) ListPodSandboxStats(ctx context.Context, r *runti
13261338
}
13271339

13281340
func (in *instrumentedAlphaService) ListPodSandboxStats(ctx context.Context, r *runtime_alpha.ListPodSandboxStatsRequest) (res *runtime_alpha.ListPodSandboxStatsResponse, err error) {
1329-
if err := in.checkInitialized(); err != nil {
1341+
if err := in.checkInitialized(ctx); err != nil {
13301342
return nil, err
13311343
}
13321344
log.G(ctx).Tracef("ListPodSandboxStats with filter %+v", r.GetFilter())
@@ -1379,7 +1391,7 @@ func (in *instrumentedService) ListContainerStats(ctx context.Context, r *runtim
13791391
}
13801392

13811393
func (in *instrumentedAlphaService) ListContainerStats(ctx context.Context, r *runtime_alpha.ListContainerStatsRequest) (res *runtime_alpha.ListContainerStatsResponse, err error) {
1382-
if err := in.checkInitialized(); err != nil {
1394+
if err := in.checkInitialized(ctx); err != nil {
13831395
return nil, err
13841396
}
13851397
log.G(ctx).Tracef("ListContainerStats with filter %+v", r.GetFilter())
@@ -1432,14 +1444,7 @@ func (in *instrumentedService) Status(ctx context.Context, r *runtime.StatusRequ
14321444
}
14331445

14341446
func (in *instrumentedAlphaService) Status(ctx context.Context, r *runtime_alpha.StatusRequest) (res *runtime_alpha.StatusResponse, err error) {
1435-
// Only emit the warning the first time an v1alpha2 api is called
1436-
in.emitWarning.Do(func() {
1437-
log.G(ctx).Warning("CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead.")
1438-
if in.warn != nil {
1439-
in.warn.Emit(ctx, deprecation.CRIAPIV1Alpha2)
1440-
}
1441-
})
1442-
if err := in.checkInitialized(); err != nil {
1447+
if err := in.checkInitialized(ctx); err != nil {
14431448
return nil, err
14441449
}
14451450
log.G(ctx).Tracef("Status")
@@ -1492,14 +1497,7 @@ func (in *instrumentedService) Version(ctx context.Context, r *runtime.VersionRe
14921497
}
14931498

14941499
func (in *instrumentedAlphaService) Version(ctx context.Context, r *runtime_alpha.VersionRequest) (res *runtime_alpha.VersionResponse, err error) {
1495-
// Only emit the warning the first time the v1alpha2 api is called
1496-
in.emitWarning.Do(func() {
1497-
log.G(ctx).Warning("CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead.")
1498-
if in.warn != nil {
1499-
in.warn.Emit(ctx, deprecation.CRIAPIV1Alpha2)
1500-
}
1501-
})
1502-
if err := in.checkInitialized(); err != nil {
1500+
if err := in.checkInitialized(ctx); err != nil {
15031501
return nil, err
15041502
}
15051503
log.G(ctx).Tracef("Version with client side version %q", r.GetVersion())
@@ -1531,7 +1529,7 @@ func (in *instrumentedService) UpdateRuntimeConfig(ctx context.Context, r *runti
15311529
}
15321530

15331531
func (in *instrumentedAlphaService) UpdateRuntimeConfig(ctx context.Context, r *runtime_alpha.UpdateRuntimeConfigRequest) (res *runtime_alpha.UpdateRuntimeConfigResponse, err error) {
1534-
if err := in.checkInitialized(); err != nil {
1532+
if err := in.checkInitialized(ctx); err != nil {
15351533
return nil, err
15361534
}
15371535
log.G(ctx).Debugf("UpdateRuntimeConfig with config %+v", r.GetRuntimeConfig())
@@ -1584,7 +1582,7 @@ func (in *instrumentedService) ReopenContainerLog(ctx context.Context, r *runtim
15841582
}
15851583

15861584
func (in *instrumentedAlphaService) ReopenContainerLog(ctx context.Context, r *runtime_alpha.ReopenContainerLogRequest) (res *runtime_alpha.ReopenContainerLogResponse, err error) {
1587-
if err := in.checkInitialized(); err != nil {
1585+
if err := in.checkInitialized(ctx); err != nil {
15881586
return nil, err
15891587
}
15901588
log.G(ctx).Debugf("ReopenContainerLog for %q", r.GetContainerId())

0 commit comments

Comments
 (0)