diff --git a/ksops.go b/ksops.go index 8093a88..44de614 100644 --- a/ksops.go +++ b/ksops.go @@ -38,6 +38,7 @@ type secretFrom struct { Files []string `json:"files,omitempty" yaml:"files,omitempty"` BinaryFiles []string `json:"binaryFiles,omitempty" yaml:"binaryFiles,omitempty"` Envs []string `json:"envs,omitempty" yaml:"envs,omitempty"` + Literals []string `json:"literals,omitempty" yaml:"literals,omitempty"` Metadata types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"` Type string `json:"type,omitempty" yaml:"type,omitempty"` } @@ -197,6 +198,11 @@ func generate(raw []byte) (string, error) { } } + for _, literal := range secretFrom.Literals { + k, v := parseLiteral(literal) + stringData[k] = v + } + s := kubernetesSecret{ APIVersion: "v1", Kind: "Secret", @@ -243,3 +249,12 @@ func fileKeyPath(file string) (string, string) { } return slices[0], slices[1] } + +func parseLiteral(literal string) (string, string) { + k, v, found := strings.Cut(literal, "=") + if !found { + fmt.Fprintf(os.Stderr, "error parsing literal %s", literal) + os.Exit(1) + } + return k, v +} diff --git a/ksops_test.go b/ksops_test.go index 7a4ab80..14a4d77 100644 --- a/ksops_test.go +++ b/ksops_test.go @@ -107,6 +107,10 @@ func TestKSOPSPluginInstallation(t *testing.T) { name: "KRM From Envs", dir: "test/krm/envs", }, + { + name: "KRM From Literals", + dir: "test/krm/literals", + }, { name: "KRM Override Key", dir: "test/krm/override", diff --git a/test/krm/literals/generate-resources.yaml b/test/krm/literals/generate-resources.yaml new file mode 100644 index 0000000..cdffc0a --- /dev/null +++ b/test/krm/literals/generate-resources.yaml @@ -0,0 +1,17 @@ +apiVersion: viaduct.ai/v1 +kind: ksops +metadata: + name: ksops-secret-from-generator + annotations: + config.kubernetes.io/function: | + exec: + # if the binary is your PATH, you can do + path: ksops + # otherwise, path should be relative to manifest files, like + # path: ../../../ksops +secretFrom: +- metadata: + name: mysecret + literals: + - password=1f2d1e2e67df + - username=admin diff --git a/test/krm/literals/kustomization.yaml b/test/krm/literals/kustomization.yaml new file mode 100644 index 0000000..052a7d7 --- /dev/null +++ b/test/krm/literals/kustomization.yaml @@ -0,0 +1,2 @@ +generators: + - ./generate-resources.yaml diff --git a/test/krm/literals/want.yaml b/test/krm/literals/want.yaml new file mode 100644 index 0000000..dc42fc2 --- /dev/null +++ b/test/krm/literals/want.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: Secret +metadata: + name: mysecret +stringData: + password: 1f2d1e2e67df + username: admin