github.com/IBM-Cloud/bluemix-go@v0.0.0-20241117121028-a3be206688b3/api/container/containerv2/worker_pool.go (about) 1 package containerv2 2 3 import ( 4 "fmt" 5 6 "github.com/IBM-Cloud/bluemix-go/client" 7 ) 8 9 // CommonWorkerPoolConfig provides common worker pool data for cluster and workerpool operations 10 type CommonWorkerPoolConfig struct { 11 DiskEncryption bool `json:"diskEncryption,omitempty"` 12 Entitlement string `json:"entitlement"` 13 Flavor string `json:"flavor"` 14 Isolation string `json:"isolation,omitempty"` 15 Labels map[string]string `json:"labels,omitempty"` 16 Name string `json:"name" binding:"required" description:"The workerpool's name"` 17 OperatingSystem string `json:"operatingSystem,omitempty"` 18 VpcID string `json:"vpcID"` 19 WorkerCount int `json:"workerCount"` 20 Zones []Zone `json:"zones"` 21 WorkerVolumeEncryption *WorkerVolumeEncryption `json:"workerVolumeEncryption,omitempty"` 22 SecondaryStorageOption string `json:"secondaryStorageOption,omitempty"` 23 SecurityGroupIDs []string `json:"securityGroupIDs,omitempty"` 24 } 25 26 // WorkerPoolRequest provides worker pool data 27 // swagger:model 28 type WorkerPoolRequest struct { 29 Cluster string `json:"cluster" description:"cluster name where the worker pool will be created"` 30 HostPoolID string `json:"hostPool,omitempty"` 31 CommonWorkerPoolConfig 32 } 33 type WorkerPoolTaintRequest struct { 34 Cluster string `json:"cluster" description:"cluster name"` 35 WorkerPool string `json:"workerpool" description:"worker Pool name"` 36 Taints map[string]string `json:"taints" description:"map of taints that has to be applied on workerpool"` 37 } 38 39 type SetWorkerPoolLabelsRequest struct { 40 Cluster string `json:"cluster" description:"cluster name"` 41 WorkerPool string `json:"workerpool" description:"worker pool name"` 42 Labels map[string]string `json:"labels" description:"Labels to apply to the worker pool and each of its worker nodes."` 43 } 44 45 // WorkerPoolResponse provides worker pool data 46 // swagger:model 47 type WorkerPoolResponse struct { 48 ID string `json:"workerPoolID"` 49 } 50 51 type WorkerPoolZone struct { 52 Cluster string `json:"cluster"` 53 Id string `json:"id"` 54 SubnetID string `json:"subnetID"` 55 WorkerPoolID string `json:"workerPoolID"` 56 } 57 58 type GetWorkerPoolResponse struct { 59 AutoscaleEnabled bool `json:"autoscaleEnabled,omitempty"` 60 HostPoolID string `json:"dedicatedHostPoolId,omitempty"` 61 Flavor string `json:"flavor"` 62 ID string `json:"id"` 63 Isolation string `json:"isolation"` 64 Labels map[string]string `json:"labels,omitempty"` 65 Lifecycle `json:"lifecycle"` 66 OperatingSystem string `json:"operatingSystem,omitempty"` 67 PoolName string `json:"poolName"` 68 Provider string `json:"provider"` 69 SecondaryStorageOption *DiskConfigResp `json:"secondaryStorageOption,omitempty"` 70 Taints map[string]string `json:"taints,omitempty"` 71 VpcID string `json:"vpcID"` 72 WorkerCount int `json:"workerCount"` 73 WorkerVolumeEncryption *WorkerVolumeEncryption `json:"workerVolumeEncryption,omitempty"` 74 Zones []ZoneResp `json:"zones"` 75 } 76 77 // DiskConfigResp response type for describing a disk configuration 78 // swagger:model 79 type DiskConfigResp struct { 80 Name string `json:"name,omitempty"` 81 Count int 82 // the size of each individual device in GB 83 Size int 84 DeviceType string 85 RAIDConfiguration string 86 Profile string `json:"profile,omitempty"` 87 } 88 89 type Lifecycle struct { 90 ActualState string `json:"actualState"` 91 DesiredState string `json:"desiredState"` 92 } 93 94 type ZoneResp struct { 95 ID string `json:"id"` 96 WorkerCount int `json:"workerCount"` 97 Subnets []Subnet `json:"subnets"` 98 } 99 100 type Subnet struct { 101 ID string `json:"id"` 102 Primary bool `json:"primary"` 103 } 104 105 type ResizeWorkerPoolReq struct { 106 Cluster string `json:"cluster"` 107 Size int64 `json:"size"` 108 Workerpool string `json:"workerpool"` 109 } 110 111 type SetWorkerPoolOperatingSystem struct { 112 Cluster string `json:"cluster"` 113 WorkerPool string `json:"workerPool"` 114 OperatingSystem string `json:"operatingSystem"` 115 } 116 117 // Workers ... 118 type WorkerPool interface { 119 CreateWorkerPool(workerPoolReq WorkerPoolRequest, target ClusterTargetHeader) (WorkerPoolResponse, error) 120 GetWorkerPool(clusterNameOrID, workerPoolNameOrID string, target ClusterTargetHeader) (GetWorkerPoolResponse, error) 121 ListWorkerPools(clusterNameOrID string, target ClusterTargetHeader) ([]GetWorkerPoolResponse, error) 122 CreateWorkerPoolZone(workerPoolZone WorkerPoolZone, target ClusterTargetHeader) error 123 DeleteWorkerPool(clusterNameOrID string, workerPoolNameOrID string, target ClusterTargetHeader) error 124 UpdateWorkerPoolTaints(taintRequest WorkerPoolTaintRequest, target ClusterTargetHeader) error 125 ResizeWorkerPool(resizeWorkerPoolReq ResizeWorkerPoolReq, target ClusterTargetHeader) error 126 UpdateWorkerPoolLabels(setWorkerPoolLabelsRequest SetWorkerPoolLabelsRequest, target ClusterTargetHeader) error 127 SetWorkerPoolOperatingSystem(setWorkerPoolOperatingSystemRequest SetWorkerPoolOperatingSystem, target ClusterTargetHeader) error 128 } 129 130 type workerpool struct { 131 client *client.Client 132 } 133 134 func newWorkerPoolAPI(c *client.Client) WorkerPool { 135 return &workerpool{ 136 client: c, 137 } 138 } 139 140 // GetWorkerPool calls the API to get a worker pool 141 func (w *workerpool) ListWorkerPools(clusterNameOrID string, target ClusterTargetHeader) ([]GetWorkerPoolResponse, error) { 142 successV := []GetWorkerPoolResponse{} 143 _, err := w.client.Get(fmt.Sprintf("/v2/vpc/getWorkerPools?cluster=%s", clusterNameOrID), &successV, target.ToMap()) 144 return successV, err 145 } 146 147 // GetWorkerPool calls the API to get a worker pool 148 func (w *workerpool) GetWorkerPool(clusterNameOrID, workerPoolNameOrID string, target ClusterTargetHeader) (GetWorkerPoolResponse, error) { 149 var successV GetWorkerPoolResponse 150 _, err := w.client.Get(fmt.Sprintf("/v2/vpc/getWorkerPool?cluster=%s&workerpool=%s", clusterNameOrID, workerPoolNameOrID), &successV, target.ToMap()) 151 return successV, err 152 } 153 154 // CreateWorkerPool calls the API to create a worker pool 155 func (w *workerpool) CreateWorkerPool(workerPoolReq WorkerPoolRequest, target ClusterTargetHeader) (WorkerPoolResponse, error) { 156 var successV WorkerPoolResponse 157 _, err := w.client.Post("/v2/vpc/createWorkerPool", workerPoolReq, &successV, target.ToMap()) 158 return successV, err 159 } 160 161 // DeleteWorkerPool calls the API to remove a worker pool 162 func (w *workerpool) DeleteWorkerPool(clusterNameOrID string, workerPoolNameOrID string, target ClusterTargetHeader) error { 163 // Make the request, don't care about return value 164 _, err := w.client.Delete(fmt.Sprintf("/v1/clusters/%s/workerpools/%s", clusterNameOrID, workerPoolNameOrID), target.ToMap()) 165 return err 166 } 167 168 // CreateWorkerPoolZone calls the API to add a zone to a cluster and worker pool 169 func (w *workerpool) CreateWorkerPoolZone(workerPoolZone WorkerPoolZone, target ClusterTargetHeader) error { 170 // Make the request, don't care about return value 171 _, err := w.client.Post("/v2/vpc/createWorkerPoolZone", workerPoolZone, nil, target.ToMap()) 172 return err 173 } 174 175 // UpdateWorkerPoolTaints calls the API to update taints to a worker pool 176 func (w *workerpool) UpdateWorkerPoolTaints(taintRequest WorkerPoolTaintRequest, target ClusterTargetHeader) error { 177 // Make the request, don't care about return value 178 _, err := w.client.Post("/v2/setWorkerPoolTaints", taintRequest, nil, target.ToMap()) 179 return err 180 } 181 182 // ResizeWorkerPool calls the API to resize an existing worker pool. 183 func (w *workerpool) ResizeWorkerPool(resizeWorkerPoolReq ResizeWorkerPoolReq, target ClusterTargetHeader) error { 184 // Make the request, don't care about return value 185 _, err := w.client.Post("/v2/resizeWorkerPool", resizeWorkerPoolReq, nil, target.ToMap()) 186 return err 187 } 188 189 func (w *workerpool) UpdateWorkerPoolLabels(setWorkerPoolLabelsRequest SetWorkerPoolLabelsRequest, target ClusterTargetHeader) error { 190 // Make the request, don't care about return value 191 _, err := w.client.Post("/v2/setWorkerPoolLabels", setWorkerPoolLabelsRequest, nil, target.ToMap()) 192 return err 193 } 194 195 // SetWorkerPoolOperatingSystem calls the API to set the workerpool operating system. 196 func (w *workerpool) SetWorkerPoolOperatingSystem(setWorkerPoolOperatingSystemRequest SetWorkerPoolOperatingSystem, target ClusterTargetHeader) error { 197 // Returns 202 without body 198 _, err := w.client.Post("/v2/setWorkerPoolOperatingSystem", setWorkerPoolOperatingSystemRequest, nil, target.ToMap()) 199 return err 200 }