@@ -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+ )
0 commit comments