From ca494a7277fa005f9abfe6e3ae3b1ba4172987c3 Mon Sep 17 00:00:00 2001 From: Paul Maidment Date: Wed, 12 Jul 2023 19:59:08 +0300 Subject: [PATCH] MGMT-15243: Skip any zero size manifests when applying When applying manifests when installation is started, we should skip any manifests that are of zero size to prevent them from causing bootstrap problems later. We can't validate zero size at the point of file upload as the UI is presently using an approach where it uploads an empty manifest file to track that the user wishes to add user defined manifests. Discussions are underway to change this but for now we need to take this alternative approach. This PR implements this. --- internal/ignition/ignition.go | 6 ++++++ internal/ignition/ignition_test.go | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/internal/ignition/ignition.go b/internal/ignition/ignition.go index 97bb9e15fa..273b65e3e4 100644 --- a/internal/ignition/ignition.go +++ b/internal/ignition/ignition.go @@ -1574,6 +1574,12 @@ func (g *installerGenerator) downloadManifest(ctx context.Context, manifest stri if err != nil { return err } + + if len(content) == 0 { + // Ignore any empty files. + return nil + } + // manifest has full path as object-key on s3: clusterID/manifests/[manifests|openshift]/filename // clusterID/manifests should be trimmed prefix := manifests.GetManifestObjectName(*g.cluster.ID, "") diff --git a/internal/ignition/ignition_test.go b/internal/ignition/ignition_test.go index 6de8371c2c..2444aa1ae0 100644 --- a/internal/ignition/ignition_test.go +++ b/internal/ignition/ignition_test.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "io/fs" "os" "path/filepath" "strings" @@ -921,7 +922,7 @@ var _ = Describe("downloadManifest", func() { It("writes the correct file", func() { ctx := context.Background() manifestName := fmt.Sprintf("%s/manifests/openshift/masters-chrony-configuration.yaml", cluster.ID) - mockS3Client.EXPECT().Download(ctx, manifestName).Return(io.NopCloser(strings.NewReader("chronyconf")), int64(10), nil) + mockS3Client.EXPECT().Download(ctx, manifestName).Return(io.NopCloser(strings.NewReader("content:entry")), int64(10), nil) Expect(os.Mkdir(filepath.Join(workDir, "/openshift"), 0755)).To(Succeed()) Expect(os.Mkdir(filepath.Join(workDir, "/manifests"), 0755)).To(Succeed()) @@ -929,7 +930,21 @@ var _ = Describe("downloadManifest", func() { content, err := os.ReadFile(filepath.Join(workDir, "/openshift/masters-chrony-configuration.yaml")) Expect(err).NotTo(HaveOccurred()) - Expect(content).To(Equal([]byte("chronyconf"))) + Expect(content).To(Equal([]byte("content:entry"))) + }) + + It("If a file has empty content, it will not be written", func() { + ctx := context.Background() + manifestName := fmt.Sprintf("%s/manifests/openshift/masters-chrony-configuration.yaml", cluster.ID) + mockS3Client.EXPECT().Download(ctx, manifestName).Return(io.NopCloser(strings.NewReader("")), int64(0), nil) + Expect(os.Mkdir(filepath.Join(workDir, "/openshift"), 0755)).To(Succeed()) + Expect(os.Mkdir(filepath.Join(workDir, "/manifests"), 0755)).To(Succeed()) + + Expect(generator.downloadManifest(ctx, manifestName)).To(Succeed()) + + _, err := os.Stat(filepath.Join(workDir, "/openshift/masters-chrony-configuration.yaml")) + Expect(err).To(HaveOccurred()) + Expect(errors.Is(err, fs.ErrNotExist)).To(BeTrue()) }) })