Skip to content

Commit

Permalink
Merge pull request #4867 from deitch/cherry-support-ssh-keys
Browse files Browse the repository at this point in the history
Cherry support ssh keys
  • Loading branch information
k8s-ci-robot authored May 9, 2022
2 parents 9bca83a + cd35689 commit cff6cde
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type cherryManagerNodePool struct {
os string
cloudinit string
hostnamePattern string
sshKeyIDs []int
waitTimeStep time.Duration
}

Expand All @@ -84,14 +85,20 @@ type cherryManagerRest struct {

// ConfigNodepool options only include the project-id for now
type ConfigNodepool struct {
ClusterName string `gcfg:"cluster-name"`
ProjectID int `gcfg:"project-id"`
APIServerEndpoint string `gcfg:"api-server-endpoint"`
Region string `gcfg:"region"`
Plan string `gcfg:"plan"`
OS string `gcfg:"os"`
CloudInit string `gcfg:"cloudinit"`
HostnamePattern string `gcfg:"hostname-pattern"`
ClusterName string `gcfg:"cluster-name"`
ProjectID int `gcfg:"project-id"`
APIServerEndpoint string `gcfg:"api-server-endpoint"`
Region string `gcfg:"region"`
Plan string `gcfg:"plan"`
OS string `gcfg:"os"`
SSHKeys []string `gcfg:"ssh-key-ids"`
CloudInit string `gcfg:"cloudinit"`
HostnamePattern string `gcfg:"hostname-pattern"`
}

// IsEmpty determine if this is an empty config
func (c ConfigNodepool) IsEmpty() bool {
return c.ClusterName == "" && c.CloudInit == "" && c.Region == "" && c.Plan == "" && c.ProjectID == 0
}

// ConfigFile is used to read and store information from the cloud configuration file
Expand Down Expand Up @@ -179,7 +186,7 @@ func createCherryManagerRest(configReader io.Reader, discoverOpts cloudprovider.
cfg.Nodegroupdef["default"] = &cfg.DefaultNodegroupdef
}

if *cfg.Nodegroupdef["default"] == (ConfigNodepool{}) {
if cfg.Nodegroupdef["default"].IsEmpty() {
klog.Fatalf("No \"default\" or [Global] nodepool definition was found")
}

Expand Down Expand Up @@ -210,6 +217,14 @@ func createCherryManagerRest(configReader io.Reader, discoverOpts cloudprovider.
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)
if err != nil {
return nil, fmt.Errorf("invalid ssh-key ID at position %d: %s; it must be an integer", i, keyIDString)
}
sshKeyIDs = append(sshKeyIDs, int(keyID))
}
manager.nodePools[key] = &cherryManagerNodePool{
projectID: projectID,
apiServerEndpoint: apiServerEndpoint,
Expand All @@ -218,6 +233,7 @@ func createCherryManagerRest(configReader io.Reader, discoverOpts cloudprovider.
plan: int(plan),
os: nodepool.OS,
cloudinit: nodepool.CloudInit,
sshKeyIDs: sshKeyIDs,
hostnamePattern: nodepool.HostnamePattern,
}
}
Expand Down Expand Up @@ -410,14 +426,14 @@ func (mgr *cherryManagerRest) createNode(ctx context.Context, cloudinit, nodegro
if err != nil {
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},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ stringData:
region=EU-Nord-1
os=ubuntu_18_04
plan=113
cloudinit=IyEvYmluL2Jhc2gKZXhwb3J0IERFQklBTl9GUk9OVEVORD1ub25pbnRlcmFjdGl2ZQpleHBvcnQgSzhTX1ZFUlNJT049MS4yMy4xCmFwdC1nZXQgdXBkYXRlICYmIGFwdC1nZXQgaW5zdGFsbCAteSBhcHQtdHJhbnNwb3J0LWh0dHBz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aXZlLmNncm91cGRyaXZlcj1zeXN0ZW1kIl0sCiAgImxvZy1kcml2ZXIiOiAianNvbi1maWxlIiwKICAibG9nLW9wdHMiOiB7CiAgICAibWF4LXNpemUiOiAiMTAwbSIKICB9LAogICJzdG9yYWdlLWRyaXZlciI6ICJvdmVybGF5MiIKfQpFT0YKbWtkaXIgLXAgL2V0Yy9zeXN0ZW1kL3N5c3RlbS9kb2NrZXIuc2VydmljZS5kCnN5c3RlbWN0bCBkYWVtb24tcmVsb2FkCnN5c3RlbWN0bCByZXN0YXJ0IGRvY2tlcgpzd2Fwb2ZmIC1hCm12IC9ldGMvZnN0YWIgL2V0Yy9mc3RhYi5vbGQgJiYgZ3JlcCAtdiBzd2FwIC9ldGMvZnN0YWIub2xkID4gL2V0Yy9mc3RhYgpjYXQgPDxFT0YgfCB0ZWUgL2V0Yy9kZWZhdWx0L2t1YmVsZXQKS1VCRUxFVF9FWFRSQV9BUkdTPS0tY2xvdWQtcHJvdmlkZXI9ZXh0ZXJuYWwKRU9GCmt1YmVhZG0gam9pbiAtLWRpc2NvdmVyeS10b2tlbi11bnNhZmUtc2tpcC1jYS12ZXJpZmljYXRpb24gLS10b2tlbiBuZjhhdGYua3dmczF0MTVwam1oazduNCA5My4xMTUuMjkuNDQ6ODQ0Mwo=
hostname-pattern=k8s-{{.ClusterName}}-{{.NodeGroup}}-{{.RandString8}}
---
# The following secret is only required when using bootstrap tokens in cloudinit
Expand Down

0 comments on commit cff6cde

Please sign in to comment.