Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
fix second helm bundle format handle error
Browse files Browse the repository at this point in the history
Signed-off-by: akihikokuroda <[email protected]>
  • Loading branch information
akihikokuroda committed Sep 1, 2022
1 parent 81f8fd7 commit 4f19948
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 5 deletions.
41 changes: 36 additions & 5 deletions internal/source/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"strings"
"syscall"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/memfs"
Expand Down Expand Up @@ -218,12 +219,18 @@ func (f *billyFS) ReadFile(name string) ([]byte, error) {
}

func (f *billyFS) Open(path string) (fs.File, error) {
fi, err := f.Filesystem.Stat(path)
if err != nil {
return nil, err
}
if fi.IsDir() {
return &billyDirFile{billyFile{nil, fi}, f, path}, nil
}
file, err := f.Filesystem.Open(path)
if err != nil {
return nil, err
}
fi, err := f.Filesystem.Stat(path)
return &billyFile{file, fi, err}, nil
return &billyFile{file, fi}, nil
}

func (f *billyFS) ReadDir(name string) ([]fs.DirEntry, error) {
Expand All @@ -240,10 +247,34 @@ func (f *billyFS) ReadDir(name string) ([]fs.DirEntry, error) {

type billyFile struct {
billy.File
fi os.FileInfo
fiErr error
fi os.FileInfo
}

func (b billyFile) Stat() (fs.FileInfo, error) {
return b.fi, b.fiErr
return b.fi, nil
}

func (b billyFile) Close() error {
if b.File == nil {
return nil
}
return b.File.Close()
}

type billyDirFile struct {
billyFile
fs *billyFS
path string
}

func (d *billyDirFile) ReadDir(n int) ([]fs.DirEntry, error) {
entries, err := d.fs.ReadDir(d.path)
if n <= 0 || n > len(entries) {
n = len(entries)
}
return entries[:n], err
}

func (d billyDirFile) Read(data []byte) (int, error) {
return 0, &fs.PathError{Op: "read", Path: d.path, Err: syscall.EISDIR}
}
63 changes: 63 additions & 0 deletions test/e2e/helm_provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,69 @@ var _ = Describe("helm provisioner bundledeployment", func() {
})
})
})
When("a BundleDeployment targets a valid Bundle with no chart directory in Github", func() {
var (
bd *rukpakv1alpha1.BundleDeployment
ctx context.Context
)
BeforeEach(func() {
ctx = context.Background()

bd = &rukpakv1alpha1.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "ahoy-",
},
Spec: rukpakv1alpha1.BundleDeploymentSpec{
ProvisionerClassName: helm.ProvisionerID,
Template: &rukpakv1alpha1.BundleTemplate{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/name": "ahoy",
},
},
Spec: rukpakv1alpha1.BundleSpec{
ProvisionerClassName: helm.ProvisionerID,
Source: rukpakv1alpha1.BundleSource{
Type: rukpakv1alpha1.SourceTypeGit,
Git: &rukpakv1alpha1.GitSource{
Repository: "https://github.com/helm/examples",
Directory: "./charts/hello-world",
Ref: rukpakv1alpha1.GitRef{
Branch: "main",
},
},
},
},
},
},
}
err := c.Create(ctx, bd)
Expect(err).To(BeNil())
})
AfterEach(func() {
By("deleting the testing resources")
Expect(c.Delete(ctx, bd)).To(BeNil())
})

It("should rollout the bundle contents successfully", func() {
By("eventually writing a successful installation state back to the bundledeployment status")
Eventually(func() (*metav1.Condition, error) {
if err := c.Get(ctx, client.ObjectKeyFromObject(bd), bd); err != nil {
return nil, err
}
if bd.Status.ActiveBundle == "" {
return nil, fmt.Errorf("waiting for bundle name to be populated")
}
return meta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeInstalled), nil
}).Should(And(
Not(BeNil()),
WithTransform(func(c *metav1.Condition) string { return c.Type }, Equal(rukpakv1alpha1.TypeInstalled)),
WithTransform(func(c *metav1.Condition) metav1.ConditionStatus { return c.Status }, Equal(metav1.ConditionTrue)),
WithTransform(func(c *metav1.Condition) string { return c.Reason }, Equal(rukpakv1alpha1.ReasonInstallationSucceeded)),
WithTransform(func(c *metav1.Condition) string { return c.Message }, ContainSubstring("instantiated bundle")),
))
})
})
When("a BundleDeployment targets a valid Bundle with values", func() {
var (
bd *rukpakv1alpha1.BundleDeployment
Expand Down

0 comments on commit 4f19948

Please sign in to comment.