Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cluster-autoscaler/cloudprovider/cloudstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ that is suitable for your environment.
api-url = <CloudStack API URL>
api-key = <CloudStack API Key>
secret-key = <CloudStack API Secret>
project-id = <CloudStack Project ID> # Optional: required for multi-project environments
```
The access token needs to be able to execute the `listKubernetesClusters` and `scaleKubernetesCluster` APIs.

**Note:** The `project-id` parameter is optional but required when working with clusters in CloudStack projects.
If not specified, the API will use the default project associated with the API credentials.

To create the secret, use the following command:
```bash
kubectl -n kube-system create secret generic cloudstack-secret --from-file=cloud-config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func createConfig(opts ...option) (*managerConfig, error) {
APIKey: config.Global.APIKey,
SecretKey: config.Global.SecretKey,
Endpoint: config.Global.APIURL,
ProjectID: config.Global.ProjectID,
}
}

Expand Down
33 changes: 25 additions & 8 deletions cluster-autoscaler/cloudprovider/cloudstack/service/cks.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ type VirtualMachine struct {

// cksService implements the CKSService interface
type cksService struct {
client APIClient
client APIClient
projectID string
}

func virtaulMachinesToMap(vms []*VirtualMachine) map[string]*VirtualMachine {
Expand All @@ -89,9 +90,14 @@ func virtaulMachinesToMap(vms []*VirtualMachine) map[string]*VirtualMachine {

func (service *cksService) GetClusterDetails(clusterID string) (*Cluster, error) {
var out ListClusterResponse
_, err := service.client.NewRequest("listKubernetesClusters", map[string]string{
params := map[string]string{
"id": clusterID,
}, &out)
}
if service.projectID != "" {
params["projectid"] = service.projectID
}

_, err := service.client.NewRequest("listKubernetesClusters", params, &out)

if err != nil {
return nil, fmt.Errorf("Unable to fetch cluster details : %v", err)
Expand All @@ -108,10 +114,15 @@ func (service *cksService) GetClusterDetails(clusterID string) (*Cluster, error)

func (service *cksService) ScaleCluster(clusterID string, workerCount int) (*Cluster, error) {
var out ClusterResponse
_, err := service.client.NewRequest("scaleKubernetesCluster", map[string]string{
params := map[string]string{
"id": clusterID,
"size": strconv.Itoa(workerCount),
}, &out)
}
if service.projectID != "" {
params["projectid"] = service.projectID
}

_, err := service.client.NewRequest("scaleKubernetesCluster", params, &out)

if err != nil {
return nil, fmt.Errorf("Unable to scale cluster : %v", err)
Expand All @@ -123,10 +134,15 @@ func (service *cksService) ScaleCluster(clusterID string, workerCount int) (*Clu

func (service *cksService) RemoveNodesFromCluster(clusterID string, nodeIDs ...string) (*Cluster, error) {
var out ClusterResponse
_, err := service.client.NewRequest("scaleKubernetesCluster", map[string]string{
params := map[string]string{
"id": clusterID,
"nodeids": strings.Join(nodeIDs[:], ","),
}, &out)
}
if service.projectID != "" {
params["projectid"] = service.projectID
}

_, err := service.client.NewRequest("scaleKubernetesCluster", params, &out)
if err != nil {
return nil, fmt.Errorf("Unable to delete %v from cluster : %v", nodeIDs, err)
}
Expand All @@ -143,6 +159,7 @@ func (service *cksService) Close() {
func NewCKSService(config *Config) CKSService {
client := NewAPIClient(config)
return &cksService{
client: client,
client: client,
projectID: config.ProjectID,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Config struct {
APIKey string
SecretKey string
Endpoint string
ProjectID string
Timeout int
PollInterval int
}
Expand Down
Loading