@@ -44,6 +44,7 @@ import (
44
44
"sigs.k8s.io/kustomize/kyaml/yaml"
45
45
46
46
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
47
+ "github.com/fluxcd/kustomize-controller/decryptor"
47
48
"github.com/fluxcd/pkg/kustomize"
48
49
runclient "github.com/fluxcd/pkg/runtime/client"
49
50
ssautil "github.com/fluxcd/pkg/ssa/utils"
@@ -77,15 +78,16 @@ type Builder struct {
77
78
kustomizationFile string
78
79
ignore []string
79
80
// mu is used to synchronize access to the kustomization file
80
- mu sync.Mutex
81
- action kustomize.Action
82
- kustomization * kustomizev1.Kustomization
83
- timeout time.Duration
84
- spinner * yacspin.Spinner
85
- dryRun bool
86
- strictSubst bool
87
- recursive bool
88
- localSources map [string ]string
81
+ mu sync.Mutex
82
+ action kustomize.Action
83
+ kustomization * kustomizev1.Kustomization
84
+ timeout time.Duration
85
+ spinner * yacspin.Spinner
86
+ dryRun bool
87
+ strictSubst bool
88
+ recursive bool
89
+ decryptSecrets bool
90
+ localSources map [string ]string
89
91
// diff needs to handle kustomizations one by one
90
92
singleKustomization bool
91
93
}
@@ -190,6 +192,14 @@ func WithRecursive(recursive bool) BuilderOptionFunc {
190
192
}
191
193
}
192
194
195
+ // WithDecryptSecrets sets the decrypt secrets field
196
+ func WithDecryptSecrets (decryptSecrets bool ) BuilderOptionFunc {
197
+ return func (b * Builder ) error {
198
+ b .decryptSecrets = decryptSecrets
199
+ return nil
200
+ }
201
+ }
202
+
193
203
// WithLocalSources sets the local sources field
194
204
func WithLocalSources (localSources map [string ]string ) BuilderOptionFunc {
195
205
return func (b * Builder ) error {
@@ -514,7 +524,36 @@ func (b *Builder) do(ctx context.Context, kustomization kustomizev1.Kustomizatio
514
524
return nil , fmt .Errorf ("kustomize build failed: %w" , err )
515
525
}
516
526
527
+ var dec * decryptor.Decryptor
528
+ var cleanup func ()
529
+ if b .decryptSecrets {
530
+ dec , cleanup , err = decryptor .NewTempDecryptor (b .resourcesPath , b .client , b .kustomization )
531
+ if err != nil {
532
+ return nil , err
533
+ }
534
+ defer cleanup ()
535
+
536
+ // Import decryption keys
537
+ if err := dec .ImportKeys (ctx ); err != nil {
538
+ return nil , err
539
+ }
540
+ }
541
+
517
542
for _ , res := range m .Resources () {
543
+ if res .GetKind () == "Secret" && b .decryptSecrets {
544
+ outRes , err := dec .DecryptResource (res )
545
+ if err != nil {
546
+ return nil , fmt .Errorf ("decryption failed for '%s': %w" , res .GetName (), err )
547
+ }
548
+
549
+ if outRes != nil {
550
+ _ , err = m .Replace (res )
551
+ if err != nil {
552
+ return nil , err
553
+ }
554
+ }
555
+ }
556
+
518
557
// run variable substitutions
519
558
if kustomization .Spec .PostBuild != nil {
520
559
data , err := runtime .DefaultUnstructuredConverter .ToUnstructured (& kustomization )
0 commit comments