github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/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 // Workers ... 112 type WorkerPool interface { 113 CreateWorkerPool(workerPoolReq WorkerPoolRequest, target ClusterTargetHeader) (WorkerPoolResponse, error) 114 GetWorkerPool(clusterNameOrID, workerPoolNameOrID string, target ClusterTargetHeader) (GetWorkerPoolResponse, error) 115 ListWorkerPools(clusterNameOrID string, target ClusterTargetHeader) ([]GetWorkerPoolResponse, error) 116 CreateWorkerPoolZone(workerPoolZone WorkerPoolZone, target ClusterTargetHeader) error 117 DeleteWorkerPool(clusterNameOrID string, workerPoolNameOrID string, target ClusterTargetHeader) error 118 UpdateWorkerPoolTaints(taintRequest WorkerPoolTaintRequest, target ClusterTargetHeader) error 119 ResizeWorkerPool(resizeWorkerPoolReq ResizeWorkerPoolReq, target ClusterTargetHeader) error 120 UpdateWorkerPoolLabels(setWorkerPoolLabelsRequest SetWorkerPoolLabelsRequest, target ClusterTargetHeader) error 121 } 122 123 type workerpool struct { 124 client *client.Client 125 } 126 127 func newWorkerPoolAPI(c *client.Client) WorkerPool { 128 return &workerpool{ 129 client: c, 130 } 131 } 132 133 // GetWorkerPool calls the API to get a worker pool 134 func (w *workerpool) ListWorkerPools(clusterNameOrID string, target ClusterTargetHeader) ([]GetWorkerPoolResponse, error) { 135 successV := []GetWorkerPoolResponse{} 136 _, err := w.client.Get(fmt.Sprintf("/v2/vpc/getWorkerPools?cluster=%s", clusterNameOrID), &successV, target.ToMap()) 137 return successV, err 138 } 139 140 // GetWorkerPool calls the API to get a worker pool 141 func (w *workerpool) GetWorkerPool(clusterNameOrID, workerPoolNameOrID string, target ClusterTargetHeader) (GetWorkerPoolResponse, error) { 142 var successV GetWorkerPoolResponse 143 _, err := w.client.Get(fmt.Sprintf("/v2/vpc/getWorkerPool?cluster=%s&workerpool=%s", clusterNameOrID, workerPoolNameOrID), &successV, target.ToMap()) 144 return successV, err 145 } 146 147 // CreateWorkerPool calls the API to create a worker pool 148 func (w *workerpool) CreateWorkerPool(workerPoolReq WorkerPoolRequest, target ClusterTargetHeader) (WorkerPoolResponse, error) { 149 var successV WorkerPoolResponse 150 _, err := w.client.Post("/v2/vpc/createWorkerPool", workerPoolReq, &successV, target.ToMap()) 151 return successV, err 152 } 153 154 // DeleteWorkerPool calls the API to remove a worker pool 155 func (w *workerpool) DeleteWorkerPool(clusterNameOrID string, workerPoolNameOrID string, target ClusterTargetHeader) error { 156 // Make the request, don't care about return value 157 _, err := w.client.Delete(fmt.Sprintf("/v1/clusters/%s/workerpools/%s", clusterNameOrID, workerPoolNameOrID), target.ToMap()) 158 return err 159 } 160 161 // CreateWorkerPoolZone calls the API to add a zone to a cluster and worker pool 162 func (w *workerpool) CreateWorkerPoolZone(workerPoolZone WorkerPoolZone, target ClusterTargetHeader) error { 163 // Make the request, don't care about return value 164 _, err := w.client.Post("/v2/vpc/createWorkerPoolZone", workerPoolZone, nil, target.ToMap()) 165 return err 166 } 167 168 // UpdateWorkerPoolTaints calls the API to update taints to a worker pool 169 func (w *workerpool) UpdateWorkerPoolTaints(taintRequest WorkerPoolTaintRequest, target ClusterTargetHeader) error { 170 // Make the request, don't care about return value 171 _, err := w.client.Post("/v2/setWorkerPoolTaints", taintRequest, nil, target.ToMap()) 172 return err 173 } 174 175 // ResizeWorkerPool calls the API to resize an existing worker pool. 176 func (w *workerpool) ResizeWorkerPool(resizeWorkerPoolReq ResizeWorkerPoolReq, target ClusterTargetHeader) error { 177 // Make the request, don't care about return value 178 _, err := w.client.Post("/v2/resizeWorkerPool", resizeWorkerPoolReq, nil, target.ToMap()) 179 return err 180 } 181 182 func (w *workerpool) UpdateWorkerPoolLabels(setWorkerPoolLabelsRequest SetWorkerPoolLabelsRequest, target ClusterTargetHeader) error { 183 // Make the request, don't care about return value 184 _, err := w.client.Post("/v2/setWorkerPoolLabels", setWorkerPoolLabelsRequest, nil, target.ToMap()) 185 return err 186 }