diff --git a/cmd/werf/common/common.go b/cmd/werf/common/common.go index 6281bae538..cc075b0999 100644 --- a/cmd/werf/common/common.go +++ b/cmd/werf/common/common.go @@ -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" diff --git a/pkg/config/meta_deploy.go b/pkg/config/meta_deploy.go index d1c4088df2..fa47822365 100644 --- a/pkg/config/meta_deploy.go +++ b/pkg/config/meta_deploy.go @@ -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 +} diff --git a/pkg/config/raw_meta_deploy.go b/pkg/config/raw_meta_deploy.go index af3075a586..8e1632d7ef 100644 --- a/pkg/config/raw_meta_deploy.go +++ b/pkg/config/raw_meta_deploy.go @@ -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 @@ -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, + } +} diff --git a/pkg/deploy/helm/chart_extender/helpers/chart_metadata_autosetter.go b/pkg/deploy/helm/chart_extender/helpers/chart_metadata_autosetter.go index fc2a0dfffb..688ea5961c 100644 --- a/pkg/deploy/helm/chart_extender/helpers/chart_metadata_autosetter.go +++ b/pkg/deploy/helm/chart_extender/helpers/chart_metadata_autosetter.go @@ -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 { @@ -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 } diff --git a/pkg/deploy/helm/chart_extender/werf_chart.go b/pkg/deploy/helm/chart_extender/werf_chart.go index fb27f6687d..af3a20c9d0 100644 --- a/pkg/deploy/helm/chart_extender/werf_chart.go +++ b/pkg/deploy/helm/chart_extender/werf_chart.go @@ -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" @@ -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)