mirror of https://github.com/knative/func.git
chore: prefer slices over plural types (#655)
* chore: prefer slices over plural types * chore: update formatting to reflect slice types
This commit is contained in:
parent
db2c3e246e
commit
4d29384958
|
@ -407,7 +407,7 @@ func runRemoveEnvsPrompt(f fn.Function) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var newEnvs fn.Envs
|
||||
var newEnvs []fn.Env
|
||||
removed := false
|
||||
for i, e := range f.Envs {
|
||||
if e.String() == selectedEnv {
|
||||
|
|
|
@ -269,7 +269,7 @@ func runRemoveLabelsPrompt(f fn.Function, saver functionSaver) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var newLabels fn.Labels
|
||||
var newLabels []fn.Label
|
||||
removed := false
|
||||
for i, e := range f.Labels {
|
||||
if e.String() == selectedLabel {
|
||||
|
|
|
@ -30,7 +30,7 @@ func (m *mockFunctionLoaderSaver) Save(f fn.Function) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func assertLabelEq(t *testing.T, actual fn.Labels, want fn.Labels) {
|
||||
func assertLabelEq(t *testing.T, actual []fn.Label, want []fn.Label) {
|
||||
t.Helper()
|
||||
if !reflect.DeepEqual(actual, want) {
|
||||
t.Errorf("labels = %v, want %v", actual, want)
|
||||
|
@ -113,22 +113,22 @@ func TestNewConfigLabelsCmd(t *testing.T) {
|
|||
return fn.Label{Key: &k, Value: &v}
|
||||
}
|
||||
|
||||
assertLabel := func(ps fn.Labels) {
|
||||
assertLabel := func(ps []fn.Label) {
|
||||
t.Helper()
|
||||
assertLabelEq(t, *labels, ps)
|
||||
}
|
||||
|
||||
run("add", enter, "a", enter, "b", enter)
|
||||
assertLabel(fn.Labels{p("a", "b")})
|
||||
assertLabel([]fn.Label{p("a", "b")})
|
||||
|
||||
run("add", enter, enter, "c", enter, "d", enter)
|
||||
assertLabel(fn.Labels{p("a", "b"), p("c", "d")})
|
||||
assertLabel([]fn.Label{p("a", "b"), p("c", "d")})
|
||||
|
||||
run("add", arrowUp, arrowUp, enter, enter, "e", enter, "f", enter)
|
||||
assertLabel(fn.Labels{p("e", "f"), p("a", "b"), p("c", "d")})
|
||||
assertLabel([]fn.Label{p("e", "f"), p("a", "b"), p("c", "d")})
|
||||
|
||||
run("remove", arrowDown, enter)
|
||||
assertLabel(fn.Labels{p("e", "f"), p("c", "d")})
|
||||
assertLabel([]fn.Label{p("e", "f"), p("c", "d")})
|
||||
}
|
||||
|
||||
func TestListLabels(t *testing.T) {
|
||||
|
|
|
@ -224,7 +224,7 @@ func runRemoveVolumesPrompt(f fn.Function) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var newVolumes fn.Volumes
|
||||
var newVolumes []fn.Volume
|
||||
removed := false
|
||||
for i, v := range f.Volumes {
|
||||
if v.String() == selectedVolume {
|
||||
|
|
|
@ -299,7 +299,7 @@ func envFromCmd(cmd *cobra.Command) (*util.OrderedMap, []string, error) {
|
|||
return util.NewOrderedMap(), []string{}, nil
|
||||
}
|
||||
|
||||
func mergeEnvs(envs fn.Envs, envToUpdate *util.OrderedMap, envToRemove []string) (fn.Envs, error) {
|
||||
func mergeEnvs(envs []fn.Env, envToUpdate *util.OrderedMap, envToRemove []string) ([]fn.Env, error) {
|
||||
updated := sets.NewString()
|
||||
|
||||
for i := range envs {
|
||||
|
@ -332,7 +332,7 @@ func mergeEnvs(envs fn.Envs, envToUpdate *util.OrderedMap, envToRemove []string)
|
|||
|
||||
errMsg := fn.ValidateEnvs(envs)
|
||||
if len(errMsg) > 0 {
|
||||
return fn.Envs{}, fmt.Errorf(strings.Join(errMsg, "\n"))
|
||||
return []fn.Env{}, fmt.Errorf(strings.Join(errMsg, "\n"))
|
||||
}
|
||||
|
||||
return envs, nil
|
||||
|
|
|
@ -18,77 +18,77 @@ func Test_mergeEnvMaps(t *testing.T) {
|
|||
v2 := "y"
|
||||
|
||||
type args struct {
|
||||
envs fn.Envs
|
||||
envs []fn.Env
|
||||
toUpdate *util.OrderedMap
|
||||
toRemove []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want fn.Envs
|
||||
want []fn.Env
|
||||
}{
|
||||
{
|
||||
"add new var to empty list",
|
||||
args{
|
||||
fn.Envs{},
|
||||
[]fn.Env{},
|
||||
util.NewOrderedMapWithKVStrings([][]string{{a, v1}}),
|
||||
[]string{},
|
||||
},
|
||||
fn.Envs{fn.Env{Name: &a, Value: &v1}},
|
||||
[]fn.Env{{Name: &a, Value: &v1}},
|
||||
},
|
||||
{
|
||||
"add new var",
|
||||
args{
|
||||
fn.Envs{fn.Env{Name: &b, Value: &v2}},
|
||||
[]fn.Env{{Name: &b, Value: &v2}},
|
||||
util.NewOrderedMapWithKVStrings([][]string{{a, v1}}),
|
||||
[]string{},
|
||||
},
|
||||
fn.Envs{fn.Env{Name: &b, Value: &v2}, fn.Env{Name: &a, Value: &v1}},
|
||||
[]fn.Env{{Name: &b, Value: &v2}, {Name: &a, Value: &v1}},
|
||||
},
|
||||
{
|
||||
"update var",
|
||||
args{
|
||||
fn.Envs{fn.Env{Name: &a, Value: &v1}},
|
||||
[]fn.Env{{Name: &a, Value: &v1}},
|
||||
util.NewOrderedMapWithKVStrings([][]string{{a, v2}}),
|
||||
[]string{},
|
||||
},
|
||||
fn.Envs{fn.Env{Name: &a, Value: &v2}},
|
||||
[]fn.Env{{Name: &a, Value: &v2}},
|
||||
},
|
||||
{
|
||||
"update multiple vars",
|
||||
args{
|
||||
fn.Envs{fn.Env{Name: &a, Value: &v1}, fn.Env{Name: &b, Value: &v2}},
|
||||
[]fn.Env{{Name: &a, Value: &v1}, {Name: &b, Value: &v2}},
|
||||
util.NewOrderedMapWithKVStrings([][]string{{a, v2}, {b, v1}}),
|
||||
[]string{},
|
||||
},
|
||||
fn.Envs{fn.Env{Name: &a, Value: &v2}, fn.Env{Name: &b, Value: &v1}},
|
||||
[]fn.Env{{Name: &a, Value: &v2}, {Name: &b, Value: &v1}},
|
||||
},
|
||||
{
|
||||
"remove var",
|
||||
args{
|
||||
fn.Envs{fn.Env{Name: &a, Value: &v1}},
|
||||
[]fn.Env{{Name: &a, Value: &v1}},
|
||||
util.NewOrderedMap(),
|
||||
[]string{a},
|
||||
},
|
||||
fn.Envs{},
|
||||
[]fn.Env{},
|
||||
},
|
||||
{
|
||||
"remove multiple vars",
|
||||
args{
|
||||
fn.Envs{fn.Env{Name: &a, Value: &v1}, fn.Env{Name: &b, Value: &v2}},
|
||||
[]fn.Env{{Name: &a, Value: &v1}, {Name: &b, Value: &v2}},
|
||||
util.NewOrderedMap(),
|
||||
[]string{a, b},
|
||||
},
|
||||
fn.Envs{},
|
||||
[]fn.Env{},
|
||||
},
|
||||
{
|
||||
"update and remove vars",
|
||||
args{
|
||||
fn.Envs{fn.Env{Name: &a, Value: &v1}, fn.Env{Name: &b, Value: &v2}},
|
||||
[]fn.Env{{Name: &a, Value: &v1}, {Name: &b, Value: &v2}},
|
||||
util.NewOrderedMapWithKVStrings([][]string{{a, v2}}),
|
||||
[]string{b},
|
||||
},
|
||||
fn.Envs{fn.Env{Name: &a, Value: &v2}},
|
||||
[]fn.Env{{Name: &a, Value: &v2}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
19
config.go
19
config.go
|
@ -26,7 +26,6 @@ var (
|
|||
regLocalEnv = regexp.MustCompile(`^{{\s*env:(\w+)\s*}}$`)
|
||||
)
|
||||
|
||||
type Volumes []Volume
|
||||
type Volume struct {
|
||||
Secret *string `yaml:"secret,omitempty" jsonschema:"oneof_required=secret"`
|
||||
ConfigMap *string `yaml:"configMap,omitempty" jsonschema:"oneof_required=configmap"`
|
||||
|
@ -43,7 +42,6 @@ func (v Volume) String() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
type Envs []Env
|
||||
type Env struct {
|
||||
Name *string `yaml:"name,omitempty" jsonschema:"pattern=^[-._a-zA-Z][-._a-zA-Z0-9]*$"`
|
||||
Value *string `yaml:"value"`
|
||||
|
@ -78,7 +76,6 @@ func (e Env) String() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
type Labels []Label
|
||||
type Label struct {
|
||||
// Key consist of optional prefix part (ended by '/') and name part
|
||||
// Prefix part validation pattern: [a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*
|
||||
|
@ -141,12 +138,12 @@ type Config struct {
|
|||
Builders map[string]string `yaml:"builders"`
|
||||
Buildpacks []string `yaml:"buildpacks"`
|
||||
HealthEndpoints HealthEndpoints `yaml:"healthEndpoints"`
|
||||
Volumes Volumes `yaml:"volumes"`
|
||||
BuildEnvs Envs `yaml:"buildEnvs"`
|
||||
Envs Envs `yaml:"envs"`
|
||||
Volumes []Volume `yaml:"volumes"`
|
||||
BuildEnvs []Env `yaml:"buildEnvs"`
|
||||
Envs []Env `yaml:"envs"`
|
||||
Annotations map[string]string `yaml:"annotations"`
|
||||
Options Options `yaml:"options"`
|
||||
Labels Labels `yaml:"labels"`
|
||||
Labels []Label `yaml:"labels"`
|
||||
Created time.Time `yaml:"created"`
|
||||
// Add new values to the toConfig/fromConfig functions.
|
||||
}
|
||||
|
@ -282,7 +279,7 @@ func writeConfig(f Function) (err error) {
|
|||
// path: /etc/secret-volume
|
||||
// - configMap: example-configMap # mount ConfigMap as Volume
|
||||
// path: /etc/configMap-volume
|
||||
func validateVolumes(volumes Volumes) (errors []string) {
|
||||
func validateVolumes(volumes []Volume) (errors []string) {
|
||||
|
||||
for i, vol := range volumes {
|
||||
if vol.Secret != nil && vol.ConfigMap != nil {
|
||||
|
@ -312,7 +309,7 @@ func validateVolumes(volumes Volumes) (errors []string) {
|
|||
// value: value1
|
||||
// - name: EXAMPLE2 # ENV from the local ENV var
|
||||
// value: {{ env:MY_ENV }}
|
||||
func ValidateBuildEnvs(envs Envs) (errors []string) {
|
||||
func ValidateBuildEnvs(envs []Env) (errors []string) {
|
||||
for i, env := range envs {
|
||||
if env.Name == nil && env.Value == nil {
|
||||
errors = append(errors, fmt.Sprintf("env entry #%d is not properly set", i))
|
||||
|
@ -353,7 +350,7 @@ func ValidateBuildEnvs(envs Envs) (errors []string) {
|
|||
// - name: EXAMPLE4
|
||||
// value: {{ configMap:configMapName:key }} # ENV from a key in configMap
|
||||
// - value: {{ configMap:configMapName }} # all key-pair values from configMap are set as ENV
|
||||
func ValidateEnvs(envs Envs) (errors []string) {
|
||||
func ValidateEnvs(envs []Env) (errors []string) {
|
||||
for i, env := range envs {
|
||||
if env.Name == nil && env.Value == nil {
|
||||
errors = append(errors, fmt.Sprintf("env entry #%d is not properly set", i))
|
||||
|
@ -396,7 +393,7 @@ func ValidateEnvs(envs Envs) (errors []string) {
|
|||
// value: value1
|
||||
// - key: EXAMPLE2 # label from the local ENV var
|
||||
// value: {{ env:MY_ENV }}
|
||||
func ValidateLabels(labels Labels) (errors []string) {
|
||||
func ValidateLabels(labels []Label) (errors []string) {
|
||||
for i, label := range labels {
|
||||
if label.Key == nil && label.Value == nil {
|
||||
errors = append(errors, fmt.Sprintf("label entry #%d is not properly set", i))
|
||||
|
|
380
config_test.go
380
config_test.go
|
@ -20,13 +20,13 @@ func Test_validateVolumes(t *testing.T) {
|
|||
|
||||
tests := []struct {
|
||||
name string
|
||||
volumes Volumes
|
||||
volumes []Volume
|
||||
errs int
|
||||
}{
|
||||
{
|
||||
"correct entry - single volume with secret",
|
||||
Volumes{
|
||||
Volume{
|
||||
[]Volume{
|
||||
{
|
||||
Secret: &secret,
|
||||
Path: &path,
|
||||
},
|
||||
|
@ -35,8 +35,8 @@ func Test_validateVolumes(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - single volume with configmap",
|
||||
Volumes{
|
||||
Volume{
|
||||
[]Volume{
|
||||
{
|
||||
ConfigMap: &cm,
|
||||
Path: &path,
|
||||
},
|
||||
|
@ -45,12 +45,12 @@ func Test_validateVolumes(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple volumes with secrets",
|
||||
Volumes{
|
||||
Volume{
|
||||
[]Volume{
|
||||
{
|
||||
Secret: &secret,
|
||||
Path: &path,
|
||||
},
|
||||
Volume{
|
||||
{
|
||||
Secret: &secret2,
|
||||
Path: &path2,
|
||||
},
|
||||
|
@ -59,12 +59,12 @@ func Test_validateVolumes(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple volumes with both secret and configMap",
|
||||
Volumes{
|
||||
Volume{
|
||||
[]Volume{
|
||||
{
|
||||
Secret: &secret,
|
||||
Path: &path,
|
||||
},
|
||||
Volume{
|
||||
{
|
||||
ConfigMap: &cm,
|
||||
Path: &path2,
|
||||
},
|
||||
|
@ -73,8 +73,8 @@ func Test_validateVolumes(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"missing secret/configMap - single volume",
|
||||
Volumes{
|
||||
Volume{
|
||||
[]Volume{
|
||||
{
|
||||
Path: &path,
|
||||
},
|
||||
},
|
||||
|
@ -82,8 +82,8 @@ func Test_validateVolumes(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"missing path - single volume with secret",
|
||||
Volumes{
|
||||
Volume{
|
||||
[]Volume{
|
||||
{
|
||||
Secret: &secret,
|
||||
},
|
||||
},
|
||||
|
@ -91,8 +91,8 @@ func Test_validateVolumes(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"missing path - single volume with configMap",
|
||||
Volumes{
|
||||
Volume{
|
||||
[]Volume{
|
||||
{
|
||||
ConfigMap: &cm,
|
||||
},
|
||||
},
|
||||
|
@ -100,19 +100,19 @@ func Test_validateVolumes(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"missing secret/configMap and path - single volume",
|
||||
Volumes{
|
||||
Volume{},
|
||||
[]Volume{
|
||||
{},
|
||||
},
|
||||
1,
|
||||
},
|
||||
{
|
||||
"missing secret/configMap in one volume - multiple volumes",
|
||||
Volumes{
|
||||
Volume{
|
||||
[]Volume{
|
||||
{
|
||||
Secret: &secret,
|
||||
Path: &path,
|
||||
},
|
||||
Volume{
|
||||
{
|
||||
Path: &path2,
|
||||
},
|
||||
},
|
||||
|
@ -120,15 +120,15 @@ func Test_validateVolumes(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"missing secret/configMap and path in two different volumes - multiple volumes",
|
||||
Volumes{
|
||||
Volume{
|
||||
[]Volume{
|
||||
{
|
||||
Secret: &secret,
|
||||
Path: &path,
|
||||
},
|
||||
Volume{
|
||||
{
|
||||
Secret: &secret,
|
||||
},
|
||||
Volume{
|
||||
{
|
||||
Path: &path2,
|
||||
},
|
||||
},
|
||||
|
@ -165,13 +165,13 @@ func Test_validateBuildEnvs(t *testing.T) {
|
|||
|
||||
tests := []struct {
|
||||
name string
|
||||
envs Envs
|
||||
envs []Env
|
||||
errs int
|
||||
}{
|
||||
{
|
||||
"correct entry - single env with value",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &value,
|
||||
},
|
||||
|
@ -180,8 +180,8 @@ func Test_validateBuildEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - missing value",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
},
|
||||
},
|
||||
|
@ -189,8 +189,8 @@ func Test_validateBuildEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - invalid name",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &incorrectName,
|
||||
Value: &value,
|
||||
},
|
||||
|
@ -199,8 +199,8 @@ func Test_validateBuildEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - invalid name2",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &incorrectName2,
|
||||
Value: &value,
|
||||
},
|
||||
|
@ -209,12 +209,12 @@ func Test_validateBuildEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple envs with value",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &value,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name2,
|
||||
Value: &value2,
|
||||
},
|
||||
|
@ -223,11 +223,11 @@ func Test_validateBuildEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - mmissing value - multiple envs",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name2,
|
||||
},
|
||||
},
|
||||
|
@ -235,8 +235,8 @@ func Test_validateBuildEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - single env with value Local env",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
|
@ -245,16 +245,16 @@ func Test_validateBuildEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple envs with value Local env",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv3,
|
||||
},
|
||||
|
@ -263,20 +263,20 @@ func Test_validateBuildEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - multiple envs with value Local env",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnvIncorrect,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnvIncorrect2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnvIncorrect3,
|
||||
},
|
||||
|
@ -341,13 +341,13 @@ func Test_validateEnvs(t *testing.T) {
|
|||
|
||||
tests := []struct {
|
||||
name string
|
||||
envs Envs
|
||||
envs []Env
|
||||
errs int
|
||||
}{
|
||||
{
|
||||
"correct entry - single env with value",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &value,
|
||||
},
|
||||
|
@ -356,8 +356,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - missing value",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
},
|
||||
},
|
||||
|
@ -365,8 +365,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - invalid name",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &incorrectName,
|
||||
Value: &value,
|
||||
},
|
||||
|
@ -375,8 +375,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - invalid name2",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &incorrectName2,
|
||||
Value: &value,
|
||||
},
|
||||
|
@ -385,12 +385,12 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple envs with value",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &value,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name2,
|
||||
Value: &value2,
|
||||
},
|
||||
|
@ -399,11 +399,11 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - mmissing value - multiple envs",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name2,
|
||||
},
|
||||
},
|
||||
|
@ -411,8 +411,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - single env with value Local env",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
|
@ -421,16 +421,16 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple envs with value Local env",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv3,
|
||||
},
|
||||
|
@ -439,20 +439,20 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - multiple envs with value Local env",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnvIncorrect,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnvIncorrect2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnvIncorrect3,
|
||||
},
|
||||
|
@ -461,8 +461,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - single secret with key",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey,
|
||||
},
|
||||
|
@ -471,8 +471,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - single configMap with key",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey,
|
||||
},
|
||||
|
@ -481,36 +481,36 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple configMaps with key",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey3,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey4,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey5,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey6,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey7,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey8,
|
||||
},
|
||||
|
@ -519,36 +519,36 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple secrets with key",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey3,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey4,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey5,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey6,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey7,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey8,
|
||||
},
|
||||
|
@ -557,12 +557,12 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - both secret and configmap with key",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey,
|
||||
},
|
||||
|
@ -571,8 +571,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - single secret with key",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKeyIncorrect,
|
||||
},
|
||||
|
@ -581,20 +581,20 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - mutliple secrets with key",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKeyIncorrect,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKeyIncorrect2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKeyIncorrect3,
|
||||
},
|
||||
|
@ -603,8 +603,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - single whole secret",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Value: &valueSecret,
|
||||
},
|
||||
},
|
||||
|
@ -612,8 +612,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - single whole configMap",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Value: &valueConfigMap,
|
||||
},
|
||||
},
|
||||
|
@ -621,14 +621,14 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple whole secret",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Value: &valueSecret,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueSecret2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueSecret3,
|
||||
},
|
||||
},
|
||||
|
@ -636,11 +636,11 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - both whole secret and configMap",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Value: &valueSecret,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueConfigMap,
|
||||
},
|
||||
},
|
||||
|
@ -648,8 +648,8 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - single whole secret",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Value: &value,
|
||||
},
|
||||
},
|
||||
|
@ -657,29 +657,29 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - multiple whole secret",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Value: &valueSecretIncorrect,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueSecretIncorrect2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueSecretIncorrect3,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &value,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueLocalEnv2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueLocalEnv3,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueSecret,
|
||||
},
|
||||
},
|
||||
|
@ -687,52 +687,52 @@ func Test_validateEnvs(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - all combinations",
|
||||
Envs{
|
||||
Env{
|
||||
[]Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &value,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name2,
|
||||
Value: &value2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueLocalEnv3,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueSecret,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueSecret2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueSecret3,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Value: &valueConfigMap,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey2,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueSecretKey3,
|
||||
},
|
||||
Env{
|
||||
{
|
||||
Name: &name,
|
||||
Value: &valueConfigMapKey,
|
||||
},
|
||||
|
@ -779,13 +779,13 @@ func Test_validateLabels(t *testing.T) {
|
|||
|
||||
tests := []struct {
|
||||
key string
|
||||
labels Labels
|
||||
labels []Label
|
||||
errs int
|
||||
}{
|
||||
{
|
||||
"correct entry - single label with value",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &value,
|
||||
},
|
||||
|
@ -794,8 +794,8 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - prefixed label with value",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key3,
|
||||
Value: &value3,
|
||||
},
|
||||
|
@ -803,19 +803,19 @@ func Test_validateLabels(t *testing.T) {
|
|||
0,
|
||||
}, {
|
||||
"incorrect entry - missing key",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Value: &value,
|
||||
},
|
||||
},
|
||||
1,
|
||||
}, {
|
||||
"incorrect entry - missing multiple keys",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Value: &value,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Value: &value2,
|
||||
},
|
||||
},
|
||||
|
@ -823,8 +823,8 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - invalid key",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &incorrectKey,
|
||||
Value: &value,
|
||||
},
|
||||
|
@ -833,8 +833,8 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - invalid key2",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &incorrectKey2,
|
||||
Value: &value,
|
||||
},
|
||||
|
@ -843,8 +843,8 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - invalid value",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &incorrectValue,
|
||||
},
|
||||
|
@ -853,12 +853,12 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple labels with value",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &value,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key2,
|
||||
Value: &value2,
|
||||
},
|
||||
|
@ -867,11 +867,11 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - missing value - multiple labels",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key2,
|
||||
},
|
||||
},
|
||||
|
@ -879,8 +879,8 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - single label with value from local env",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
|
@ -889,16 +889,16 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - multiple labels with values from Local env",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnv2,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnv3,
|
||||
},
|
||||
|
@ -907,20 +907,20 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"incorrect entry - multiple labels with values from Local env",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnvIncorrect,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnvIncorrect2,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnvIncorrect3,
|
||||
},
|
||||
|
@ -929,8 +929,8 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - good environment variable value",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnv4,
|
||||
},
|
||||
|
@ -938,8 +938,8 @@ func Test_validateLabels(t *testing.T) {
|
|||
0,
|
||||
}, {
|
||||
"incorrect entry - bad environment variable value",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnvIncorrect4,
|
||||
},
|
||||
|
@ -948,28 +948,28 @@ func Test_validateLabels(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"correct entry - all combinations",
|
||||
Labels{
|
||||
Label{
|
||||
[]Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &value,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key2,
|
||||
Value: &value2,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key3,
|
||||
Value: &value3,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnv,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnv2,
|
||||
},
|
||||
Label{
|
||||
{
|
||||
Key: &key,
|
||||
Value: &valueLocalEnv3,
|
||||
},
|
||||
|
|
|
@ -56,13 +56,13 @@ type Function struct {
|
|||
Buildpacks []string
|
||||
|
||||
// List of volumes to be mounted to the function
|
||||
Volumes Volumes
|
||||
Volumes []Volume
|
||||
|
||||
// Build Env variables to be set
|
||||
BuildEnvs Envs
|
||||
BuildEnvs []Env
|
||||
|
||||
// Env variables to be set
|
||||
Envs Envs
|
||||
Envs []Env
|
||||
|
||||
// Map containing user-supplied annotations
|
||||
// Example: { "division": "finance" }
|
||||
|
@ -72,7 +72,7 @@ type Function struct {
|
|||
Options Options
|
||||
|
||||
// Map of user-supplied labels
|
||||
Labels Labels
|
||||
Labels []Label
|
||||
|
||||
// Health endpoints specified by the language pack
|
||||
HealthEndpoints HealthEndpoints
|
||||
|
|
|
@ -390,7 +390,7 @@ func processLabels(f fn.Function) (map[string]string, error) {
|
|||
// - name: EXAMPLE4
|
||||
// value: {{ configMap:configMapName:key }} # ENV from a key in ConfigMap
|
||||
// - value: {{ configMap:configMapName }} # all key-pair values from ConfigMap are set as ENV
|
||||
func processEnvs(envs fn.Envs, referencedSecrets, referencedConfigMaps *sets.String) ([]corev1.EnvVar, []corev1.EnvFromSource, error) {
|
||||
func processEnvs(envs []fn.Env, referencedSecrets, referencedConfigMaps *sets.String) ([]corev1.EnvVar, []corev1.EnvFromSource, error) {
|
||||
|
||||
envVars := []corev1.EnvVar{{Name: "BUILT", Value: time.Now().Format("20060102T150405")}}
|
||||
envFrom := []corev1.EnvFromSource{}
|
||||
|
@ -563,7 +563,7 @@ func processLocalEnvValue(val string) (string, error) {
|
|||
// path: /etc/secret-volume
|
||||
// - configMap: example-cm # mount ConfigMap as Volume
|
||||
// path: /etc/cm-volume
|
||||
func processVolumes(volumes fn.Volumes, referencedSecrets, referencedConfigMaps *sets.String) ([]corev1.Volume, []corev1.VolumeMount, error) {
|
||||
func processVolumes(volumes []fn.Volume, referencedSecrets, referencedConfigMaps *sets.String) ([]corev1.Volume, []corev1.VolumeMount, error) {
|
||||
|
||||
createdVolumes := sets.NewString()
|
||||
usedPaths := sets.NewString()
|
||||
|
|
Loading…
Reference in New Issue