Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpack the string values from the CL2_.* envs #1145

Merged
merged 1 commit into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion clusterloader2/pkg/config/template_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"strconv"
"strings"
"sync"
"text/template"
Expand Down Expand Up @@ -240,11 +241,24 @@ func LoadCL2Envs() (map[string]interface{}, error) {
return nil, goerrors.Errorf("unparsable string in os.Eviron(): %v", keyValue)
}
key, value := split[0], split[1]
mapping[key] = value
mapping[key] = unpackStringValue(value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure it won't break any existing test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 99% sure as of now.
Currently, we only use this feature in two places: scheduler_throughput and access_tokens. Both are enabled in the presubmit so we'll know for 100% in ~30min

}
return mapping, nil
}

func unpackStringValue(str string) interface{} {
if v, err := strconv.ParseBool(str); err == nil {
return v
}
if v, err := strconv.ParseInt(str, 10, 64); err == nil {
return v
}
if v, err := strconv.ParseFloat(str, 64); err == nil {
return v
}
return str
}

// MergeMappings modifies map b to contain all new key=value pairs from b.
// It will return error in case of conflict, i.e. if exists key k for which a[k] != b[k]
func MergeMappings(a, b map[string]interface{}) error {
Expand Down
12 changes: 8 additions & 4 deletions clusterloader2/pkg/config/template_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,22 @@ func TestLoadCL2Envs(t *testing.T) {
"NODE_SIZE": "n1-standard-1",
},
wantedMapping: map[string]interface{}{
"CL2_MY_PARAM": "100",
"CL2_MY_PARAM": int64(100),
},
},
{
name: "Multiple CL2 envs",
env: map[string]string{
"CL2_MY_PARAM1": "100",
"CL2_MY_PARAM2": "XXX",
"CL2_MY_PARAM2": "true",
"CL2_MY_PARAM3": "99.99",
"CL2_MY_PARAM4": "XXX",
},
wantedMapping: map[string]interface{}{
"CL2_MY_PARAM1": "100",
"CL2_MY_PARAM2": "XXX",
"CL2_MY_PARAM1": int64(100),
"CL2_MY_PARAM2": true,
"CL2_MY_PARAM3": 99.99,
"CL2_MY_PARAM4": "XXX",
},
},
{
Expand Down