@@ -35,16 +35,17 @@ import (
35
35
containerTypes "github.com/bleemeo/glouton/facts/container-runtime/types"
36
36
"github.com/bleemeo/glouton/logger"
37
37
"github.com/bleemeo/glouton/types"
38
+
38
39
v1 "github.com/containerd/cgroups/v3/cgroup1/stats"
39
40
v2 "github.com/containerd/cgroups/v3/cgroup2/stats"
40
- "github.com/containerd/containerd"
41
41
pbEvents "github.com/containerd/containerd/api/events"
42
42
"github.com/containerd/containerd/api/services/tasks/v1"
43
- "github.com/containerd/containerd/cio"
44
- "github.com/containerd/containerd/containers"
45
- "github.com/containerd/containerd/events"
46
- "github.com/containerd/containerd/namespaces"
47
- "github.com/containerd/containerd/oci"
43
+ "github.com/containerd/containerd/v2/client"
44
+ "github.com/containerd/containerd/v2/core/containers"
45
+ "github.com/containerd/containerd/v2/core/events"
46
+ "github.com/containerd/containerd/v2/pkg/cio"
47
+ "github.com/containerd/containerd/v2/pkg/namespaces"
48
+ "github.com/containerd/containerd/v2/pkg/oci"
48
49
"github.com/containerd/errdefs"
49
50
"github.com/containerd/typeurl/v2"
50
51
"github.com/mitchellh/copystructure"
@@ -129,10 +130,10 @@ func (c *Containerd) DiagnosticArchive(_ context.Context, archive types.ArchiveW
129
130
IsIgnored bool
130
131
}
131
132
132
- containers := make ([]containerInfo , 0 , len (c .containers ))
133
+ ctrs := make ([]containerInfo , 0 , len (c .containers ))
133
134
134
135
for _ , row := range c .containers {
135
- containers = append (containers , containerInfo {
136
+ ctrs = append (ctrs , containerInfo {
136
137
ID : row .ID (),
137
138
Name : row .ContainerName (),
138
139
IsIgnored : c .ignoredID [row .ID ()],
@@ -147,7 +148,7 @@ func (c *Containerd) DiagnosticArchive(_ context.Context, archive types.ArchiveW
147
148
PastMetricValues []metricValue
148
149
}{
149
150
WorkedOnce : c .workedOnce ,
150
- Containers : containers ,
151
+ Containers : ctrs ,
151
152
LastDestroyedName : c .lastDestroyedName ,
152
153
LastUpdate : c .lastUpdate ,
153
154
PastMetricValues : c .pastMetricValues ,
@@ -477,21 +478,21 @@ func (c *Containerd) Exec(ctx context.Context, containerID string, cmd []string)
477
478
cio .WithStreams (nil , buffer , buffer ),
478
479
)
479
480
480
- process , err := task .Exec (ctx , "glouton-exec-id" , & pspec , ioCreator )
481
+ proc , err := task .Exec (ctx , "glouton-exec-id" , & pspec , ioCreator )
481
482
if err != nil {
482
483
return nil , err
483
484
}
484
485
485
- statusC , err := process .Wait (ctx )
486
+ statusC , err := proc .Wait (ctx )
486
487
if err != nil {
487
488
return nil , err
488
489
}
489
490
490
- if err := process .Start (ctx ); err != nil {
491
+ if err := proc .Start (ctx ); err != nil {
491
492
return nil , err
492
493
}
493
494
494
- var status containerd .ExitStatus
495
+ var status client .ExitStatus
495
496
496
497
select {
497
498
case status = <- statusC :
@@ -763,7 +764,7 @@ func (c *Containerd) updateContainers(ctx context.Context) error {
763
764
return fmt .Errorf ("listing namespaces failed: %w" , err )
764
765
}
765
766
766
- containers := make (map [string ]containerObject )
767
+ ctrs := make (map [string ]containerObject )
767
768
ignoredID := make (map [string ]bool )
768
769
769
770
for _ , ns := range nsList {
@@ -773,7 +774,7 @@ func (c *Containerd) updateContainers(ctx context.Context) error {
773
774
774
775
ctx := namespaces .WithNamespace (ctx , ns )
775
776
776
- err := c .addContainersInfo (ctx , containers , cl , ns , ignoredID )
777
+ err := c .addContainersInfo (ctx , ctrs , cl , ns , ignoredID )
777
778
if err != nil {
778
779
return err
779
780
}
@@ -782,7 +783,7 @@ func (c *Containerd) updateContainers(ctx context.Context) error {
782
783
var deletedContainerID []string
783
784
784
785
for k := range c .containers {
785
- if _ , ok := containers [k ]; ! ok {
786
+ if _ , ok := ctrs [k ]; ! ok {
786
787
deletedContainerID = append (deletedContainerID , k )
787
788
}
788
789
}
@@ -796,20 +797,20 @@ func (c *Containerd) updateContainers(ctx context.Context) error {
796
797
"ContainerD runtime request to delete %d containers (previous container count was %d, new containers count is %d)" ,
797
798
len (deletedContainerID ),
798
799
len (c .containers ),
799
- len (containers ),
800
+ len (ctrs ),
800
801
)
801
802
c .DeletedContainersCallback (deletedContainerID )
802
803
}
803
804
804
805
c .lastUpdate = time .Now ()
805
- c .containers = containers
806
+ c .containers = ctrs
806
807
c .ignoredID = ignoredID
807
808
808
809
return nil
809
810
}
810
811
811
- func convertToContainerObject (ctx context.Context , ns string , cont containerd .Container ) (containerObject , error ) {
812
- info , err := cont .Info (ctx , containerd .WithoutRefreshedMetadata )
812
+ func convertToContainerObject (ctx context.Context , ns string , cont client .Container ) (containerObject , error ) {
813
+ info , err := cont .Info (ctx , client .WithoutRefreshedMetadata )
813
814
if err != nil {
814
815
return containerObject {}, fmt .Errorf ("Info() on %s/%s failed: %w" , ns , cont .ID (), err )
815
816
}
@@ -840,7 +841,7 @@ func convertToContainerObject(ctx context.Context, ns string, cont containerd.Co
840
841
Container : info ,
841
842
Spec : & spec ,
842
843
},
843
- state : string (containerd .Unknown ),
844
+ state : string (client .Unknown ),
844
845
imageID : imgDigest ,
845
846
}
846
847
@@ -931,11 +932,13 @@ func (c *Containerd) getClient(ctx context.Context) (containerdClient, error) {
931
932
_ , err = cl .Version (ctx )
932
933
if err != nil {
933
934
if firstErr == nil {
934
- logger .V (2 ).Printf ("ContainerD openConnection on %s failed: %v" , addr , err )
935
+ logger .V (2 ).Printf ("ContainerD interaction on %s failed: %v" , addr , err )
935
936
936
937
firstErr = err
937
938
}
938
939
940
+ _ = cl .Close ()
941
+
939
942
continue
940
943
}
941
944
@@ -955,9 +958,9 @@ func (c *Containerd) getClient(ctx context.Context) (containerdClient, error) {
955
958
}
956
959
957
960
type containerdClient interface {
958
- LoadContainer (ctx context.Context , id string ) (containerd .Container , error )
959
- Containers (ctx context.Context ) ([]containerd .Container , error )
960
- Version (ctx context.Context ) (containerd .Version , error )
961
+ LoadContainer (ctx context.Context , id string ) (client .Container , error )
962
+ Containers (ctx context.Context ) ([]client .Container , error )
963
+ Version (ctx context.Context ) (client .Version , error )
961
964
Namespaces (ctx context.Context ) ([]string , error )
962
965
Events (ctx context.Context ) (ch <- chan * events.Envelope , errs <- chan error )
963
966
Metrics (ctx context.Context , filters []string ) (* tasks.MetricsResponse , error )
@@ -972,27 +975,27 @@ func openConnection(_ context.Context, address string) (containerdClient, error)
972
975
}
973
976
}
974
977
975
- client , err := containerd .New (address )
978
+ cl , err := client .New (address )
976
979
if err != nil {
977
980
return nil , fmt .Errorf ("failed to connect to containerd at address %s: %w" , address , err )
978
981
}
979
982
980
- return realClient {client : client }, nil
983
+ return realClient {client : cl }, nil
981
984
}
982
985
983
986
type realClient struct {
984
- client * containerd .Client
987
+ client * client .Client
985
988
}
986
989
987
- func (cl realClient ) Containers (ctx context.Context ) ([]containerd .Container , error ) {
990
+ func (cl realClient ) Containers (ctx context.Context ) ([]client .Container , error ) {
988
991
return cl .client .Containers (ctx )
989
992
}
990
993
991
- func (cl realClient ) LoadContainer (ctx context.Context , id string ) (containerd .Container , error ) {
994
+ func (cl realClient ) LoadContainer (ctx context.Context , id string ) (client .Container , error ) {
992
995
return cl .client .LoadContainer (ctx , id )
993
996
}
994
997
995
- func (cl realClient ) Version (ctx context.Context ) (containerd .Version , error ) {
998
+ func (cl realClient ) Version (ctx context.Context ) (client .Version , error ) {
996
999
return cl .client .Version (ctx )
997
1000
}
998
1001
@@ -1153,18 +1156,18 @@ func (c containerObject) StartedAt() time.Time {
1153
1156
}
1154
1157
1155
1158
func (c containerObject ) State () facts.ContainerState {
1156
- switch containerd .ProcessStatus (c .state ) {
1157
- case containerd .Created :
1159
+ switch client .ProcessStatus (c .state ) {
1160
+ case client .Created :
1158
1161
return facts .ContainerCreated
1159
- case containerd .Paused :
1162
+ case client .Paused :
1160
1163
return facts .ContainerRunning
1161
- case containerd .Pausing :
1164
+ case client .Pausing :
1162
1165
return facts .ContainerRunning
1163
- case containerd .Running :
1166
+ case client .Running :
1164
1167
return facts .ContainerRunning
1165
- case containerd .Stopped :
1168
+ case client .Stopped :
1166
1169
return facts .ContainerStopped
1167
- case containerd .Unknown :
1170
+ case client .Unknown :
1168
1171
return facts .ContainerUnknown
1169
1172
default :
1170
1173
return facts .ContainerUnknown
@@ -1205,7 +1208,7 @@ var cgroupRE = regexp.MustCompile(
1205
1208
1206
1209
type namespaceContainer struct {
1207
1210
namespace string
1208
- container containerd .Container
1211
+ container client .Container
1209
1212
}
1210
1213
1211
1214
type containerdProcessQuerier struct {
0 commit comments