Skip to content

Commit 2db5699

Browse files
committed
fix(deploy): panics in bundle apply and bundle render
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
1 parent 36ad39d commit 2db5699

File tree

5 files changed

+45
-41
lines changed

5 files changed

+45
-41
lines changed

cmd/werf/bundle/apply/apply.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616

1717
"github.com/werf/3p-helm/pkg/chart"
1818
"github.com/werf/3p-helm/pkg/chartutil"
19+
"github.com/werf/3p-helm/pkg/werf/secrets"
20+
"github.com/werf/common-go/pkg/secrets_manager"
1921
"github.com/werf/common-go/pkg/util"
2022
"github.com/werf/nelm/pkg/action"
2123
"github.com/werf/werf/v2/cmd/werf/common"
@@ -179,17 +181,10 @@ func runApply(ctx context.Context) error {
179181
return fmt.Errorf("construct bundles registry client: %w", err)
180182
}
181183

182-
if err := bundles.Pull(ctx, fmt.Sprintf("%s:%s", repoAddress, cmdData.Tag), bundlePath, bundlesRegistryClient); err != nil {
183-
return fmt.Errorf("pull bundle: %w", err)
184-
}
185-
186-
serviceAnnotations, extraAnnotations, extraLabels, err := getAnnotationsAndLabels(bundlePath)
187-
if err != nil {
188-
return fmt.Errorf("get annotations and labels: %w", err)
189-
}
190-
191184
registryCredentialsPath := docker.GetDockerConfigCredentialsFile(*commonCmdData.DockerConfig)
192185

186+
secrets.CoalesceTablesFunc = chartutil.CoalesceTables
187+
secrets_manager.DisableSecretsDecryption = *commonCmdData.IgnoreSecretKey
193188
chartutil.ServiceValues, err = helpers.GetBundleServiceValues(ctx, helpers.ServiceValuesOptions{
194189
Env: *commonCmdData.Environment,
195190
Namespace: releaseNamespace,
@@ -200,6 +195,15 @@ func runApply(ctx context.Context) error {
200195
return fmt.Errorf("get service values: %w", err)
201196
}
202197

198+
if err := bundles.Pull(ctx, fmt.Sprintf("%s:%s", repoAddress, cmdData.Tag), bundlePath, bundlesRegistryClient); err != nil {
199+
return fmt.Errorf("pull bundle: %w", err)
200+
}
201+
202+
serviceAnnotations, extraAnnotations, extraLabels, err := getAnnotationsAndLabels(bundlePath)
203+
if err != nil {
204+
return fmt.Errorf("get annotations and labels: %w", err)
205+
}
206+
203207
chart.CurrentChartType = chart.ChartTypeBundle
204208

205209
if err := action.Deploy(ctx, action.DeployOptions{

cmd/werf/bundle/publish/publish.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,6 @@ func runPublish(ctx context.Context, imageNameListFromArgs []string) error {
328328
return err
329329
}
330330

331-
secrets_manager.DefaultManager = secrets_manager.NewSecretsManager(secrets_manager.SecretsManagerOptions{
332-
DisableSecretsDecryption: *commonCmdData.IgnoreSecretKey,
333-
})
334-
335-
// FIXME(1.3): compatibility mode with older 1.2 versions, which do not require WERF_SECRET_KEY in the 'werf bundle publish' command
336-
if err := secrets_manager.DefaultManager.AllowMissedSecretKeyMode(giterminismManager.ProjectDir()); err != nil {
337-
return err
338-
}
339-
340331
loader.ChartFileReader = giterminismManager.FileReader()
341332

342333
headHash, err := giterminismManager.LocalGitRepo().HeadCommitHash(ctx)
@@ -364,12 +355,18 @@ func runPublish(ctx context.Context, imageNameListFromArgs []string) error {
364355
loader.WithoutDefaultValues = *commonCmdData.DisableDefaultValues
365356
secrets.CoalesceTablesFunc = chartutil.CoalesceTables
366357
secrets.SecretsWorkingDir = giterminismManager.ProjectDir()
358+
secrets_manager.DisableSecretsDecryption = *commonCmdData.IgnoreSecretKey
367359

368360
chartextender.DefaultChartAPIVersion = chart.APIVersionV2
369361
chartextender.DefaultChartName = werfConfig.Meta.Project
370362
chartextender.DefaultChartVersion = "1.0.0"
371363
chartextender.ChartAppVersion = common.GetHelmChartConfigAppVersion(werfConfig)
372364

365+
// FIXME(1.3): compatibility mode with older 1.2 versions, which do not require WERF_SECRET_KEY in the 'werf bundle publish' command
366+
if err := secrets_manager.Manager.AllowMissedSecretKeyMode(giterminismManager.ProjectDir()); err != nil {
367+
return err
368+
}
369+
373370
sv, err := bundles.BundleTagToChartVersion(ctx, cmdData.Tag, time.Now())
374371
if err != nil {
375372
return fmt.Errorf("unable to set chart version from bundle tag %q: %w", cmdData.Tag, err)
@@ -463,7 +460,7 @@ func createNewBundle(
463460
}
464461

465462
var secretValsData []byte
466-
if chrt.SecretsRuntimeData != nil && !secrets_manager.DefaultManager.IsMissedSecretKeyModeEnabled() {
463+
if chrt.SecretsRuntimeData != nil && !secrets_manager.Manager.IsMissedSecretKeyModeEnabled() {
467464
vals, err := makeBundleSecretValues(ctx, chrt.SecretsRuntimeData)
468465
if err != nil {
469466
return fmt.Errorf("unable to construct bundle secret values: %w", err)
@@ -673,5 +670,5 @@ func makeBundleSecretValues(
673670
if chartutil.DebugSecretValues() {
674671
chartutil.DebugPrintValues(context.Background(), "secret", secretsRuntimeData.GetDecryptedSecretValues())
675672
}
676-
return secretsRuntimeData.GetEncodedSecretValues(ctx, secrets_manager.DefaultManager, false)
673+
return secretsRuntimeData.GetEncodedSecretValues(ctx, secrets_manager.Manager, false)
677674
}

cmd/werf/bundle/render/render.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515

1616
"github.com/werf/3p-helm/pkg/chart"
1717
"github.com/werf/3p-helm/pkg/chartutil"
18+
"github.com/werf/3p-helm/pkg/werf/secrets"
19+
"github.com/werf/common-go/pkg/secrets_manager"
1820
"github.com/werf/common-go/pkg/util"
1921
"github.com/werf/nelm/pkg/action"
2022
"github.com/werf/werf/v2/cmd/werf/common"
@@ -161,6 +163,19 @@ func runRender(ctx context.Context) error {
161163

162164
releaseNamespace := common.GetNamespace(&commonCmdData)
163165
releaseName := common.GetOptionalRelease(&commonCmdData)
166+
registryCredentialsPath := docker.GetDockerConfigCredentialsFile(*commonCmdData.DockerConfig)
167+
168+
secrets.CoalesceTablesFunc = chartutil.CoalesceTables
169+
secrets_manager.DisableSecretsDecryption = *commonCmdData.IgnoreSecretKey
170+
chartutil.ServiceValues, err = helpers.GetBundleServiceValues(ctx, helpers.ServiceValuesOptions{
171+
Env: *commonCmdData.Environment,
172+
Namespace: releaseNamespace,
173+
SetDockerConfigJsonValue: *commonCmdData.SetDockerConfigJsonValue,
174+
DockerConfigPath: filepath.Dir(registryCredentialsPath),
175+
})
176+
if err != nil {
177+
return fmt.Errorf("get service values: %w", err)
178+
}
164179

165180
var bundlePath string
166181
if isLocalBundle {
@@ -189,18 +204,6 @@ func runRender(ctx context.Context) error {
189204
return fmt.Errorf("get annotations and labels: %w", err)
190205
}
191206

192-
registryCredentialsPath := docker.GetDockerConfigCredentialsFile(*commonCmdData.DockerConfig)
193-
194-
chartutil.ServiceValues, err = helpers.GetBundleServiceValues(ctx, helpers.ServiceValuesOptions{
195-
Env: *commonCmdData.Environment,
196-
Namespace: releaseNamespace,
197-
SetDockerConfigJsonValue: *commonCmdData.SetDockerConfigJsonValue,
198-
DockerConfigPath: filepath.Dir(registryCredentialsPath),
199-
})
200-
if err != nil {
201-
return fmt.Errorf("get service values: %w", err)
202-
}
203-
204207
chart.CurrentChartType = chart.ChartTypeBundle
205208

206209
if err := action.Render(ctx, action.RenderOptions{

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ require (
6060
github.com/sirupsen/logrus v1.9.3
6161
github.com/spf13/cobra v1.8.0
6262
github.com/spf13/pflag v1.0.5
63-
github.com/werf/3p-helm v0.0.0-20250207093334-888917337dae
63+
github.com/werf/3p-helm v0.0.0-20250208082815-f391bcb12608
6464
github.com/werf/3p-helm-for-werf-helm v0.0.0-20241217155820-089f92cd5c9d
65-
github.com/werf/common-go v0.0.0-20250207093249-cd1b85356290
65+
github.com/werf/common-go v0.0.0-20250208082739-007d0979ac4b
6666
github.com/werf/copy-recurse v0.2.7
6767
github.com/werf/kubedog v0.12.4-0.20250122091205-68c31637c845
6868
github.com/werf/kubedog-for-werf-helm v0.0.0-20241217155728-9d45c48b82b6
6969
github.com/werf/lockgate v0.1.1
7070
github.com/werf/logboek v0.6.1
71-
github.com/werf/nelm v0.0.0-20250207093505-34e180d255cd
71+
github.com/werf/nelm v0.0.0-20250208083001-db6c2fbf96ce
7272
github.com/werf/nelm-for-werf-helm v0.0.0-20241217155925-b0e6734d1dbf
7373
go.opentelemetry.io/otel v1.24.0
7474
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -1433,14 +1433,14 @@ github.com/werf/3p-buildah v1.35.2-0.20241120093816-5b80b7b735de h1:adTANOZyNmmn
14331433
github.com/werf/3p-buildah v1.35.2-0.20241120093816-5b80b7b735de/go.mod h1:vVSVUlTu8+99H5j43gBJscpkb/quZvdJg78+6X1HeTM=
14341434
github.com/werf/3p-docker-buildx v0.13.0-rc2.0.20241111114615-d77c2e1444ad h1:FBDNACfjjpDBwXhALF5LgvEiu08HpUurb/2G323SVsQ=
14351435
github.com/werf/3p-docker-buildx v0.13.0-rc2.0.20241111114615-d77c2e1444ad/go.mod h1:Q3gtkv8D3sdaa5LJXbzMooYR/A5vBiEB2yQ56wywohM=
1436-
github.com/werf/3p-helm v0.0.0-20250207093334-888917337dae h1:gqy9fUkGIqY4m/2UKOUsK9UmKfqKoqrc28UUjKWleMQ=
1437-
github.com/werf/3p-helm v0.0.0-20250207093334-888917337dae/go.mod h1:n9jzrNNWo7DSNAwpLVDqhgx5+97Vx7SnTaJQm5+33Rc=
1436+
github.com/werf/3p-helm v0.0.0-20250208082815-f391bcb12608 h1:l52/hJ4owTUyW0VifUfmUCGMThWyHJH/YeNeacZ3xtY=
1437+
github.com/werf/3p-helm v0.0.0-20250208082815-f391bcb12608/go.mod h1:X2Ab7KcvII0xWOT3+sY0+erA6lR4M4uHV5+lfU9Ag/c=
14381438
github.com/werf/3p-helm-for-werf-helm v0.0.0-20241217155820-089f92cd5c9d h1:HN9jmAG2Gyhf8hJca9yoAO2xawNZQ/6OYDomxkKr5Sw=
14391439
github.com/werf/3p-helm-for-werf-helm v0.0.0-20241217155820-089f92cd5c9d/go.mod h1:fozJ+C/Llp1e+jHxrJOZUu+D4QEw+laQK6W6RFqvTsg=
14401440
github.com/werf/3p-oras v0.9.1-0.20240115121544-03962ecbd40a h1:PsU9szHZlIH+CjcuIuPXRLc5dsdoaFldvYjS6YHI7YQ=
14411441
github.com/werf/3p-oras v0.9.1-0.20240115121544-03962ecbd40a/go.mod h1:XTePf8biMMCkqbuuWBZ24xOwo3hZej+BBM0uvd8aGqk=
1442-
github.com/werf/common-go v0.0.0-20250207093249-cd1b85356290 h1:kgzJeq3TOqUqkl3+D07nKYvnRxkMHbW0lWabx1CuUtg=
1443-
github.com/werf/common-go v0.0.0-20250207093249-cd1b85356290/go.mod h1:7pkHNfgZ2wvdwcMWCuDjdkY7iR3mIX5snYwbd1Iu7T4=
1442+
github.com/werf/common-go v0.0.0-20250208082739-007d0979ac4b h1:6pV9c3VZQP0p9uUilULaGgif2HHCL8+IMMCOGFyfLAA=
1443+
github.com/werf/common-go v0.0.0-20250208082739-007d0979ac4b/go.mod h1:7pkHNfgZ2wvdwcMWCuDjdkY7iR3mIX5snYwbd1Iu7T4=
14441444
github.com/werf/copy-recurse v0.2.7 h1:3FTOarbJ9uhFLi75oeUCioK9zxZwuV7o28kuUBPDZPM=
14451445
github.com/werf/copy-recurse v0.2.7/go.mod h1:6Ypb+qN+hRBJgoCgEkX1vpbqcQ+8q69BQ3hi8s8Y6Qc=
14461446
github.com/werf/kubedog v0.12.4-0.20250122091205-68c31637c845 h1:LG5HPq5vDABdq6hPFIjUb9RX1IP2pNZLjRQlfzMQ/yQ=
@@ -1451,8 +1451,8 @@ github.com/werf/lockgate v0.1.1 h1:S400JFYjtWfE4i4LY9FA8zx0fMdfui9DPrBiTciCrx4=
14511451
github.com/werf/lockgate v0.1.1/go.mod h1:0yIFSLq9ausy6ejNxF5uUBf/Ib6daMAfXuCaTMZJzIE=
14521452
github.com/werf/logboek v0.6.1 h1:oEe6FkmlKg0z0n80oZjLplj6sXcBeLleCkjfOOZEL2g=
14531453
github.com/werf/logboek v0.6.1/go.mod h1:Gez5J4bxekyr6MxTmIJyId1F61rpO+0/V4vjCIEIZmk=
1454-
github.com/werf/nelm v0.0.0-20250207093505-34e180d255cd h1:mYONoCbd1VSedM3Sk8qlVNDFcMsr+0DW6/ee1yOmjbk=
1455-
github.com/werf/nelm v0.0.0-20250207093505-34e180d255cd/go.mod h1:aIRCaSSGnDIYjW1aY4HcRQRQCHVol/HWV0j01bdbYPc=
1454+
github.com/werf/nelm v0.0.0-20250208083001-db6c2fbf96ce h1:aVvsLaOzO6RPXXn4O90kNmZvyG4AsKoyX/9ubxSFB8I=
1455+
github.com/werf/nelm v0.0.0-20250208083001-db6c2fbf96ce/go.mod h1:XOA/fWDd8qUqcKKKzRox//WbeMyjgjii+kAwyKWgXeA=
14561456
github.com/werf/nelm-for-werf-helm v0.0.0-20241217155925-b0e6734d1dbf h1:K51qz209c1yJgKzPw8AeS72T21F/ACp0VI3RJvT4THA=
14571457
github.com/werf/nelm-for-werf-helm v0.0.0-20241217155925-b0e6734d1dbf/go.mod h1:7RJXSGPKKPEvfPqrTwNA8jT7y52O0ebwhSbSn29ESMA=
14581458
github.com/xanzy/go-gitlab v0.31.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=

0 commit comments

Comments
 (0)