File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,25 @@ import (
99
1010type Envs []Env
1111
12+ // Add appends a new environment variable to the Envs slice with the given name and value.
13+ // If name is an empty string, the Name pointer will be nil, which is used for importing
14+ // all key-value pairs from a secret or configmap.
15+ // This method supports template syntax for values:
16+ // - Plain values: Add("KEY", "value")
17+ // - From local env: Add("KEY", "{{ env:LOCAL_VAR }}")
18+ // - From secret: Add("KEY", "{{ secret:secretName:key }}")
19+ // - From configmap: Add("KEY", "{{ configMap:configMapName:key }}")
20+ // - Import all from secret: Add("", "{{ secret:secretName }}")
21+ // - Import all from configmap: Add("", "{{ configMap:configMapName }}")
22+ func (ee * Envs ) Add (name , value string ) * Envs {
23+ env := Env {Value : & value }
24+ if name != "" {
25+ env .Name = & name
26+ }
27+ * ee = append (* ee , env )
28+ return ee
29+ }
30+
1231// String returns Envs as a space-separated set of environment variable
1332// declarations in the form "KEY=VALUE K2=V2"
1433func (ee Envs ) String () string {
Original file line number Diff line number Diff line change 1+ package functions
2+
3+ import "testing"
4+
5+ func TestEnvsAdd (t * testing.T ) {
6+ var envs Envs
7+ envs .Add ("KEY" , "value" )
8+
9+ if len (envs ) != 1 || * envs [0 ].Name != "KEY" || * envs [0 ].Value != "value" {
10+ t .Errorf ("Add failed: got %v" , envs )
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments