Skip to content

Commit

Permalink
feat(werf): add helmChartConfig property to werf.yaml
Browse files Browse the repository at this point in the history
Implements werf#6390
  • Loading branch information
drey committed Dec 3, 2024
1 parent 4aa3b66 commit 12d75f3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
8 changes: 8 additions & 0 deletions cmd/werf/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,14 @@ func GetHelmChartDir(werfConfigPath string, werfConfig *config.WerfConfig, giter
return helmChartDir, nil
}

func GetHelmChartConfigAppVersion(werfConfig *config.WerfConfig) string {
if werfConfig.Meta.Deploy.HelmChartConfig.AppVersion != nil {
return *werfConfig.Meta.Deploy.HelmChartConfig.AppVersion
}

return ""
}

func GetNamespace(cmdData *CmdData) string {
if *cmdData.Namespace == "" {
return "default"
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/meta_deploy.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package config

type MetaDeploy struct {
HelmChartConfig MetaDeployHelmChartConfig
HelmChartDir *string
HelmRelease *string
HelmReleaseSlug *bool
Namespace *string
NamespaceSlug *bool
}

type MetaDeployHelmChartConfig struct {
AppVersion *string
}
50 changes: 45 additions & 5 deletions pkg/config/raw_meta_deploy.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package config

type rawMetaDeploy struct {
HelmChartDir *string `yaml:"helmChartDir,omitempty"`
HelmRelease *string `yaml:"helmRelease,omitempty"`
HelmReleaseSlug *bool `yaml:"helmReleaseSlug,omitempty"`
Namespace *string `yaml:"namespace,omitempty"`
NamespaceSlug *bool `yaml:"namespaceSlug,omitempty"`
HelmChartConfig *rawMetaDeployHelmChartConfig `yaml:"helmChartConfig,omitempty"`
HelmChartDir *string `yaml:"helmChartDir,omitempty"`
HelmRelease *string `yaml:"helmRelease,omitempty"`
HelmReleaseSlug *bool `yaml:"helmReleaseSlug,omitempty"`
Namespace *string `yaml:"namespace,omitempty"`
NamespaceSlug *bool `yaml:"namespaceSlug,omitempty"`

rawMeta *rawMeta

UnsupportedAttributes map[string]interface{} `yaml:",inline"`
}

type rawMetaDeployHelmChartConfig struct {
AppVersion *string `yaml:"appVersion,omitempty"`

rawMetaDeploy *rawMetaDeploy

UnsupportedAttributes map[string]interface{} `yaml:",inline"`
}

func (c *rawMetaDeploy) UnmarshalYAML(unmarshal func(interface{}) error) error {
if parent, ok := parentStack.Peek().(*rawMeta); ok {
c.rawMeta = parent
Expand Down Expand Up @@ -51,5 +60,36 @@ func (c *rawMetaDeploy) toMetaDeploy() MetaDeploy {
metaDeploy.HelmReleaseSlug = c.HelmReleaseSlug
metaDeploy.Namespace = c.Namespace
metaDeploy.NamespaceSlug = c.NamespaceSlug

if c.HelmChartConfig != nil {
metaDeploy.HelmChartConfig = c.HelmChartConfig.toMetaDeploy()
}

return metaDeploy
}

func (c *rawMetaDeployHelmChartConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if parent, ok := parentStack.Peek().(*rawMetaDeploy); ok {
c.rawMetaDeploy = parent
}

parentStack.Push(c)
type plain rawMetaDeployHelmChartConfig
err := unmarshal((*plain)(c))
parentStack.Pop()
if err != nil {
return err
}

if err := checkOverflow(c.UnsupportedAttributes, nil, c.rawMetaDeploy.rawMeta.doc); err != nil {
return err
}

return nil
}

func (c *rawMetaDeployHelmChartConfig) toMetaDeploy() MetaDeployHelmChartConfig {
return MetaDeployHelmChartConfig{
AppVersion: c.AppVersion,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package helpers
import "github.com/werf/3p-helm/pkg/chart"

type GetHelmChartMetadataOptions struct {
OverrideName string
DefaultName string
DefaultVersion string
OverrideAppVersion string
OverrideName string
DefaultName string
DefaultVersion string
}

func AutosetChartMetadata(metadataIn *chart.Metadata, opts GetHelmChartMetadataOptions) *chart.Metadata {
Expand All @@ -24,6 +25,10 @@ func AutosetChartMetadata(metadataIn *chart.Metadata, opts GetHelmChartMetadataO
metadata.Name = opts.DefaultName
}

if opts.OverrideAppVersion != "" {
metadata.AppVersion = opts.OverrideAppVersion
}

if metadata.Version == "" {
metadata.Version = opts.DefaultVersion
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/deploy/helm/chart_extender/werf_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/werf/3p-helm/pkg/registry"
"github.com/werf/logboek"
"github.com/werf/nelm/pkg/secrets_manager"
"github.com/werf/werf/v2/cmd/werf/common"
"github.com/werf/werf/v2/pkg/config"
"github.com/werf/werf/v2/pkg/deploy/helm"
"github.com/werf/werf/v2/pkg/deploy/helm/chart_extender/helpers"
Expand Down Expand Up @@ -131,6 +132,7 @@ func (wc *WerfChart) ChartLoaded(files []*chart.ChartExtenderBufferedFile) error
var opts helpers.GetHelmChartMetadataOptions
if wc.werfConfig != nil {
opts.DefaultName = wc.werfConfig.Meta.Project
opts.OverrideAppVersion = common.GetHelmChartConfigAppVersion(wc.werfConfig)
}
opts.DefaultVersion = "1.0.0"
wc.HelmChart.Metadata = helpers.AutosetChartMetadata(wc.HelmChart.Metadata, opts)
Expand Down

0 comments on commit 12d75f3

Please sign in to comment.