From b97ce20c1db583867896b52f1066588c89056353 Mon Sep 17 00:00:00 2001 From: Mikhail Sakhnov Date: Wed, 24 Mar 2021 10:38:18 +0200 Subject: [PATCH 1/2] Reduce amounts of attempts in OCI bundle import, add extended warnings between attempts to get rid of awkward silence in logs Signed-off-by: Mikhail Sakhnov --- pkg/component/worker/ocibundle.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/component/worker/ocibundle.go b/pkg/component/worker/ocibundle.go index 5fe04f98a9bb..39c431e2345c 100644 --- a/pkg/component/worker/ocibundle.go +++ b/pkg/component/worker/ocibundle.go @@ -61,17 +61,18 @@ func (a *OCIBundleReconciler) Run() error { client, err := containerd.New(sock, containerd.WithDefaultNamespace("k8s.io")) if err != nil { + logrus.WithError(err).Errorf("can't connect to containerd socket %s", sock) return fmt.Errorf("can't connect to containerd socket %s: %v", sock, err) } defer client.Close() for _, file := range files { if err := a.unpackBundle(client, a.k0sVars.OCIBundleDir+"/"+file.Name()); err != nil { + logrus.WithError(err).Errorf("can't unpack bundle %s", file.Name()) return fmt.Errorf("can't unpack bundle %s: %w", file.Name(), err) } } return nil - }, retry.Delay(time.Second*5), - retry.Attempts(50)) + }, retry.Delay(time.Second*5)) } From 244c212db5a618de53a490445d1afd631c91fdb0 Mon Sep 17 00:00:00 2001 From: Mikhail Sakhnov Date: Wed, 24 Mar 2021 11:01:35 +0200 Subject: [PATCH 2/2] Use retries for containerd creation and try to use it first to validate the connectivity Signed-off-by: Mikhail Sakhnov --- docs/airgap-install.md | 3 ++ pkg/component/worker/ocibundle.go | 63 ++++++++++++++++++------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/docs/airgap-install.md b/docs/airgap-install.md index 5d787f0d05ec..57c43351a435 100644 --- a/docs/airgap-install.md +++ b/docs/airgap-install.md @@ -12,6 +12,9 @@ You also need to have containerd CLI management tool `ctr` installed on the work ## Steps #### 1. Create OCI bundle + +k0s supports only uncompressed image bundles. + ##### 1.1 Using Docker Use following commands to build OCI bundle by utilizing your docker environment. ``` diff --git a/pkg/component/worker/ocibundle.go b/pkg/component/worker/ocibundle.go index 39c431e2345c..370e87b912dc 100644 --- a/pkg/component/worker/ocibundle.go +++ b/pkg/component/worker/ocibundle.go @@ -32,22 +32,6 @@ func (a *OCIBundleReconciler) Init() error { return util.InitDirectory(a.k0sVars.OCIBundleDir, constant.ManifestsDirMode) } -func (a OCIBundleReconciler) unpackBundle(client *containerd.Client, bundlePath string) error { - r, err := os.Open(bundlePath) - if err != nil { - return fmt.Errorf("can't open bundle file %s: %v", bundlePath, err) - } - defer r.Close() - images, err := client.Import(context.Background(), r) - if err != nil { - return fmt.Errorf("can't import bundle: %v", err) - } - for _, i := range images { - logrus.Infof("Imported image %s", i.Name) - } - return nil -} - func (a *OCIBundleReconciler) Run() error { files, err := ioutil.ReadDir(a.k0sVars.OCIBundleDir) if err != nil { @@ -56,24 +40,49 @@ func (a *OCIBundleReconciler) Run() error { if len(files) == 0 { return nil } - return retry.Do(func() error { - sock := filepath.Join(a.k0sVars.RunDir, "containerd.sock") - client, err := containerd.New(sock, containerd.WithDefaultNamespace("k8s.io")) - + var client *containerd.Client + sock := filepath.Join(a.k0sVars.RunDir, "containerd.sock") + err = retry.Do(func() error { + client, err = containerd.New(sock, containerd.WithDefaultNamespace("k8s.io")) if err != nil { logrus.WithError(err).Errorf("can't connect to containerd socket %s", sock) - return fmt.Errorf("can't connect to containerd socket %s: %v", sock, err) + return err } - defer client.Close() - for _, file := range files { - if err := a.unpackBundle(client, a.k0sVars.OCIBundleDir+"/"+file.Name()); err != nil { - logrus.WithError(err).Errorf("can't unpack bundle %s", file.Name()) - return fmt.Errorf("can't unpack bundle %s: %w", file.Name(), err) - } + _, err := client.ListImages(context.Background()) + if err != nil { + logrus.WithError(err).Errorf("can't use containerd client") + return err } return nil }, retry.Delay(time.Second*5)) + if err != nil { + return fmt.Errorf("can't connect to containerd socket %s: %v", sock, err) + } + defer client.Close() + for _, file := range files { + if err := a.unpackBundle(client, a.k0sVars.OCIBundleDir+"/"+file.Name()); err != nil { + logrus.WithError(err).Errorf("can't unpack bundle %s", file.Name()) + return fmt.Errorf("can't unpack bundle %s: %w", file.Name(), err) + } + } + return nil +} + +func (a OCIBundleReconciler) unpackBundle(client *containerd.Client, bundlePath string) error { + r, err := os.Open(bundlePath) + if err != nil { + return fmt.Errorf("can't open bundle file %s: %v", bundlePath, err) + } + defer r.Close() + images, err := client.Import(context.Background(), r) + if err != nil { + return fmt.Errorf("can't import bundle: %v", err) + } + for _, i := range images { + logrus.Infof("Imported image %s", i.Name) + } + return nil } func (a *OCIBundleReconciler) Stop() error {