Skip to content

Commit

Permalink
fix sheduler_hints
Browse files Browse the repository at this point in the history
  • Loading branch information
vooon committed Dec 13, 2023
1 parent d80544a commit fef64ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ExtCreateOpts struct {
Networks any `json:"networks,omitempty"`
SecurityGroups []string `json:"security_groups,omitempty"`
UserData string `json:"user_data,omitempty"`
SchedulerHints *SchedulerHints `json:"os:scheduler_hints,omitempty"`
SchedulerHints *SchedulerHints `json:"scheduler_hints,omitempty"`
}

// ToServerCreateMap for extended opts
Expand All @@ -61,6 +61,14 @@ func (opts ExtCreateOpts) ToServerCreateMap() (map[string]interface{}, error) {
delete(b, "user_data")
delete(b, "security_groups")

if opts.SchedulerHints != nil {
hints := b["scheduler_hints"]
delete(b, "scheduler_hints")
if hints != nil {
ob["os:scheduler_hints"] = hints
}
}

sob := ob["server"].(map[string]any)
maps.Copy(sob, b)

Expand Down
4 changes: 2 additions & 2 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ func TestExtCreateOpts(t *testing.T) {
"key_name": "gitlab-autoscaler",
"networks": [{"uuid": "c487d046-80ad-4da0-8b98-4a48ad3c257a"}],
"security_groups": ["allow_gitlab_runner"],
"os:scheduler_hints": {"group": "a5b557be-b7f0-4cb3-8f7c-6b5092f29c2c"},
"scheduler_hints": {"group": "a5b557be-b7f0-4cb3-8f7c-6b5092f29c2c"},
"tags": ["podman", "CI"],
"user_data": "#!cloud-config\npackage_update: true\npackage_upgrade: true\n",
"metadata": {"foo": "bar"}
}
`

expected := `{"server":{"description":"podman instance","flavorRef":"5","imageRef":"f2403879-6fbe-49a0-b71f-54b70039f32a","key_name":"gitlab-autoscaler","metadata":{"foo":"bar"},"name":"gitlab-runner-%d","networks":[{"uuid":"c487d046-80ad-4da0-8b98-4a48ad3c257a"}],"os:scheduler_hints":{"group":"a5b557be-b7f0-4cb3-8f7c-6b5092f29c2c"},"security_groups":[{"name":"allow_gitlab_runner"}],"tags":["podman","CI"],"user_data":"IyFjbG91ZC1jb25maWcKcGFja2FnZV91cGRhdGU6IHRydWUKcGFja2FnZV91cGdyYWRlOiB0cnVlCg=="}}`
expected := `{"os:scheduler_hints":{"group":"a5b557be-b7f0-4cb3-8f7c-6b5092f29c2c"},"server":{"description":"podman instance","flavorRef":"5","imageRef":"f2403879-6fbe-49a0-b71f-54b70039f32a","key_name":"gitlab-autoscaler","metadata":{"foo":"bar"},"name":"gitlab-runner-%d","networks":[{"uuid":"c487d046-80ad-4da0-8b98-4a48ad3c257a"}],"security_groups":[{"name":"allow_gitlab_runner"}],"tags":["podman","CI"],"user_data":"IyFjbG91ZC1jb25maWcKcGFja2FnZV91cGRhdGU6IHRydWUKcGFja2FnZV91cGdyYWRlOiB0cnVlCg=="}}`

cfg := new(ExtCreateOpts)
err := json.Unmarshal([]byte(cfgJSON), cfg)
Expand Down

0 comments on commit fef64ce

Please sign in to comment.