Skip to content

Commit

Permalink
Fix of errors/problems discovered during usage of TOI on MAC (#336)
Browse files Browse the repository at this point in the history
* pass driver config to TOI execution environment

* also set user namespace

* improve readability of command help

* provide credential access to the value mapping

* more error context in filesystem walk

* fix filepath usage

* fix walking filesystem in helm input

* toi create local filesystem environment

* add ignored helm file for test
  • Loading branch information
mandelsoft authored Apr 14, 2023
1 parent 7bac90d commit 78c8e23
Show file tree
Hide file tree
Showing 90 changed files with 1,342 additions and 332 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/cmds/test
/pkg/test
.idea
/.idea
*.sw[pqo]
main
/ecrplugin
Expand Down
3 changes: 2 additions & 1 deletion cmds/demoplugin/uploaders/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"strings"

"github.com/mandelsoft/filepath/pkg/filepath"

"github.com/open-component-model/ocm/cmds/demoplugin/accessmethods"
"github.com/open-component-model/ocm/cmds/demoplugin/common"
"github.com/open-component-model/ocm/cmds/demoplugin/config"
Expand Down
3 changes: 2 additions & 1 deletion cmds/demoplugin/uploaders/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package uploaders

import (
"os"
"path/filepath"

"github.com/mandelsoft/filepath/pkg/filepath"

"github.com/open-component-model/ocm/cmds/demoplugin/accessmethods"
"github.com/open-component-model/ocm/pkg/common"
Expand Down
9 changes: 9 additions & 0 deletions cmds/helminstaller/app/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@

package driver

import (
"io"

"github.com/mandelsoft/logging"
)

type Config struct {
ChartPath string
Release string
Namespace string
CreateNamespace bool
Values []byte
Kubeconfig []byte
Output io.Writer
Debug logging.Logger
}

type Driver interface {
Install(*Config) error
Uninstall(*Config) error
Expand Down
14 changes: 12 additions & 2 deletions cmds/helminstaller/app/driver/helm/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
package helm

import (
"fmt"

"github.com/mandelsoft/logging"

"github.com/open-component-model/ocm/cmds/helminstaller/app/driver"
)

Expand All @@ -17,9 +21,15 @@ func New() driver.Driver {
}

func (Driver) Install(cfg *driver.Config) error {
return Install(cfg.ChartPath, cfg.Release, cfg.Namespace, cfg.CreateNamespace, cfg.Values, cfg.Kubeconfig)
return Install(cfg.Debug, cfg.ChartPath, cfg.Release, cfg.Namespace, cfg.CreateNamespace, cfg.Values, cfg.Kubeconfig)
}

func (Driver) Uninstall(cfg *driver.Config) error {
return Uninstall(cfg.ChartPath, cfg.Release, cfg.Namespace, cfg.CreateNamespace, cfg.Values, cfg.Kubeconfig)
return Uninstall(cfg.Debug, cfg.ChartPath, cfg.Release, cfg.Namespace, cfg.CreateNamespace, cfg.Values, cfg.Kubeconfig)
}

func DebugFunction(l logging.Logger) func(msg string, args ...any) {
return func(msg string, args ...any) {
l.Debug(fmt.Sprintf(msg, args...))
}
}
6 changes: 3 additions & 3 deletions cmds/helminstaller/app/driver/helm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import (
"context"
"time"

"github.com/mandelsoft/logging"
helmclient "github.com/mittwald/go-helm-client"
"github.com/sirupsen/logrus"
)

func Install(path string, release string, namespace string, createNamespace bool, values []byte, kubeconfig []byte) error {
func Install(l logging.Logger, path string, release string, namespace string, createNamespace bool, values []byte, kubeconfig []byte) error {
opt := &helmclient.KubeConfClientOptions{
Options: &helmclient.Options{
Namespace: namespace,
RepositoryCache: "/tmp/.helmcache",
RepositoryConfig: "/tmp/.helmrepo",
Debug: true,
Linting: true,
DebugLog: logrus.Debugf,
DebugLog: DebugFunction(l),
},
KubeContext: "",
KubeConfig: kubeconfig,
Expand Down
6 changes: 3 additions & 3 deletions cmds/helminstaller/app/driver/helm/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ package helm
import (
"time"

"github.com/mandelsoft/logging"
helmclient "github.com/mittwald/go-helm-client"
"github.com/sirupsen/logrus"
)

func Uninstall(path string, release string, namespace string, createNamespace bool, values []byte, kubeconfig []byte) error {
func Uninstall(l logging.Logger, path string, release string, namespace string, createNamespace bool, values []byte, kubeconfig []byte) error {
opt := &helmclient.KubeConfClientOptions{
Options: &helmclient.Options{
Namespace: namespace,
RepositoryCache: "/tmp/.helmcache",
RepositoryConfig: "/tmp/.helmrepo",
Debug: true,
Linting: true,
DebugLog: logrus.Debugf,
DebugLog: DebugFunction(l),
},
KubeContext: "",
KubeConfig: kubeconfig,
Expand Down
5 changes: 3 additions & 2 deletions cmds/helminstaller/app/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/open-component-model/ocm/pkg/errors"
"github.com/open-component-model/ocm/pkg/out"
"github.com/open-component-model/ocm/pkg/runtime"
"github.com/open-component-model/ocm/pkg/toi"
"github.com/open-component-model/ocm/pkg/toi/support"
utils2 "github.com/open-component-model/ocm/pkg/utils"
)
Expand Down Expand Up @@ -181,7 +180,7 @@ func (e *Execution) Execute(cfg *Config, values map[string]interface{}, kubeconf
if err != nil {
return err
}
toi.Log.Info("starting download", "path", path, "access", string(data))
e.Logger.Info("starting download", "path", path, "access", string(data))

_, e.path = Must2f(R2(download.For(e.Context).Download(common.NewPrinter(e.OutputContext.StdOut()), acc, path, e.fs)), "downloading helm chart")

Expand Down Expand Up @@ -243,6 +242,8 @@ func (e *Execution) Execute(cfg *Config, values map[string]interface{}, kubeconf
CreateNamespace: cfg.CreateNamespace,
Values: valuesdata,
Kubeconfig: kubeconfig,
Output: e.OutputContext.StdOut(),
Debug: e.Logger,
}
switch e.Action {
case "install":
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/controllercmds/install/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"io"
"net/http"
"os"
"path/filepath"
"strings"
"time"

"github.com/fluxcd/pkg/ssa"
"github.com/mandelsoft/filepath/pkg/filepath"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down
4 changes: 3 additions & 1 deletion cmds/ocm/commands/controllercmds/install/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "github.com/open-component-model/ocm/cmds/ocm/testhelper"
. "github.com/open-component-model/ocm/pkg/testutils"

"github.com/mandelsoft/filepath/pkg/filepath"
)

var _ = Describe("Test Environment", func() {
Expand Down
7 changes: 4 additions & 3 deletions cmds/ocm/commands/ocmcmds/common/inputs/types/helm/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/open-component-model/ocm/pkg/contexts/oci/ociutils/helm"
"github.com/open-component-model/ocm/pkg/contexts/oci/ociutils/helm/loader"
"github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartifact"
"github.com/open-component-model/ocm/pkg/errors"
)

type Spec struct {
Expand Down Expand Up @@ -47,11 +48,11 @@ func (s *Spec) Validate(fldPath *field.Path, ctx inputs.Context, inputFilePath s
func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (accessio.TemporaryBlobAccess, string, error) {
_, inputPath, err := inputs.FileInfo(ctx, s.Path, info.InputFilePath)
if err != nil {
return nil, "", err
return nil, "", errors.Wrapf(err, "cannot handle input path %q", s.Path)
}
chart, err := loader.Load(inputPath, ctx.FileSystem())
if err != nil {
return nil, "", err
return nil, "", errors.Wrapf(err, "cannot load chart from %q", inputPath)
}
vers := chart.Metadata.Version
if s.Version != "" {
Expand All @@ -62,7 +63,7 @@ func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (acces
}
blob, err := helm.SynthesizeArtifactBlob(inputPath, ctx.FileSystem())
if err != nil {
return nil, "", err
return nil, "", errors.Wrapf(err, "cannot synthesize artifact blob")
}

return blob, ociartifact.Hint(info.ComponentVersion, chart.Name(), s.Repository, vers), err
Expand Down
11 changes: 5 additions & 6 deletions cmds/ocm/commands/ocmcmds/common/options/lookupoption/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ func (o *Option) getResolver(ctx clictx.OCM, session ocm.Session) (ocm.Component
}

func (o *Option) Usage() string {
s := `
s := `\
If a component lookup for building a reference closure is required
the <code>--lookup</code> option can be used to specify a fallback
lookup repository.
By default the component versions are searched in the repository
holding the component version for which the closure is determined.
For *Component Archives* this is never possible, because it only
contains a single component version. Therefore, in this scenario
lookup repository. By default the component versions are searched in
the repository holding the component version for which the closure is
determined. For *Component Archives* this is never possible, because
it only contains a single component version. Therefore, in this scenario
this option must always be specified to be able to follow component
references.
`
Expand Down
8 changes: 7 additions & 1 deletion cmds/ocm/commands/ocmcmds/plugins/describe/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package describe

import (
"strings"

"github.com/spf13/cobra"

handler "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/handlers/pluginhdlr"
Expand Down Expand Up @@ -84,7 +86,11 @@ func (a *action) Add(e interface{}) error {
if a.Count > 1 {
a.Printer.Printf("----------------------\n")
}
a.Printer.Printf("%s\n", cobrautils.CleanMarkdown(buf.String()))
desc := cobrautils.CleanMarkdown(buf.String())
if !strings.HasSuffix(desc, "\n") {
desc += "\n"
}
a.Printer.Printf("%s", desc)
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion cmds/ocm/commands/ocmcmds/plugins/describe/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package describe_test

import (
"bytes"
"path/filepath"

"github.com/mandelsoft/filepath/pkg/filepath"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand All @@ -26,6 +26,7 @@ var _ = Describe("Test Environment", func() {
BeforeEach(func() {
env = NewTestEnv(TestData())

// use os filesystem here
p, err := filepath.Abs("testdata")
Expect(err).To(Succeed())
path = p
Expand Down
5 changes: 0 additions & 5 deletions cmds/ocm/commands/ocmcmds/plugins/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,24 @@ func DescribePlugin(p plugin.Plugin, out common.Printer) {
} else {
out.Printf("Source: manually installed\n")
}
out.Printf("\n")
out.Printf("Description: \n")
if d.Long == "" {
out.Printf("%s\n", utils2.IndentLines(d.Short, " "))
} else {
out.Printf("%s\n", utils2.IndentLines(d.Long, " "))
}
if len(d.AccessMethods) > 0 {
out.Printf("\n")
out.Printf("Access Methods:\n")
plugincommon.DescribeAccessMethods(d, out)
}
if len(d.Uploaders) > 0 {
out.Printf("\n")
// a working type inference would be really great
plugincommon.ListElements[plugin.UploaderDescriptor, plugin.UploaderKey]("Repository Uploaders", d.Uploaders, out)
}
if len(d.Downloaders) > 0 {
out.Printf("\n")
plugincommon.ListElements[plugin.DownloaderDescriptor, plugin.DownloaderKey]("Resource Downloaders", d.Downloaders, out)
}
if len(d.Actions) > 0 {
out.Printf("\n")
out.Printf("Actions:\n")
plugincommon.DescribeActions(d, out)
}
Expand Down
3 changes: 2 additions & 1 deletion cmds/ocm/commands/ocmcmds/plugins/get/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package get_test

import (
"bytes"
"path/filepath"

"github.com/mandelsoft/filepath/pkg/filepath"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand All @@ -26,6 +26,7 @@ var _ = Describe("Test Environment", func() {
BeforeEach(func() {
env = NewTestEnv(TestData())

// use os filesystem here
p, err := filepath.Abs("testdata")
Expect(err).To(Succeed())
path = p
Expand Down
10 changes: 7 additions & 3 deletions cmds/ocm/commands/ocmcmds/resources/add/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "github.com/open-component-model/ocm/cmds/ocm/testhelper"
. "github.com/open-component-model/ocm/pkg/testutils"

Expand Down Expand Up @@ -141,8 +142,8 @@ var _ = Describe("Add resources", func() {
CheckTextResource(env, cd, "testdata")
})

It("adds helm chart", func() {
Expect(env.Execute("add", "resources", "--file", ARCH, "/testdata/helm.yaml")).To(Succeed())
DescribeTable("adds helm chart", func(rsc string) {
Expect(env.Execute("add", "resources", "--file", ARCH, rsc)).To(Succeed())
data, err := env.ReadFile(env.Join(ARCH, comparch.ComponentDescriptorFileName))
Expect(err).To(Succeed())
cd, err := compdesc.Decode(data)
Expand Down Expand Up @@ -182,7 +183,10 @@ var _ = Describe("Add resources", func() {
defer reader.Close()
_, err = loader.LoadArchive(reader)
Expect(err).To(Succeed())
})
},
Entry("flat", "/testdata/helm.yaml"),
Entry("up", "/testdata/nested/helm.yaml"),
)

It("adds external image", func() {
Expect(env.Execute("add", "resources", "--file", ARCH, "/testdata/image.yaml")).To(Succeed())
Expand Down
14 changes: 14 additions & 0 deletions cmds/ocm/commands/ocmcmds/resources/add/testdata/nested/helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: chart
type: helmChart
input:
type: helm
path: ../testchart
repository: mandelsoft/testchart
---
name: echoserver
type: ociImage
version: "1.0"
access:
type: ociArtifact
imageReference: gcr.io/google_containers/echoserver:1.0
Empty file.
Loading

0 comments on commit 78c8e23

Please sign in to comment.