Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support helm functions on raw app args #81

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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