Skip to content

Commit

Permalink
Merge pull request containerd#10571 from chrishenzie/v1alpha2-cri-api…
Browse files Browse the repository at this point in the history
…-warnings

[release/1.7] Ensure the CRIAPIV1Alpha2 warning's lastOccurrence is accurate
  • Loading branch information
samuelkarp authored Aug 12, 2024
2 parents 90367cc + 52b79f3 commit e242c6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/cri/instrument/instrumented_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ func (in *instrumentedAlphaService) checkInitialized(ctx context.Context) error

// emitUsageWarning emits a warning when v1alpha2 cri-api is called.
func (in *instrumentedAlphaService) emitUsageWarning(ctx context.Context) {
// Only emit the warning the first time an v1alpha2 api is called
// Only log the warning the first time an v1alpha2 api is called
in.emitWarning.Do(func() {
log.G(ctx).Warning("CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead.")
if in.warn != nil {
in.warn.Emit(ctx, deprecation.CRIAPIV1Alpha2)
}
})
if in.warn != nil {
in.warn.Emit(ctx, deprecation.CRIAPIV1Alpha2)
}
}

func (in *instrumentedService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandboxRequest) (res *runtime.RunPodSandboxResponse, err error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cri/server/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ func TestAlphaCRIWarning(t *testing.T) {
c.Version(ctx, &v1alpha2.VersionRequest{})
c.Status(ctx, &v1alpha2.StatusRequest{})

// Only emit the warning the first time an v1alpha2 api is called.
// Emit warnings both times an v1alpha2 api is called.
expectedWarnings := []deprecation.Warning{
deprecation.CRIAPIV1Alpha2,
deprecation.CRIAPIV1Alpha2,
}
assert.Equal(t, expectedWarnings, ws.GetWarnings())
}

0 comments on commit e242c6a

Please sign in to comment.