Skip to content

Commit

Permalink
feat: support --show-only|-s helm-style render option + export-values…
Browse files Browse the repository at this point in the history
… chaining

* Pass either `-s templates/*ingress*.yaml` path (helm compatible) or use `-s .helm/templates/*ingress*.yaml` with full path in local filesystem (with bash completion convenience).
* `export-values` in subcharts and sub-subcharts (and sub-sub-subcharts etc.) are processed now as expected.

Refs werf/3p-helm#162
Refs werf/3p-helm#161

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Apr 26, 2022
1 parent 5c27a1e commit e9e3b86
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
34 changes: 32 additions & 2 deletions cmd/werf/render/render.go
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
helm_v3 "helm.sh/helm/v3/cmd/helm"
Expand All @@ -31,6 +32,7 @@ import (
"github.com/werf/werf/pkg/storage/manager"
"github.com/werf/werf/pkg/tmp_manager"
"github.com/werf/werf/pkg/true_git"
"github.com/werf/werf/pkg/util"
"github.com/werf/werf/pkg/werf"
"github.com/werf/werf/pkg/werf/global_warnings"
)
Expand All @@ -39,6 +41,7 @@ var cmdData struct {
RenderOutput string
Validate bool
IncludeCRDs bool
ShowOnly []string
}

var commonCmdData common.CmdData
Expand Down Expand Up @@ -127,10 +130,15 @@ func NewCmd() *cobra.Command {
cmd.Flags().BoolVarP(&cmdData.IncludeCRDs, "include-crds", "", common.GetBoolEnvironmentDefaultTrue("WERF_INCLUDE_CRDS"), "Include CRDs in the templated output (default $WERF_INCLUDE_CRDS)")

cmd.Flags().StringVarP(&cmdData.RenderOutput, "output", "", os.Getenv("WERF_RENDER_OUTPUT"), "Write render output to the specified file instead of stdout ($WERF_RENDER_OUTPUT by default)")
cmd.Flags().StringArrayVarP(&cmdData.ShowOnly, "show-only", "s", []string{}, "only show manifests rendered from the given templates")

return cmd
}

func getShowOnly() []string {
return append(common.PredefinedValuesByEnvNamePrefix("WERF_SHOW_ONLY"), cmdData.ShowOnly...)
}

func runRender(ctx context.Context) error {
if err := werf.Init(*commonCmdData.TmpDir, *commonCmdData.HomeDir); err != nil {
return fmt.Errorf("initialization error: %w", err)
Expand Down Expand Up @@ -387,7 +395,7 @@ func runRender(ctx context.Context) error {
SubchartExtenderFactoryFunc: func() chart.ChartExtender { return chart_extender.NewWerfSubchart() },
}

helmTemplateCmd, _ := helm_v3.NewTemplateCmd(actionConfig, output, helm_v3.TemplateCmdOptions{
templateOpts := helm_v3.TemplateCmdOptions{
ChainPostRenderer: wc.ChainPostRenderer,
ValueOpts: &values.Options{
ValueFiles: common.GetValues(&commonCmdData),
Expand All @@ -397,7 +405,29 @@ func runRender(ctx context.Context) error {
},
Validate: &cmdData.Validate,
IncludeCrds: &cmdData.IncludeCRDs,
})
}

fullChartDir := filepath.Join(giterminismManager.ProjectDir(), chartDir)

if showOnly := getShowOnly(); len(showOnly) > 0 {
var showFiles []string

for _, p := range showOnly {
pAbs := util.GetAbsoluteFilepath(p)
if strings.HasPrefix(pAbs, fullChartDir) {
tp := util.GetRelativeToBaseFilepath(fullChartDir, pAbs)
logboek.Context(ctx).Debug().LogF("Process show-only params: use path %q\n", tp)
showFiles = append(showFiles, tp)
} else {
logboek.Context(ctx).Debug().LogF("Process show-only params: use path %q\n", p)
showFiles = append(showFiles, p)
}
}

templateOpts.ShowFiles = &showFiles
}

helmTemplateCmd, _ := helm_v3.NewTemplateCmd(actionConfig, output, templateOpts)
if err := helmTemplateCmd.RunE(helmTemplateCmd, []string{releaseName, filepath.Join(giterminismManager.ProjectDir(), chartDir)}); err != nil {
return fmt.Errorf("helm templates rendering failed: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -109,4 +109,4 @@ replace k8s.io/helm => github.com/werf/helm v0.0.0-20210202111118-81e74d46da0f

replace github.com/deislabs/oras => github.com/werf/third-party-oras v0.9.1-0.20210927171747-6d045506f4c8

replace helm.sh/helm/v3 => github.com/werf/3p-helm/v3 v3.0.0-20220419131239-a2df9b725de3
replace helm.sh/helm/v3 => github.com/werf/3p-helm/v3 v3.0.0-20220426084422-a22e7bc5d766
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -2061,6 +2061,8 @@ github.com/weppos/publicsuffix-go v0.5.0 h1:rutRtjBJViU/YjcI5d80t4JAVvDltS6bciJg
github.com/weppos/publicsuffix-go v0.5.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k=
github.com/werf/3p-helm/v3 v3.0.0-20220419131239-a2df9b725de3 h1:H3C8D/30GQ71laOCsLGJrIHZMAa4Joab48hkOfTH8KA=
github.com/werf/3p-helm/v3 v3.0.0-20220419131239-a2df9b725de3/go.mod h1:Nm0Z2ciZFFvR9cRKpiRE2SMhJTgqY0b+ezT2cDcyqNw=
github.com/werf/3p-helm/v3 v3.0.0-20220426084422-a22e7bc5d766 h1:Z1vzNVuptwHZBzHcSZ1rrJ8MVVdh8Sh7P39onUS9a3k=
github.com/werf/3p-helm/v3 v3.0.0-20220426084422-a22e7bc5d766/go.mod h1:Nm0Z2ciZFFvR9cRKpiRE2SMhJTgqY0b+ezT2cDcyqNw=
github.com/werf/copy-recurse v0.2.2 h1:OpBB+Ezsv7j+iQR02p7zUQXSefZ7UaKBtQPMg2dxi7M=
github.com/werf/copy-recurse v0.2.2/go.mod h1:KVHSQ90p19xflWW0B7BJhLBwmSbEtuxIaBnjlUYRPhk=
github.com/werf/copy-recurse v0.2.3 h1:bi43vHBDQiX2Qnq+Ci9IGqtm7YdzzpkBO+8MKjp6x8g=
Expand Down

0 comments on commit e9e3b86

Please sign in to comment.