From 902d7e5f7571bc1b70fb8be2a42b0dcc38a4a4d7 Mon Sep 17 00:00:00 2001 From: Andrius521 Date: Mon, 20 Jun 2022 15:34:03 +0300 Subject: [PATCH] Node groups plan and region define via slug --- .../cloudprovider/cherryservers/README.md | 9 ++++---- .../cherryservers/cherry_manager_rest.go | 22 ++++++++----------- .../cherryservers/cherry_manager_rest_test.go | 8 +++---- .../cherryservers/cherry_node_group_test.go | 6 ++--- .../cherryservers/cherry_types.go | 4 +++- .../examples/cluster-autoscaler-secret.yaml | 8 +++---- 6 files changed, 27 insertions(+), 30 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/cherryservers/README.md b/cluster-autoscaler/cloudprovider/cherryservers/README.md index 5fcd2fa65b56..d4361a9f4cee 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/README.md +++ b/cluster-autoscaler/cloudprovider/cherryservers/README.md @@ -23,11 +23,10 @@ In the above file you can modify the following fields: | cluster-autoscaler-cherry | authtoken | Your Cherry Servers API token. It must be base64 encoded. | | cluster-autoscaler-cloud-config | Global/project-id | Your Cherry Servers project id | | cluster-autoscaler-cloud-config | Global/api-server | The ip:port for you cluster's k8s api (e.g. K8S_MASTER_PUBLIC_IP:6443) | -| cluster-autoscaler-cloud-config | Global/region | The Cherry Servers region for the servers in your nodepool (eg: EU-Nord-1) | -| cluster-autoscaler-cloud-config | Global/plan | The Cherry Servers plan ID for new nodes in the nodepool (eg: `103`) | -| cluster-autoscaler-cloud-config | Global/os | The OS image to use for new nodes, e.g. `CentOS 6 64bit`. If you change this also update cloudinit. | +| cluster-autoscaler-cloud-config | Global/region | The Cherry Servers region slug for the servers in your nodepool (eg: `eu_nord_1`) | +| cluster-autoscaler-cloud-config | Global/plan | The Cherry Servers plan slug for new nodes in the nodepool (eg: `e5_1620v4`) | +| cluster-autoscaler-cloud-config | Global/os | The OS image slug to use for new nodes, e.g. `ubuntu_18_04`. If you change this also update cloudinit. | | 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 nodepool (eg: `60`, default: `none`) | @@ -92,7 +91,7 @@ affinity: - key: beta.kubernetes.io/instance-type operator: In values: - - 103 + - e5_1620v4 ``` ## CCM and Controller node labels diff --git a/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go b/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go index 3c8c000aee7c..95c66bb7b44f 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go +++ b/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest.go @@ -67,7 +67,7 @@ type cherryManagerNodePool struct { projectID int apiServerEndpoint string region string - plan int + plan string os string cloudinit string hostnamePattern string @@ -80,7 +80,7 @@ type cherryManagerRest struct { authToken string baseURL *url.URL nodePools map[string]*cherryManagerNodePool - plans map[int]*Plan + plans map[string]*Plan planUpdate time.Time } @@ -215,10 +215,6 @@ func createCherryManagerRest(configReader io.Reader, discoverOpts cloudprovider. nodepool.ClusterName = opts.ClusterName } - plan, err := strconv.ParseInt(nodepool.Plan, 10, 32) - if err != nil { - return nil, fmt.Errorf("invalid plan %s for nodepool %s, must be integer: %v", nodepool.Plan, key, err) - } var sshKeyIDs []int for i, keyIDString := range nodepool.SSHKeys { keyID, err := strconv.ParseInt(keyIDString, 10, 32) @@ -232,7 +228,7 @@ func createCherryManagerRest(configReader io.Reader, discoverOpts cloudprovider. apiServerEndpoint: apiServerEndpoint, clusterName: nodepool.ClusterName, region: nodepool.Region, - plan: int(plan), + plan: nodepool.Plan, os: nodepool.OS, cloudinit: nodepool.CloudInit, sshKeyIDs: sshKeyIDs, @@ -432,7 +428,7 @@ func (mgr *cherryManagerRest) createNode(ctx context.Context, cloudinit, nodegro cr := &CreateServer{ Hostname: hn, Region: mgr.getNodePoolDefinition(nodegroup).region, - PlanID: mgr.getNodePoolDefinition(nodegroup).plan, + Plan: mgr.getNodePoolDefinition(nodegroup).plan, Image: mgr.getNodePoolDefinition(nodegroup).os, ProjectID: mgr.getNodePoolDefinition(nodegroup).projectID, UserData: base64.StdEncoding.EncodeToString([]byte(ud)), @@ -642,15 +638,15 @@ func (mgr *cherryManagerRest) templateNodeInfo(nodegroup string) (*schedulerfram if err != nil { return nil, fmt.Errorf("unable to update cherry plans: %v", err) } - mgr.plans = map[int]*Plan{} + mgr.plans = map[string]*Plan{} for _, plan := range plans { - mgr.plans[plan.ID] = &plan + mgr.plans[plan.Slug] = &plan } } - planID := mgr.getNodePoolDefinition(nodegroup).plan - cherryPlan, ok := mgr.plans[planID] + planSlug := mgr.getNodePoolDefinition(nodegroup).plan + cherryPlan, ok := mgr.plans[planSlug] if !ok { - klog.V(5).Infof("no plan found for planID %d", planID) + klog.V(5).Infof("no plan found for planSlug %s", planSlug) return nil, fmt.Errorf("cherry plan %q not supported", mgr.getNodePoolDefinition(nodegroup).plan) } var ( diff --git a/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest_test.go b/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest_test.go index 6c160b60a4eb..f3015f1b1261 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest_test.go +++ b/cluster-autoscaler/cloudprovider/cherryservers/cherry_manager_rest_test.go @@ -70,8 +70,8 @@ func newTestCherryManagerRest(t *testing.T, serverUrl string) *cherryManagerRest clusterName: "cluster2", projectID: 10001, apiServerEndpoint: "147.75.102.15:6443", - region: "EU-Nord-1", - plan: 116, + region: "eu_nord_1", + plan: "e5_1620v4", os: "ubuntu_18_04", cloudinit: cloudinitDefault, hostnamePattern: "k8s-{{.ClusterName}}-{{.NodeGroup}}-{{.RandString8}}", @@ -80,8 +80,8 @@ func newTestCherryManagerRest(t *testing.T, serverUrl string) *cherryManagerRest clusterName: "cluster2", projectID: 10001, apiServerEndpoint: "147.75.102.15:6443", - region: "EU-Nord-1", - plan: 116, + region: "eu_nord_1", + plan: "e5_1620v4", os: "ubuntu_18_04", cloudinit: cloudinitDefault, hostnamePattern: "k8s-{{.ClusterName}}-{{.NodeGroup}}-{{.RandString8}}", diff --git a/cluster-autoscaler/cloudprovider/cherryservers/cherry_node_group_test.go b/cluster-autoscaler/cloudprovider/cherryservers/cherry_node_group_test.go index f36f6fbdce05..c20f29086339 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/cherry_node_group_test.go +++ b/cluster-autoscaler/cloudprovider/cherryservers/cherry_node_group_test.go @@ -80,11 +80,11 @@ func TestIncreaseDecreaseSize(t *testing.T) { w.Write([]byte(`{"error": "invalid body"}`)) return } - planID := createRequest.PlanID + planSlug := createRequest.Plan if err != nil { w.Header().Set("Content-Type", "application/json") w.WriteHeader(400) - w.Write([]byte(`{"error": "invalid plan ID"}`)) + w.Write([]byte(`{"error": "invalid plan slug"}`)) return } if createRequest.ProjectID != m.nodePools["default"].projectID { @@ -104,7 +104,7 @@ func TestIncreaseDecreaseSize(t *testing.T) { ID: rand.Intn(10000), Name: createRequest.Hostname, Hostname: createRequest.Hostname, - Plan: Plan{ID: planID}, + Plan: Plan{Slug: planSlug}, Project: Project{ID: projectID}, Image: createRequest.Image, Tags: *createRequest.Tags, diff --git a/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go b/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go index db5cc8344dc0..3649414fac45 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go +++ b/cluster-autoscaler/cloudprovider/cherryservers/cherry_types.go @@ -49,6 +49,7 @@ type Project struct { // Region a CherryServers region type Region struct { ID int `json:"id,omitempty"` + Slug string `json:"slug,omitempty"` Name string `json:"name,omitempty"` RegionIso2 string `json:"region_iso_2,omitempty"` BGP RegionBGP `json:"bgp,omitempty"` @@ -70,6 +71,7 @@ type ProjectBGP struct { // Plan a server plan type Plan struct { ID int `json:"id,omitempty"` + Slug string `json:"slug,omitempty"` Name string `json:"name,omitempty"` Custom bool `json:"custom,omitempty"` Specs Specs `json:"specs,omitempty"` @@ -252,7 +254,7 @@ 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"` + Plan string `json:"plan,omitempty"` Hostname string `json:"hostname,omitempty"` Image string `json:"image,omitempty"` Region string `json:"region,omitempty"` diff --git a/cluster-autoscaler/cloudprovider/cherryservers/examples/cluster-autoscaler-secret.yaml b/cluster-autoscaler/cloudprovider/cherryservers/examples/cluster-autoscaler-secret.yaml index 49d52be6251b..2167c8126f1c 100644 --- a/cluster-autoscaler/cloudprovider/cherryservers/examples/cluster-autoscaler-secret.yaml +++ b/cluster-autoscaler/cloudprovider/cherryservers/examples/cluster-autoscaler-secret.yaml @@ -23,18 +23,18 @@ stringData: [nodegroupdef "default"] project-id=YOUR_CHERRYSERVERS_PROJECT_ID api-server-endpoint=YOUR_KUBERNETES_API_IP_ADDRESS:YOUR_KUBERNETES_API_PORT - region=EU-Nord-1 + region=eu_nord_1 os=ubuntu_18_04 - plan=113 + plan=e5_1620v4 cloudinit=IyEvYmluL2Jhc2gKc2V0IC14CmV4cG9ydCBERUJJQU5fRlJPTlRFTkQ9bm9uaW50ZXJhY3RpdmUKZXhwb3J0IEs4U19WRVJTSU9OPTEuMjMuMQphcHQtZ2V0IHVwZGF0ZSAmJiBhcHQtZ2V0IGluc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c3RhbGwgLXkgZG9ja2VyLWNlPTE4LjA2LjJ+Y2V+My0wfnVidW50dQpjYXQgPiAvZXRjL2RvY2tlci9kYWVtb24uanNvbiA8PEVPRgp7CiAgImV4ZWMtb3B0cyI6IFsibmF0aXZlLmNncm91cGRyaXZlcj1zeXN0ZW1kIl0sCiAgImxvZy1kcml2ZXIiOiAianNvbi1maWxlIiwKICAibG9nLW9wdHMiOiB7CiAgICAibWF4LXNpemUiOiAiMTAwbSIKICB9LAogICJzdG9yYWdlLWRyaXZlciI6ICJvdmVybGF5MiIKfQpFT0YKbWtkaXIgLXAgL2V0Yy9zeXN0ZW1kL3N5c3RlbS9kb2NrZXIuc2VydmljZS5kCnN5c3RlbWN0bCBkYWVtb24tcmVsb2FkCnN5c3RlbWN0bCByZXN0YXJ0IGRvY2tlcgpzd2Fwb2ZmIC1hCm12IC9ldGMvZnN0YWIgL2V0Yy9mc3RhYi5vbGQgJiYgZ3JlcCAtdiBzd2FwIC9ldGMvZnN0YWIub2xkID4gL2V0Yy9mc3RhYgpjYXQgPDxFT0YgfCB0ZWUgL2V0Yy9kZWZhdWx0L2t1YmVsZXQKS1VCRUxFVF9FWFRSQV9BUkdTPS0tY2xvdWQtcHJvdmlkZXI9ZXh0ZXJuYWwKRU9GCmt1YmVhZG0gam9pbiAtLWRpc2NvdmVyeS10b2tlbi11bnNhZmUtc2tpcC1jYS12ZXJpZmljYXRpb24gLS10b2tlbiB7ey5Cb290c3RyYXBUb2tlbklEfX0ue3suQm9vdHN0cmFwVG9rZW5TZWNyZXR9fSB7ey5BUElTZXJ2ZXJFbmRwb2ludH19Cg== hostname-pattern=k8s-{{.ClusterName}}-{{.NodeGroup}}-{{.RandString8}} [nodegroupdef "pool2"] project-id=YOUR_CHERRYSERVERS_PROJECT_ID api-server-endpoint=YOUR_KUBERNETES_API_IP_ADDRESS:YOUR_KUBERNETES_API_PORT - region=EU-Nord-1 + region=eu_nord_1 os=ubuntu_18_04 - plan=113 + plan=e5_1620v4 clo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