44package generators
55
66import (
7+ "fmt"
8+
79 "sigs.k8s.io/kustomize/api/ifc"
810 "sigs.k8s.io/kustomize/api/types"
911 "sigs.k8s.io/kustomize/kyaml/yaml"
1012)
1113
1214// MakeSecret makes a kubernetes Secret.
1315//
14- // Secret: https://kubernetes.io/docs/reference/generated/ kubernetes-api/v1.19/# secret-v1-core
16+ // Secret: https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/ secret-v1/
1517//
1618// ConfigMaps and Secrets are similar.
1719//
1820// Like a ConfigMap, a Secret has a `data` field, but unlike a ConfigMap it has
19- // no `binaryData` field.
21+ // no `binaryData` field. Secret also provides a `stringData` field.
2022//
21- // All of a Secret's data is assumed to be opaque in nature, and assumed to be
23+ // A Secret's ` data` is assumed to be opaque in nature, and assumed to be
2224// base64 encoded from its original representation, regardless of whether the
2325// original data was UTF-8 text or binary.
2426//
2527// This encoding provides no secrecy. It's just a neutral, common means to
2628// represent opaque text and binary data. Beneath the base64 encoding
2729// is presumably further encoding under control of the Secret's consumer.
2830//
31+ // A Secret's `stringData` field is similar to ConfigMap's `data` field.
32+ // `stringData` allows specifying non-binary, UTF-8 secret data in string form.
33+ // It is provided as a write-only input field for convenience.
34+ // All keys and values are merged into the data field on write, overwriting any
35+ // existing values. The stringData field is never output when reading from the API.
36+ //
2937// A Secret has string field `type` which holds an identifier, used by the
3038// client, to choose the algorithm to interpret the `data` field. Kubernetes
3139// cannot make use of this data; it's up to a controller or some pod's service
@@ -50,8 +58,14 @@ func MakeSecret(
5058 if err != nil {
5159 return nil , err
5260 }
53- if err = rn .LoadMapIntoSecretData (m ); err != nil {
54- return nil , err
61+ if args .StringData {
62+ if err = rn .LoadMapIntoSecretStringData (m ); err != nil {
63+ return nil , fmt .Errorf ("Failed to load map into Secret stringData: %w" , err )
64+ }
65+ } else {
66+ if err = rn .LoadMapIntoSecretData (m ); err != nil {
67+ return nil , fmt .Errorf ("Failed to load map into Secret data: %w" , err )
68+ }
5569 }
5670 copyLabelsAndAnnotations (rn , args .Options )
5771 setImmutable (rn , args .Options )
0 commit comments