diff --git a/api/container/containerv1/api_service.go b/api/container/containerv1/api_service.go index 4c02c964..51e1db8b 100644 --- a/api/container/containerv1/api_service.go +++ b/api/container/containerv1/api_service.go @@ -18,6 +18,7 @@ const ErrCodeAPICreation = "APICreationError" type ContainerServiceAPI interface { Clusters() Clusters Workers() Workers + WorkerPools() WorkerPool WebHooks() Webhooks Subnets() Subnets KubeVersions() KubeVersions @@ -76,6 +77,11 @@ func (c *csService) Workers() Workers { return newWorkerAPI(c.Client) } +//WorkerPools implements Cluster WorkerPools API +func (c *csService) WorkerPools() WorkerPool { + return newWorkerPoolAPI(c.Client) +} + //Subnets implements Cluster Subnets API func (c *csService) Subnets() Subnets { return newSubnetAPI(c.Client) diff --git a/api/container/containerv1/worker_pool.go b/api/container/containerv1/worker_pool.go new file mode 100644 index 00000000..d4963221 --- /dev/null +++ b/api/container/containerv1/worker_pool.go @@ -0,0 +1,175 @@ +package containerv1 + +import ( + "fmt" + + "github.com/IBM-Cloud/bluemix-go/client" +) + +// WorkerPool common worker pool data +type WorkerPoolConfig struct { + Name string `json:"name" binding:"required"` + Size int `json:"sizePerZone" binding:"required"` + MachineType string `json:"machineType" binding:"required"` + Isolation string `json:"isolation"` + Labels map[string]string `json:"labels"` +} + +// WorkerPoolRequest provides worker pool data +// swagger:model +type WorkerPoolRequest struct { + WorkerPoolConfig + DiskEncryption bool `json:"diskEncryption" description:"true or false to use encryption for the secondary disk"` + Zones []WorkerPoolZone `json:"zones"` +} + +// WorkerPoolPatchRequest provides attributes to patch update worker pool +// swagger:model +type WorkerPoolPatchRequest struct { + Size int `json:"sizePerZone"` + ReasonForResize string `json:"reasonForResize"` + State string `json:"state"` +} + +// WorkerPoolResponse provides worker pool data +// swagger:model +type WorkerPoolResponse struct { + WorkerPoolConfig + ID string `json:"id" binding:"required"` + Region string `json:"region" binding:"required"` + State string `json:"state"` + WorkerVersion string `json:"kubeVersion"` + TargetVersion string `json:"targetVersion"` + EOS string `json:"versionEOS"` + MasterEOS string `json:"masterVersionEOS"` + ReasonForDelete string `json:"reasonForDelete"` + IsBalanced bool `json:"isBalanced"` + Zones WorkerPoolZoneResponses `json:"zones"` +} + +// WorkerPoolResponses sorts WorkerPoolResponse by ID. +// swagger:model +type WorkerPoolResponses []WorkerPoolResponse + +// WorkerPoolZoneNetwork holds network configuration for a zone +type WorkerPoolZoneNetwork struct { + PrivateVLAN string `json:"privateVlan" binding:"required"` + PublicVLAN string `json:"publicVlan"` +} + +// WorkerPoolZone provides zone data +// swagger:model +type WorkerPoolZone struct { + WorkerPoolZoneNetwork + ID string `json:"id" binding:"required"` +} + +// WorkerPoolZonePatchRequest updates worker pool zone data +// swagger:model +type WorkerPoolZonePatchRequest struct { + WorkerPoolZoneNetwork +} + +// WorkerPoolZoneResponse response contents for zone +// swagger:model +type WorkerPoolZoneResponse struct { + WorkerPoolZone + WorkerCount int `json:"workerCount"` +} + +// WorkerPoolZoneResponses sorts WorkerPoolZoneResponse by ID. +// swagger:model +type WorkerPoolZoneResponses []WorkerPoolZoneResponse + +//Workers ... +type WorkerPool interface { + CreateWorkerPool(clusterNameOrID string, workerPoolReq WorkerPoolRequest) (WorkerPoolResponse, error) + ResizeWorkerPool(clusterNameOrID, workerPoolNameOrID string, size int) error + PatchWorkerPool(clusterNameOrID, workerPoolNameOrID, state string) error + DeleteWorkerPool(clusterNameOrID string, workerPoolNameOrID string) error + ListWorkerPools(clusterNameOrID string) ([]WorkerPoolResponse, error) + GetWorkerPool(clusterNameOrID, workerPoolNameOrID string) (WorkerPoolResponse, error) + AddZone(clusterNameOrID string, poolID string, workerPoolZone WorkerPoolZone) error + RemoveZone(clusterNameOrID, zone, poolID string) error + UpdateZoneNetwork(clusterNameOrID, zone, poolID, privateVlan, publicVlan string) error +} + +type workerpool struct { + client *client.Client +} + +func newWorkerPoolAPI(c *client.Client) WorkerPool { + return &workerpool{ + client: c, + } +} + +// CreateWorkerPool calls the API to create a worker pool +func (w *workerpool) CreateWorkerPool(clusterNameOrID string, workerPoolReq WorkerPoolRequest) (WorkerPoolResponse, error) { + var successV WorkerPoolResponse + _, err := w.client.Post(fmt.Sprintf("/v1/clusters/%s/workerpools", clusterNameOrID), workerPoolReq, &successV) + return successV, err +} + +// ResizeWorkerPool calls the API to resize a worker +func (w *workerpool) PatchWorkerPool(clusterNameOrID, workerPoolNameOrID, state string) error { + requestBody := WorkerPoolPatchRequest{ + State: state, + } + _, err := w.client.Patch(fmt.Sprintf("/v1/clusters/%s/workerpools/%s", clusterNameOrID, workerPoolNameOrID), requestBody, nil) + return err +} + +// ResizeWorkerPool calls the API to resize a worker +func (w *workerpool) ResizeWorkerPool(clusterNameOrID, workerPoolNameOrID string, size int) error { + requestBody := WorkerPoolPatchRequest{ + State: "resizing", + Size: size, + } + _, err := w.client.Patch(fmt.Sprintf("/v1/clusters/%s/workerpools/%s", clusterNameOrID, workerPoolNameOrID), requestBody, nil) + return err +} + +// DeleteWorkerPool calls the API to remove a worker pool +func (w *workerpool) DeleteWorkerPool(clusterNameOrID string, workerPoolNameOrID string) error { + // Make the request, don't care about return value + _, err := w.client.Delete(fmt.Sprintf("/v1/clusters/%s/workerpools/%s", clusterNameOrID, workerPoolNameOrID)) + return err +} + +// ListWorkerPools calls the API to list all worker pools for a cluster +func (w *workerpool) ListWorkerPools(clusterNameOrID string) ([]WorkerPoolResponse, error) { + var successV []WorkerPoolResponse + _, err := w.client.Get(fmt.Sprintf("/v1/clusters/%s/workerpools", clusterNameOrID), &successV) + return successV, err +} + +// GetWorkerPool calls the API to get a worker pool +func (w *workerpool) GetWorkerPool(clusterNameOrID, workerPoolNameOrID string) (WorkerPoolResponse, error) { + var successV WorkerPoolResponse + _, err := w.client.Get(fmt.Sprintf("/v1/clusters/%s/workerpools/%s", clusterNameOrID, workerPoolNameOrID), &successV) + return successV, err +} + +// AddZone calls the API to add a zone to a cluster and worker pool +func (w *workerpool) AddZone(clusterNameOrID string, poolID string, workerPoolZone WorkerPoolZone) error { + // Make the request, don't care about return value + _, err := w.client.Post(fmt.Sprintf("/v1/clusters/%s/workerpools/%s/zones", clusterNameOrID, poolID), workerPoolZone, nil) + return err +} + +// RemoveZone calls the API to remove a zone from a worker pool in a cluster +func (w *workerpool) RemoveZone(clusterNameOrID, zone, poolID string) error { + _, err := w.client.Delete(fmt.Sprintf("/v1/clusters/%s/workerpools/%s/zones/%s", clusterNameOrID, poolID, zone)) + return err +} + +// UpdateZoneNetwork calls the API to update a zone's network +func (w *workerpool) UpdateZoneNetwork(clusterNameOrID, zone, poolID, privateVlan, publicVlan string) error { + body := WorkerPoolZoneNetwork{ + PrivateVLAN: privateVlan, + PublicVLAN: publicVlan, + } + _, err := w.client.Patch(fmt.Sprintf("/v1/clusters/%s/workerpools/%s/zones/%s", clusterNameOrID, poolID, zone), body, nil) + return err +} diff --git a/api/container/containerv1/worker_pool_test.go b/api/container/containerv1/worker_pool_test.go new file mode 100644 index 00000000..2765655c --- /dev/null +++ b/api/container/containerv1/worker_pool_test.go @@ -0,0 +1,363 @@ +package containerv1 + +import ( + "log" + "net/http" + + bluemix "github.com/IBM-Cloud/bluemix-go" + "github.com/IBM-Cloud/bluemix-go/client" + bluemixHttp "github.com/IBM-Cloud/bluemix-go/http" + "github.com/IBM-Cloud/bluemix-go/session" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/ghttp" +) + +var _ = Describe("WorkerPool", func() { + var server *ghttp.Server + Describe("CreateWorkerPool", func() { + Context("When creating a worker pool is successful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodPost, "/v1/clusters/test/workerpools"), + ghttp.RespondWith(http.StatusCreated, `{"Name":"testpool","Size":5,"MachineType": "u2c.2x4","Isolation": "public","ID":"rtr4tg5", "Region":"us-south", "State":"normal", "WorkerVersion":"1.9.0","MasterEOS":"1.9.0","ReasonForDelete":"","IsBalanced":true}`), + ), + ) + }) + + It("should return worker pools added to cluster", func() { + workerPoolProperties := WorkerPoolRequest{ + WorkerPoolConfig: WorkerPoolConfig{ + Name: "test-pool", + Size: 5, + MachineType: "u2c.2x4", + Isolation: "public", + }, + DiskEncryption: true, + } + _, err := newWorkerPool(server.URL()).CreateWorkerPool("test", workerPoolProperties) + Expect(err).NotTo(HaveOccurred()) + }) + }) + Context("When creating worker pool is unsuccessful", func() { + BeforeEach(func() { + + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodPost, "/v1/clusters/test/workerpools"), + ghttp.RespondWith(http.StatusInternalServerError, `Failed to create worker pools to cluster`), + ), + ) + }) + + It("should return worker pools added to cluster", func() { + workerPoolProperties := WorkerPoolRequest{ + WorkerPoolConfig: WorkerPoolConfig{ + Name: "test-pool", + Size: 5, + MachineType: "u2c.2x4", + Isolation: "public", + }, + DiskEncryption: true, + } + _, err := newWorkerPool(server.URL()).CreateWorkerPool("test", workerPoolProperties) + Expect(err).To(HaveOccurred()) + }) + }) + }) + //List + Describe("List", func() { + Context("When retrieving available worker pools of a cluster is successful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodGet, "/v1/clusters/myCluster/workerpools"), + ghttp.RespondWith(http.StatusOK, `[{"Name":"testpool","Size":5,"MachineType": "u2c.2x4","Isolation": "public","ID":"rtr4tg5", "Region":"us-south", "State":"normal", "WorkerVersion":"1.9.0","MasterEOS":"1.9.0","ReasonForDelete":"","IsBalanced":true}]`), + ), + ) + }) + + It("should return available worker pools ", func() { + worker, err := newWorkerPool(server.URL()).ListWorkerPools("myCluster") + Expect(err).NotTo(HaveOccurred()) + Expect(worker).ShouldNot(BeNil()) + for _, wObj := range worker { + Expect(wObj).ShouldNot(BeNil()) + Expect(wObj.State).Should(Equal("normal")) + } + }) + }) + Context("When retrieving available worker pools is unsuccessful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodGet, "/v1/clusters/myCluster/workerpools"), + ghttp.RespondWith(http.StatusInternalServerError, `Failed to retrieve workerpools`), + ), + ) + }) + + It("should return error during retrieveing worker pools", func() { + _, err := newWorkerPool(server.URL()).ListWorkerPools("myCluster") + Expect(err).To(HaveOccurred()) + }) + }) + }) + //Get + Describe("Get", func() { + Context("When retrieving worker pool of a cluster is successful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodGet, "/v1/clusters/myCluster/workerpools/abc-123-def"), + ghttp.RespondWith(http.StatusOK, `{"Name":"testpool","Size":5,"MachineType": "u2c.2x4","Isolation": "public","ID":"rtr4tg5", "Region":"us-south", "State":"normal", "WorkerVersion":"1.9.0","MasterEOS":"1.9.0","ReasonForDelete":"","IsBalanced":true}`), + ), + ) + }) + + It("should return worker pool", func() { + _, err := newWorkerPool(server.URL()).GetWorkerPool("myCluster", "abc-123-def") + Expect(err).NotTo(HaveOccurred()) + }) + }) + Context("When retrieving worker pool is unsuccessful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodGet, "/v1/clusters/myCluster/workerpools/abc-123-def"), + ghttp.RespondWith(http.StatusInternalServerError, `Failed to retrieve workerpool`), + ), + ) + }) + + It("should return error during retrieveing worker pool", func() { + _, err := newWorkerPool(server.URL()).GetWorkerPool("myCluster", "abc-123-def") + Expect(err).To(HaveOccurred()) + }) + }) + }) + //Delete + Describe("Delete", func() { + Context("When delete of worker pool is successful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodDelete, "/v1/clusters/test/workerpools/abc-123-def-ghi"), + ghttp.RespondWith(http.StatusOK, `{ + }`), + ), + ) + }) + + It("should delete worker pool", func() { + err := newWorkerPool(server.URL()).DeleteWorkerPool("test", "abc-123-def-ghi") + Expect(err).NotTo(HaveOccurred()) + }) + }) + Context("When worker pool delete is failed", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodDelete, "/v1/clusters/test/workerpools/abc-123-def-ghi"), + ghttp.RespondWith(http.StatusInternalServerError, `Failed to delete worker pool`), + ), + ) + }) + + It("should return error deleting worker pool", func() { + + err := newWorkerPool(server.URL()).DeleteWorkerPool("test", "abc-123-def-ghi") + Expect(err).To(HaveOccurred()) + }) + }) + }) + //Patch worker pool + Describe("Patch", func() { + Context("When resize of worker pool is successful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodPatch, "/v1/clusters/test/workerpools/abc-123-def-ghi"), + ghttp.RespondWith(http.StatusOK, `{ + }`), + ), + ) + }) + + It("should increase the size of worker pool", func() { + err := newWorkerPool(server.URL()).ResizeWorkerPool("test", "abc-123-def-ghi", 6) + Expect(err).NotTo(HaveOccurred()) + }) + }) + Context("When resize of worker pool is failed", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodPatch, "/v1/clusters/test/workerpools/abc-123-def-ghi"), + ghttp.RespondWith(http.StatusInternalServerError, `Failed to resize worker pool`), + ), + ) + }) + + It("should return error resizing worker pool", func() { + + err := newWorkerPool(server.URL()).ResizeWorkerPool("test", "abc-123-def-ghi", 6) + Expect(err).To(HaveOccurred()) + }) + }) + }) + //Add zone + Describe("Post", func() { + Context("When adding a zone is successful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodPost, "/v1/clusters/test/workerpools/abc-123-def-ghi/zones"), + ghttp.RespondWith(http.StatusOK, `{ + }`), + ), + ) + }) + + It("should add zone to the specified worker pool", func() { + workerPoolZone := WorkerPoolZone{ + ID: "abc-123-def-ghi", + WorkerPoolZoneNetwork: WorkerPoolZoneNetwork{ + PrivateVLAN: "12345", + PublicVLAN: "43215", + }, + } + err := newWorkerPool(server.URL()).AddZone("test", "abc-123-def-ghi", workerPoolZone) + Expect(err).NotTo(HaveOccurred()) + }) + }) + Context("When adding zone to worker pool is failed", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodPost, "/v1/clusters/test/workerpools/abc-123-def-ghi/zones"), + ghttp.RespondWith(http.StatusInternalServerError, `Failed to add zone to worker pool`), + ), + ) + }) + + It("should return error adding zone to worker pool", func() { + + workerPoolZone := WorkerPoolZone{ + ID: "abc-123-def-ghi", + WorkerPoolZoneNetwork: WorkerPoolZoneNetwork{ + PrivateVLAN: "12345", + PublicVLAN: "43215", + }, + } + err := newWorkerPool(server.URL()).AddZone("test", "abc-123-def-ghi", workerPoolZone) + Expect(err).To(HaveOccurred()) + }) + }) + }) + //Remove zone + Describe("Delete", func() { + Context("When delete of zone of a worker pool is successful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodDelete, "/v1/clusters/test/workerpools/abc-123-def-ghi/zones/dal10"), + ghttp.RespondWith(http.StatusOK, `{ + }`), + ), + ) + }) + + It("should delete worker pool in that zone", func() { + err := newWorkerPool(server.URL()).RemoveZone("test", "dal10", "abc-123-def-ghi") + Expect(err).NotTo(HaveOccurred()) + }) + }) + Context("When delete of zone of a worker pool delete is failed", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodDelete, "/v1/clusters/test/workerpools/abc-123-def-ghi/zones/dal10"), + ghttp.RespondWith(http.StatusInternalServerError, `Failed to delete zone of a worker pool`), + ), + ) + }) + + It("should return error deleting worker pool in the specific zone", func() { + + err := newWorkerPool(server.URL()).RemoveZone("test", "dal10", "abc-123-def-ghi") + Expect(err).To(HaveOccurred()) + }) + }) + }) + //UpdateZoneNetwork + Describe("Patch", func() { + Context("When update of worker pool zone is successful", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodPatch, "/v1/clusters/test/workerpools/abc-123-def-ghi/zones/dal10"), + ghttp.RespondWith(http.StatusOK, `{ + }`), + ), + ) + }) + + It("should update worker pool zone", func() { + err := newWorkerPool(server.URL()).UpdateZoneNetwork("test", "dal10", "abc-123-def-ghi", "12345", "43215") + Expect(err).NotTo(HaveOccurred()) + }) + }) + Context("When update of worker pool zone is failed", func() { + BeforeEach(func() { + server = ghttp.NewServer() + server.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest(http.MethodPatch, "/v1/clusters/test/workerpools/abc-123-def-ghi/zones/dal10"), + ghttp.RespondWith(http.StatusInternalServerError, `Failed to update worker pool zone`), + ), + ) + }) + + It("should return updating worker pool zone", func() { + + err := newWorkerPool(server.URL()).UpdateZoneNetwork("test", "dal10", "abc-123-def-ghi", "12345", "43215") + Expect(err).To(HaveOccurred()) + }) + }) + }) +}) + +func newWorkerPool(url string) WorkerPool { + + sess, err := session.New() + if err != nil { + log.Fatal(err) + } + conf := sess.Config.Copy() + conf.HTTPClient = bluemixHttp.NewHTTPClient(conf) + conf.Endpoint = &url + + client := client.Client{ + Config: conf, + ServiceName: bluemix.MccpService, + } + return newWorkerPoolAPI(&client) +} diff --git a/examples/container/create/main.go b/examples/container/create/main.go index a0580e49..98b53fd9 100644 --- a/examples/container/create/main.go +++ b/examples/container/create/main.go @@ -6,30 +6,15 @@ import ( "log" "os" - bluemix "github.com/IBM-Cloud/bluemix-go" "github.com/IBM-Cloud/bluemix-go/session" "github.com/IBM-Cloud/bluemix-go/api/account/accountv2" v1 "github.com/IBM-Cloud/bluemix-go/api/container/containerv1" "github.com/IBM-Cloud/bluemix-go/api/mccp/mccpv2" + "github.com/IBM-Cloud/bluemix-go/trace" ) -var clusterInfo = v1.ClusterCreateRequest{ - Name: "my_cluster", - Datacenter: "dal10", - MachineType: "free", - WorkerNum: 1, - PrivateVlan: "vlan", - PublicVlan: "vlan", - Isolation: "public", -} - func main() { - c := new(bluemix.Config) - flag.StringVar(&c.IBMID, "ibmid", "", "The IBM ID. You can also source it from env IBMID") - flag.StringVar(&c.IBMIDPassword, "ibmidpass", "", "The IBMID Password. You can also source it from IBMID_PASSWORD") - flag.StringVar(&c.Region, "region", "us-south", "The Bluemix region. You can source it from env BM_REGION or BLUEMIX_REGION") - flag.BoolVar(&c.Debug, "debug", false, "Show full trace if on") var org string flag.StringVar(&org, "org", "", "Bluemix Organization") @@ -37,17 +22,43 @@ func main() { var space string flag.StringVar(&space, "space", "", "Bluemix Space") + var zone string + flag.StringVar(&zone, "zone", "", "Zone") + + var privateVlan string + flag.StringVar(&privateVlan, "privateVlan", "", "Private Vlan") + + var publicVlan string + flag.StringVar(&publicVlan, "publicVlan", "", "Public vlan") + + var updatePrivateVlan string + flag.StringVar(&updatePrivateVlan, "updatePrivateVlan", "", "Private vlan") + + var updatePublicVlan string + flag.StringVar(&updatePublicVlan, "updatePublicVlan", "", "Public vlan") + var skipDeletion bool flag.BoolVar(&skipDeletion, "no-delete", false, "If provided will delete the resources created") flag.Parse() - if org == "" || space == "" { + trace.Logger = trace.NewLogger("true") + if org == "" || space == "" || privateVlan == "" || publicVlan == "" || updatePrivateVlan == "" || updatePublicVlan == "" || zone == "" { flag.Usage() os.Exit(1) } - sess, err := session.New(c) + var clusterInfo = v1.ClusterCreateRequest{ + Name: "my_cluster", + Datacenter: "dal10", + MachineType: "u2c.2x4", + WorkerNum: 1, + PrivateVlan: privateVlan, + PublicVlan: publicVlan, + Isolation: "public", + } + + sess, err := session.New() if err != nil { log.Fatal(err) } @@ -78,7 +89,7 @@ func main() { log.Fatal(err) } accountAPI := accClient.Accounts() - myAccount, err := accountAPI.FindByOrg(myorg.GUID, c.Region) + myAccount, err := accountAPI.FindByOrg(myorg.GUID, region) if err != nil { log.Fatal(err) } @@ -99,5 +110,56 @@ func main() { if err != nil { log.Fatal(err) } - fmt.Println(out) + + workerPoolAPI := clusterClient.WorkerPools() + workerPoolRequest := v1.WorkerPoolRequest{ + WorkerPoolConfig: v1.WorkerPoolConfig{ + Name: "test-workerpool", + Size: 2, + MachineType: "u2c.2x4", + Isolation: "public", + }, + DiskEncryption: true, + } + resp, err := workerPoolAPI.CreateWorkerPool(out.ID, workerPoolRequest) + if err != nil { + log.Fatal(err) + } + workerPoolZone := v1.WorkerPoolZone{ + ID: zone, + WorkerPoolZoneNetwork: v1.WorkerPoolZoneNetwork{ + PrivateVLAN: privateVlan, + PublicVLAN: publicVlan, + }, + } + err = workerPoolAPI.AddZone(out.ID, resp.ID, workerPoolZone) + if err != nil { + log.Fatal(err) + } + err = workerPoolAPI.UpdateZoneNetwork(out.ID, zone, resp.ID, updatePrivateVlan, updatePublicVlan) + if err != nil { + log.Fatal(err) + } + + err = workerPoolAPI.ResizeWorkerPool(out.ID, resp.ID, 3) + if err != nil { + log.Fatal(err) + } + + pool, err := workerPoolAPI.GetWorkerPool(out.ID, resp.ID) + if err != nil { + log.Fatal(err) + } + fmt.Println("Pool id is ", pool.ID) + + err = workerPoolAPI.RemoveZone(out.ID, zone, resp.ID) + if err != nil { + log.Fatal(err) + } + + err = workerPoolAPI.DeleteWorkerPool(out.ID, resp.ID) + if err != nil { + log.Fatal(err) + } + }