From 532f77332e6aaf8c2a0510becdc9ffed13736a33 Mon Sep 17 00:00:00 2001 From: Andrius521 Date: Mon, 6 Jun 2022 16:56:32 +0300 Subject: [PATCH 1/2] Add support for passing os partition size when creating nodes --- .../cherryservers/cherry_manager_rest.go | 20 +++++++++++------- .../cherryservers/cherry_types.go | 21 ++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go b/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go index 98789927b91c..3c8c000aee7c 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go +++ b/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go @@ -72,6 +72,7 @@ type cherryManagerNodePool struct { cloudinit string hostnamePattern string sshKeyIDs []int + osPartitionSize int waitTimeStep time.Duration } @@ -94,6 +95,7 @@ type ConfigNodepool struct { SSHKeys []string `gcfg:"ssh-key-ids"` CloudInit string `gcfg:"cloudinit"` HostnamePattern string `gcfg:"hostname-pattern"` + OsPartitionSize int `gcfg:"os-partition-size"` } // IsEmpty determine if this is an empty config @@ -235,6 +237,7 @@ func createCherryManagerRest(configReader io.Reader, discoverOpts cloudprovider. cloudinit: nodepool.CloudInit, sshKeyIDs: sshKeyIDs, hostnamePattern: nodepool.HostnamePattern, + osPartitionSize: nodepool.OsPartitionSize, } } @@ -427,14 +430,15 @@ func (mgr *cherryManagerRest) createNode(ctx context.Context, cloudinit, nodegro return fmt.Errorf("failed to create hostname from template: %w", err) } cr := &CreateServer{ - Hostname: hn, - Region: mgr.getNodePoolDefinition(nodegroup).region, - PlanID: mgr.getNodePoolDefinition(nodegroup).plan, - Image: mgr.getNodePoolDefinition(nodegroup).os, - ProjectID: mgr.getNodePoolDefinition(nodegroup).projectID, - UserData: base64.StdEncoding.EncodeToString([]byte(ud)), - SSHKeys: mgr.getNodePoolDefinition(nodegroup).sshKeyIDs, - Tags: &map[string]string{"k8s-cluster": mgr.getNodePoolDefinition(nodegroup).clusterName, "k8s-nodepool": nodegroup}, + Hostname: hn, + Region: mgr.getNodePoolDefinition(nodegroup).region, + PlanID: mgr.getNodePoolDefinition(nodegroup).plan, + Image: mgr.getNodePoolDefinition(nodegroup).os, + ProjectID: mgr.getNodePoolDefinition(nodegroup).projectID, + UserData: base64.StdEncoding.EncodeToString([]byte(ud)), + SSHKeys: mgr.getNodePoolDefinition(nodegroup).sshKeyIDs, + Tags: &map[string]string{"k8s-cluster": mgr.getNodePoolDefinition(nodegroup).clusterName, "k8s-nodepool": nodegroup}, + OSPartitionSize: mgr.getNodePoolDefinition(nodegroup).osPartitionSize, } if err := mgr.createServerRequest(ctx, cr, nodegroup); err != nil { diff --git a/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go b/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go index f0875bc341aa..db5cc8344dc0 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go +++ b/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go @@ -251,14 +251,15 @@ type IPAddressCreateRequest struct { // CreateServer represents a request to create a new Cherry Servers server. Used by createNodes type CreateServer struct { - ProjectID int `json:"project_id,omitempty"` - PlanID int `json:"plan_id,omitempty"` - Hostname string `json:"hostname,omitempty"` - Image string `json:"image,omitempty"` - Region string `json:"region,omitempty"` - SSHKeys []int `json:"ssh_keys"` - IPAddresses []string `json:"ip_addresses"` - UserData string `json:"user_data,omitempty"` - Tags *map[string]string `json:"tags,omitempty"` - SpotInstance int `json:"spot_market,omitempty"` + ProjectID int `json:"project_id,omitempty"` + PlanID int `json:"plan_id,omitempty"` + Hostname string `json:"hostname,omitempty"` + Image string `json:"image,omitempty"` + Region string `json:"region,omitempty"` + SSHKeys []int `json:"ssh_keys"` + IPAddresses []string `json:"ip_addresses"` + UserData string `json:"user_data,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + SpotInstance int `json:"spot_market,omitempty"` + OSPartitionSize int `json:"os_partition_size,omitempty"` } From a35024e0590321b62dd779a5a1540456cae6284f Mon Sep 17 00:00:00 2001 From: Andrius521 Date: Mon, 6 Jun 2022 16:56:32 +0300 Subject: [PATCH 2/2] Add support for passing os partition size when creating nodes --- .../cloudprovider/cherryservers/README.md | 1 + .../cherryservers/cherry_manager_rest.go | 20 +++++++++++------- .../cherryservers/cherry_types.go | 21 ++++++++++--------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/cherryservers/README.md b/cluster-autoscaler/cloudprovider/cherryservers/README.md index 786a8bdc9dff..70cfd5a6a071 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/README.md +++ b/cluster-autoscaler/cloudprovider/cherryservers/README.md @@ -29,6 +29,7 @@ In the above file you can modify the following fields: | cluster-autoscaler-cloud-config | Global/cloudinit | The base64 encoded user data submitted when provisioning servers. In the example file, the default value has been tested with Ubuntu 18.04 to install Docker & kubelet and then to bootstrap the node into the cluster using kubeadm. The kubeadm, kubelet, kubectl are pinned to version 1.17.4. For a different base OS or bootstrap method, this needs to be customized accordingly. It will use go templates to inject runtime information; see below.| | cluster-autoscaler-cloud-config | Global/reservation | The values "require" or "prefer" will request the next available hardware reservation for new servers in selected region & plan. If no hardware reservations match, "require" will trigger a failure, while "prefer" will launch on-demand servers instead (default: none) | | cluster-autoscaler-cloud-config | Global/hostname-pattern | The pattern for the names of new Cherry Servers servers (default: "k8s-{{.ClusterName}}-{{.NodeGroup}}-{{.RandString8}}" ) | +| cluster-autoscaler-cloud-config | Global/os-partition-size | The OS partition size in gigabytes for new nodes in the nodepoll (eg: `60`) | You can always update the secret with more nodepool definitions (with different plans etc.) as shown in the example, but you should always provide a default nodepool configuration. diff --git a/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go b/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go index 98789927b91c..3c8c000aee7c 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go +++ b/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go @@ -72,6 +72,7 @@ type cherryManagerNodePool struct { cloudinit string hostnamePattern string sshKeyIDs []int + osPartitionSize int waitTimeStep time.Duration } @@ -94,6 +95,7 @@ type ConfigNodepool struct { SSHKeys []string `gcfg:"ssh-key-ids"` CloudInit string `gcfg:"cloudinit"` HostnamePattern string `gcfg:"hostname-pattern"` + OsPartitionSize int `gcfg:"os-partition-size"` } // IsEmpty determine if this is an empty config @@ -235,6 +237,7 @@ func createCherryManagerRest(configReader io.Reader, discoverOpts cloudprovider. cloudinit: nodepool.CloudInit, sshKeyIDs: sshKeyIDs, hostnamePattern: nodepool.HostnamePattern, + osPartitionSize: nodepool.OsPartitionSize, } } @@ -427,14 +430,15 @@ func (mgr *cherryManagerRest) createNode(ctx context.Context, cloudinit, nodegro return fmt.Errorf("failed to create hostname from template: %w", err) } cr := &CreateServer{ - Hostname: hn, - Region: mgr.getNodePoolDefinition(nodegroup).region, - PlanID: mgr.getNodePoolDefinition(nodegroup).plan, - Image: mgr.getNodePoolDefinition(nodegroup).os, - ProjectID: mgr.getNodePoolDefinition(nodegroup).projectID, - UserData: base64.StdEncoding.EncodeToString([]byte(ud)), - SSHKeys: mgr.getNodePoolDefinition(nodegroup).sshKeyIDs, - Tags: &map[string]string{"k8s-cluster": mgr.getNodePoolDefinition(nodegroup).clusterName, "k8s-nodepool": nodegroup}, + Hostname: hn, + Region: mgr.getNodePoolDefinition(nodegroup).region, + PlanID: mgr.getNodePoolDefinition(nodegroup).plan, + Image: mgr.getNodePoolDefinition(nodegroup).os, + ProjectID: mgr.getNodePoolDefinition(nodegroup).projectID, + UserData: base64.StdEncoding.EncodeToString([]byte(ud)), + SSHKeys: mgr.getNodePoolDefinition(nodegroup).sshKeyIDs, + Tags: &map[string]string{"k8s-cluster": mgr.getNodePoolDefinition(nodegroup).clusterName, "k8s-nodepool": nodegroup}, + OSPartitionSize: mgr.getNodePoolDefinition(nodegroup).osPartitionSize, } if err := mgr.createServerRequest(ctx, cr, nodegroup); err != nil { diff --git a/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go b/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go index f0875bc341aa..db5cc8344dc0 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go +++ b/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go @@ -251,14 +251,15 @@ type IPAddressCreateRequest struct { // CreateServer represents a request to create a new Cherry Servers server. Used by createNodes type CreateServer struct { - ProjectID int `json:"project_id,omitempty"` - PlanID int `json:"plan_id,omitempty"` - Hostname string `json:"hostname,omitempty"` - Image string `json:"image,omitempty"` - Region string `json:"region,omitempty"` - SSHKeys []int `json:"ssh_keys"` - IPAddresses []string `json:"ip_addresses"` - UserData string `json:"user_data,omitempty"` - Tags *map[string]string `json:"tags,omitempty"` - SpotInstance int `json:"spot_market,omitempty"` + ProjectID int `json:"project_id,omitempty"` + PlanID int `json:"plan_id,omitempty"` + Hostname string `json:"hostname,omitempty"` + Image string `json:"image,omitempty"` + Region string `json:"region,omitempty"` + SSHKeys []int `json:"ssh_keys"` + IPAddresses []string `json:"ip_addresses"` + UserData string `json:"user_data,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + SpotInstance int `json:"spot_market,omitempty"` + OSPartitionSize int `json:"os_partition_size,omitempty"` }