Skip to content

Commit

Permalink
Support helm functions on raw app args (#81)
Browse files Browse the repository at this point in the history
Signed-off-by: Prasad Ghangal <[email protected]>
  • Loading branch information
PrasadG193 authored Jun 2, 2021
1 parent 65dc13b commit 4c200dc
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion pkg/apps/raw/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/client-go/tools/clientcmd"

"github.com/kbrew-dev/kbrew/pkg/config"
"github.com/kbrew-dev/kbrew/pkg/engine"
"github.com/kbrew-dev/kbrew/pkg/kube"
"github.com/kbrew-dev/kbrew/pkg/yaml"
)
Expand Down Expand Up @@ -75,6 +76,31 @@ func New(c config.App) (*App, error) {
return rApp, nil
}

func (r *App) resolveArgs() error {
//TODO: user global singleton kubeconfig in all modules
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
&clientcmd.ConfigOverrides{},
).ClientConfig()
if err != nil {
return errors.Wrapf(err, "Failed to load Kubernetes config")
}

e := engine.NewEngine(config)

// TODO(@sahil.lakhwani): Parse only templated arguments
if len(r.App.Args) != 0 {
for arg, value := range r.App.Args {
v, err := e.Render(fmt.Sprintf("%v", value))
if err != nil {
return err
}
r.App.Args[arg] = v
}
}
return nil
}

// Install installs the app specified by name, version and namespace.
func (r *App) Install(ctx context.Context, name, namespace, version string, options map[string]string) error {
fmt.Printf("Installing raw app %s/%s\n", r.App.Repository.Name, name)
Expand All @@ -84,6 +110,10 @@ func (r *App) Install(ctx context.Context, name, namespace, version string, opti
return err
}

if err := r.resolveArgs(); err != nil {
return err
}

patchedManifest, err := patchManifest(manifest, r.App.Args)
if err != nil {
return err
Expand All @@ -93,7 +123,7 @@ func (r *App) Install(ctx context.Context, name, namespace, version string, opti
if err := kubectlCommand(ctx, install, name, namespace, patchedManifest); err != nil {
return err
}
fmt.Printf("Waiting for components to be ready for %s", name)
fmt.Printf("Waiting for components to be ready for %s\n", name)
return r.waitForReady(ctx, namespace)
}

Expand Down

0 comments on commit 4c200dc

Please sign in to comment.