-
Notifications
You must be signed in to change notification settings - Fork 23
/
env_var.go
47 lines (36 loc) · 1 KB
/
env_var.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package models
import (
"database/sql/driver"
"encoding/json"
"errors"
k8scorev1 "k8s.io/api/core/v1"
)
// EnvVar represents an environment variable present in a container.
type EnvVar struct {
// Name of the environment variable.
Name string `json:"name"`
// Value of the environment variable.
// Defaults to "".
Value string `json:"value"`
}
// EnvVars is a list of environment variables to set in the container.
type EnvVars []*EnvVar
func (evs EnvVars) Value() (driver.Value, error) {
return json.Marshal(evs)
}
func (evs *EnvVars) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &evs)
}
// ToKubernetesEnvVars returns the representation of Kubernetes'
// v1.EnvVars.
func (evs EnvVars) ToKubernetesEnvVars() []k8scorev1.EnvVar {
kubeEnvVars := make([]k8scorev1.EnvVar, len(evs))
for k, ev := range evs {
kubeEnvVars[k] = k8scorev1.EnvVar{Name: ev.Name, Value: ev.Value}
}
return kubeEnvVars
}