Skip to content

Commit 1b3a96d

Browse files
committed
cri: propagate deprecation list to runtime status
Propagate the deprecation list to CRI runtime conditions. The propagated conditions are visible via `crictl info`, but not visible via `kubectl get nodes -o yaml` yet, although the CRI API says "These conditions will be exposed to users to help them understand the status of the system". https://github.com/kubernetes/cri-api/blob/v0.29.1/pkg/apis/runtime/v1/api.proto#L1505-L1509 Signed-off-by: Akihiro Suda <[email protected]>
1 parent dd725fa commit 1b3a96d

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

internal/cri/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ type RuntimeConfig struct {
394394
//
395395
// For example, the value can be '5h', '2h30m', '10s'.
396396
DrainExecSyncIOTimeout string `toml:"drain_exec_sync_io_timeout" json:"drainExecSyncIOTimeout"`
397+
398+
// IgnoreDeprecationWarnings is the list of the deprecation IDs (such as "io.containerd.deprecation/pull-schema-1-image")
399+
// that should be ignored for checking "ContainerdHasNoDeprecationWarnings" condition.
400+
IgnoreDeprecationWarnings []string `toml:"ignore_deprecation_warnings" json:"ignoreDeprecationWarnings"`
397401
}
398402

399403
// X509KeyPairStreaming contains the x509 configuration for streaming

internal/cri/server/status.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"fmt"
2323
goruntime "runtime"
2424

25+
"github.com/containerd/containerd/v2/api/services/introspection/v1"
26+
ptypes "github.com/containerd/containerd/v2/protobuf/types"
2527
"github.com/containerd/log"
2628
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
2729
)
@@ -94,5 +96,51 @@ func (c *criService) Status(ctx context.Context, r *runtime.StatusRequest) (*run
9496
}
9597
resp.Info["lastCNILoadStatus"] = defaultStatus
9698
}
99+
intro, err := c.client.IntrospectionService().Server(ctx, &ptypes.Empty{})
100+
if err != nil {
101+
return nil, err
102+
}
103+
cond, err := runtimeConditionContainerdHasNoDeprecationWarnings(intro.Deprecations, c.config.IgnoreDeprecationWarnings)
104+
if err != nil {
105+
return nil, err
106+
}
107+
resp.Status.Conditions = append(resp.Status.Conditions, cond)
97108
return resp, nil
98109
}
110+
111+
func runtimeConditionContainerdHasNoDeprecationWarnings(deprecations []*introspection.DeprecationWarning, ignore []string) (*runtime.RuntimeCondition, error) {
112+
cond := &runtime.RuntimeCondition{
113+
Type: ContainerdHasNoDeprecationWarnings,
114+
Status: true,
115+
}
116+
ignoreM := make(map[string]struct{})
117+
for _, f := range ignore {
118+
ignoreM[f] = struct{}{}
119+
}
120+
messages := make(map[string]string) // key: id, value: message
121+
for _, d := range deprecations {
122+
if _, ok := ignoreM[d.ID]; !ok {
123+
messages[d.ID] = d.Message
124+
}
125+
}
126+
if len(messages) > 0 {
127+
cond.Status = false
128+
cond.Reason = ContainerdHasDeprecationWarnings
129+
messageJ, err := json.Marshal(messages)
130+
if err != nil {
131+
return nil, err
132+
}
133+
cond.Message = string(messageJ) // Arbitrary string
134+
}
135+
return cond, nil
136+
}
137+
138+
const (
139+
// ContainerdHasNoDeprecationWarnings is a string for [runtime.RuntimeCondition.Type].
140+
ContainerdHasNoDeprecationWarnings = "ContainerdHasNoDeprecationWarnings"
141+
142+
// ContainerdHasDeprecationWarnings is a string for [runtime.RuntimeCondition.Reason].
143+
// CamelCase is demanded by the spec.
144+
// https://github.com/kubernetes/cri-api/blob/v0.29.1/pkg/apis/runtime/v1/api.proto#L1514
145+
ContainerdHasDeprecationWarnings = "ContainerdHasDeprecationWarnings"
146+
)

internal/cri/server/status_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package server
18+
19+
import (
20+
"testing"
21+
22+
"github.com/containerd/containerd/v2/api/services/introspection/v1"
23+
"github.com/stretchr/testify/assert"
24+
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
25+
)
26+
27+
func TestRuntimeConditionContainerdHasNoDeprecationWarnings(t *testing.T) {
28+
deprecations := []*introspection.DeprecationWarning{
29+
{
30+
ID: "io.containerd.deprecation/foo",
31+
Message: "foo",
32+
},
33+
}
34+
35+
cond, err := runtimeConditionContainerdHasNoDeprecationWarnings(deprecations, nil)
36+
assert.NoError(t, err)
37+
assert.Equal(t, &runtime.RuntimeCondition{
38+
Type: ContainerdHasNoDeprecationWarnings,
39+
Status: false,
40+
Reason: ContainerdHasDeprecationWarnings,
41+
Message: `{"io.containerd.deprecation/foo":"foo"}`,
42+
}, cond)
43+
44+
cond, err = runtimeConditionContainerdHasNoDeprecationWarnings(deprecations, []string{"io.containerd.deprecation/foo"})
45+
assert.NoError(t, err)
46+
assert.Equal(t, &runtime.RuntimeCondition{
47+
Type: ContainerdHasNoDeprecationWarnings,
48+
Status: true,
49+
}, cond)
50+
}

0 commit comments

Comments
 (0)