@@ -49,12 +49,13 @@ const (
49
49
50
50
// OCIBundleReconciler tries to import OCI bundle into the running containerd instance
51
51
type OCIBundleReconciler struct {
52
- k0sVars * config.CfgVars
53
- log * logrus.Entry
54
- alreadyImported map [string ]time.Time
55
- mtx sync.Mutex
56
- cancel context.CancelFunc
57
- end chan struct {}
52
+ ociBundleDir string
53
+ containerdAddress string
54
+ log * logrus.Entry
55
+ alreadyImported map [string ]time.Time
56
+ mtx sync.Mutex
57
+ cancel context.CancelFunc
58
+ end chan struct {}
58
59
* prober.EventEmitter
59
60
}
60
61
@@ -63,25 +64,25 @@ var _ manager.Component = (*OCIBundleReconciler)(nil)
63
64
// NewOCIBundleReconciler builds new reconciler
64
65
func NewOCIBundleReconciler (vars * config.CfgVars ) * OCIBundleReconciler {
65
66
return & OCIBundleReconciler {
66
- k0sVars : vars ,
67
- log : logrus .WithField ("component" , "OCIBundleReconciler" ),
68
- EventEmitter : prober .NewEventEmitter (),
69
- alreadyImported : map [string ]time.Time {},
70
- end : make (chan struct {}),
67
+ ociBundleDir : vars .OCIBundleDir ,
68
+ containerdAddress : GetContainerdAddress (vars .RunDir ),
69
+ log : logrus .WithField ("component" , "OCIBundleReconciler" ),
70
+ EventEmitter : prober .NewEventEmitter (),
71
+ alreadyImported : map [string ]time.Time {},
72
+ end : make (chan struct {}),
71
73
}
72
74
}
73
75
74
76
func (a * OCIBundleReconciler ) Init (_ context.Context ) error {
75
- return dir .Init (a .k0sVars . OCIBundleDir , constant .ManifestsDirMode )
77
+ return dir .Init (a .ociBundleDir , constant .ManifestsDirMode )
76
78
}
77
79
78
80
// containerdClient returns a connected containerd client.
79
81
func (a * OCIBundleReconciler ) containerdClient (ctx context.Context ) (* containerd.Client , error ) {
80
82
var client * containerd.Client
81
- sock := filepath .Join (a .k0sVars .RunDir , "containerd.sock" )
82
83
if err := retry .Do (func () (err error ) {
83
84
client , err = containerd .New (
84
- sock ,
85
+ a . containerdAddress ,
85
86
containerd .WithDefaultNamespace ("k8s.io" ),
86
87
containerd .WithDefaultPlatform (
87
88
platforms .Only (platforms .DefaultSpec ()),
@@ -126,14 +127,14 @@ func (a *OCIBundleReconciler) loadAll(ctx context.Context) {
126
127
defer a .mtx .Unlock ()
127
128
128
129
a .log .Info ("Loading OCI bundles directory" )
129
- files , err := os .ReadDir (a .k0sVars . OCIBundleDir )
130
+ files , err := os .ReadDir (a .ociBundleDir )
130
131
if err != nil {
131
132
a .log .WithError (err ).Errorf ("Failed to read bundles directory" )
132
133
return
133
134
}
134
135
a .EmitWithPayload ("importing OCI bundles" , files )
135
136
for _ , file := range files {
136
- fpath := filepath .Join (a .k0sVars . OCIBundleDir , file .Name ())
137
+ fpath := filepath .Join (a .ociBundleDir , file .Name ())
137
138
finfo , err := os .Stat (fpath )
138
139
if err != nil {
139
140
a .log .WithError (err ).Errorf ("failed to stat %s" , fpath )
@@ -237,7 +238,7 @@ func (a *OCIBundleReconciler) installWatcher(ctx context.Context) error {
237
238
return fmt .Errorf ("failed to create watcher: %w" , err )
238
239
}
239
240
240
- if err := watcher .Add (a .k0sVars . OCIBundleDir ); err != nil {
241
+ if err := watcher .Add (a .ociBundleDir ); err != nil {
241
242
return fmt .Errorf ("failed to add watcher: %w" , err )
242
243
}
243
244
@@ -261,7 +262,7 @@ func (a *OCIBundleReconciler) installWatcher(ctx context.Context) error {
261
262
262
263
go func () {
263
264
defer close (a .end )
264
- a .log .Infof ("Started to watch events on %s" , a .k0sVars . OCIBundleDir )
265
+ a .log .Infof ("Started to watch events on %s" , a .ociBundleDir )
265
266
_ = debouncer .Run (ctx )
266
267
if err := watcher .Close (); err != nil {
267
268
a .log .Errorf ("Failed to close watcher: %s" , err )
0 commit comments