Skip to content

Commit 3464588

Browse files
authored
handle differing JSON keys for API calls (#358)
1 parent 8500d0e commit 3464588

File tree

4 files changed

+96
-30
lines changed

4 files changed

+96
-30
lines changed

api/container/containerv2/worker_pool.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@ import (
99
// WorkerPoolRequest provides worker pool data
1010
// swagger:model
1111
type WorkerPoolRequest struct {
12-
Cluster string `json:"cluster" description:"cluster name where the worker pool will be created"`
13-
WorkerPoolConfig
12+
Cluster string `json:"cluster" description:"cluster name where the worker pool will be created"`
13+
DiskEncryption bool `json:"diskEncryption,omitempty"`
14+
Entitlement string `json:"entitlement"`
15+
Flavor string `json:"flavor"`
16+
HostPoolID string `json:"hostPool,omitempty"`
17+
Isolation string `json:"isolation,omitempty"`
18+
Labels map[string]string `json:"labels,omitempty"`
19+
Name string `json:"name" binding:"required" description:"The workerpool's name"`
20+
VpcID string `json:"vpcID"`
21+
WorkerCount int `json:"workerCount"`
22+
Zones []Zone `json:"zones"`
23+
WorkerVolumeEncryption *WorkerVolumeEncryption `json:"workerVolumeEncryption,omitempty"`
1424
}
1525
type WorkerPoolTaintRequest struct {
1626
Cluster string `json:"cluster" description:"cluster name"`

api/container/containerv2/worker_pool_test.go

+16-20
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var _ = Describe("workerpools", func() {
2828
server.AppendHandlers(
2929
ghttp.CombineHandlers(
3030
ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createWorkerPool"),
31-
ghttp.VerifyJSON(`{"cluster":"bm64u3ed02o93vv36hb0","flavor":"b2.4x16", "hostPoolID":"hostpoolid1", "name":"mywork211","vpcID":"6015365a-9d93-4bb4-8248-79ae0db2dc26","workerCount":1,"zones":[], "entitlement":""}`),
31+
ghttp.VerifyJSON(`{"cluster":"bm64u3ed02o93vv36hb0","flavor":"b2.4x16", "hostPool":"hostpoolid1", "name":"mywork211","vpcID":"6015365a-9d93-4bb4-8248-79ae0db2dc26","workerCount":1,"zones":[], "entitlement":""}`),
3232
ghttp.RespondWith(http.StatusCreated, `{
3333
"workerPoolID":"string"
3434
}`),
@@ -39,16 +39,14 @@ var _ = Describe("workerpools", func() {
3939
It("should create Workerpool in a cluster", func() {
4040
target := ClusterTargetHeader{}
4141
params := WorkerPoolRequest{
42-
Cluster: "bm64u3ed02o93vv36hb0",
43-
WorkerPoolConfig: WorkerPoolConfig{
44-
Flavor: "b2.4x16",
45-
HostPoolID: "hostpoolid1",
46-
Name: "mywork211",
47-
VpcID: "6015365a-9d93-4bb4-8248-79ae0db2dc26",
48-
WorkerCount: 1,
49-
Zones: []Zone{},
50-
Entitlement: "",
51-
},
42+
Cluster: "bm64u3ed02o93vv36hb0",
43+
Flavor: "b2.4x16",
44+
HostPoolID: "hostpoolid1",
45+
Name: "mywork211",
46+
VpcID: "6015365a-9d93-4bb4-8248-79ae0db2dc26",
47+
WorkerCount: 1,
48+
Zones: []Zone{},
49+
Entitlement: "",
5250
}
5351
_, err := newWorkerPool(server.URL()).CreateWorkerPool(params, target)
5452
Expect(err).NotTo(HaveOccurred())
@@ -70,15 +68,13 @@ var _ = Describe("workerpools", func() {
7068

7169
It("should return error during creating workerpool", func() {
7270
params := WorkerPoolRequest{
73-
Cluster: "bm64u3ed02o93vv36hb0",
74-
WorkerPoolConfig: WorkerPoolConfig{
75-
Flavor: "b2.4x16",
76-
Name: "mywork211",
77-
VpcID: "6015365a-9d93-4bb4-8248-79ae0db2dc26",
78-
WorkerCount: 1,
79-
Zones: []Zone{},
80-
Entitlement: "",
81-
},
71+
Cluster: "bm64u3ed02o93vv36hb0",
72+
Flavor: "b2.4x16",
73+
Name: "mywork211",
74+
VpcID: "6015365a-9d93-4bb4-8248-79ae0db2dc26",
75+
WorkerCount: 1,
76+
Zones: []Zone{},
77+
Entitlement: "",
8278
}
8379
target := ClusterTargetHeader{}
8480
_, err := newWorkerPool(server.URL()).CreateWorkerPool(params, target)

examples/container/V2containers/CreateWorkerpoolV2/main.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ func main() {
1818
trace.Logger = trace.NewLogger("true")
1919

2020
var poolinfo = v2.WorkerPoolRequest{
21-
Cluster: "bm64u3ed02o93vv36hb0",
22-
WorkerPoolConfig: v2.WorkerPoolConfig{
23-
Flavor: "c2.2x4",
24-
Name: "mywork21",
25-
VpcID: "6015365a-9d93-4bb4-8248-79ae0db2dc26",
26-
WorkerCount: 1,
27-
Zones: []v2.Zone{},
28-
},
21+
Cluster: "bm64u3ed02o93vv36hb0",
22+
Flavor: "c2.2x4",
23+
Name: "mywork21",
24+
VpcID: "6015365a-9d93-4bb4-8248-79ae0db2dc26",
25+
WorkerCount: 1,
26+
Zones: []v2.Zone{},
2927
}
3028
sess, err := session.New(c)
3129
if err != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
8+
bluemix "github.com/IBM-Cloud/bluemix-go"
9+
v2 "github.com/IBM-Cloud/bluemix-go/api/container/containerv2"
10+
"github.com/IBM-Cloud/bluemix-go/session"
11+
"github.com/IBM-Cloud/bluemix-go/trace"
12+
)
13+
14+
func main() {
15+
var VpcID string
16+
flag.StringVar(&VpcID, "vpcid", "", "VpcID")
17+
var SubnetID string
18+
flag.StringVar(&SubnetID, "subnetid", "", "SubnetID")
19+
var Name string
20+
flag.StringVar(&Name, "name", "bluemixV2Test", "Name")
21+
var Zone string
22+
flag.StringVar(&Zone, "zone", "us-south-1", "Zone")
23+
var HostPoolID string
24+
flag.StringVar(&HostPoolID, "hostpoolid", "", "HostPoolID")
25+
flag.Parse()
26+
fmt.Println("[FLAG]VpcID: ", VpcID)
27+
fmt.Println("[FLAG]SubnetID: ", SubnetID)
28+
fmt.Println("[FLAG]Name: ", Name)
29+
fmt.Println("[FLAG]Zone: ", Zone)
30+
fmt.Println("[FLAG]HostPoolID: ", HostPoolID)
31+
c := new(bluemix.Config)
32+
trace.Logger = trace.NewLogger("true")
33+
var workerPoolInfo = v2.WorkerPoolRequest{
34+
Cluster: Name,
35+
Name: fmt.Sprintf("%s-dhost-workerpool", Name),
36+
Flavor: "bx2d.16x64",
37+
VpcID: VpcID,
38+
WorkerCount: 1,
39+
HostPoolID: HostPoolID,
40+
Zones: []v2.Zone{
41+
{
42+
ID: Zone,
43+
SubnetID: SubnetID,
44+
},
45+
},
46+
}
47+
sess, err := session.New(c)
48+
if err != nil {
49+
log.Fatal(err)
50+
}
51+
target := v2.ClusterTargetHeader{}
52+
v2Client, err := v2.New(sess)
53+
if err != nil {
54+
log.Fatal(err)
55+
}
56+
workerPoolAPI := v2Client.WorkerPools()
57+
out, err := workerPoolAPI.CreateWorkerPool(workerPoolInfo, target)
58+
if err != nil {
59+
log.Fatal(err)
60+
}
61+
fmt.Println("out=", out)
62+
}

0 commit comments

Comments
 (0)