Skip to content

Commit

Permalink
Pass user ssh keys to VMs
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyanr committed Aug 26, 2020
1 parent b7bba4e commit 7c12b1b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions charts/internal/machine-class/templates/machine-class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ providerSpec:
{{- if $machineClass.memory }}
memory: "{{ $machineClass.memory }}"
{{ end }}
sshKeys:
{{ toYaml $machineClass.sshKeys | indent 4 }}
secretRef:
name: "{{ $machineClass.name }}"
namespace: "{{ $.Release.Namespace }}"
Expand Down
16 changes: 9 additions & 7 deletions charts/internal/machine-class/values.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
machineClasses:
- name: class-1
secret:
cloudConfig: abc
kubeconfig: abc
tags:
- kubernetes.io/cluster/foo
- kubernetes.io/role/node
storageClassName: standard
pvcSize: "10Gi"
sourceURL: source-image-url
cpus: "1"
memory: "4096M"
memory: "4096M"
sshKeys:
- "ssh-rsa AAAAB3..."
tags:
- kubernetes.io/cluster/foo
- kubernetes.io/role/node
secret:
cloudConfig: abc
kubeconfig: abc
5 changes: 5 additions & 0 deletions pkg/controller/worker/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error {
return err
}

if len(w.worker.Spec.SSHPublicKey) == 0 {
return fmt.Errorf("missing sshPublicKey in worker")
}

for _, pool := range w.worker.Spec.Pools {
// hardcoded for now as we don't support zones yet
zoneIdx := int32(0)
Expand Down Expand Up @@ -109,6 +113,7 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error {
"sourceURL": imageSourceURL,
"cpus": machineType.CPU,
"memory": machineType.Memory,
"sshKeys": []string{string(w.worker.Spec.SSHPublicKey)},
"tags": map[string]string{
"mcm.gardener.cloud/cluster": w.worker.Namespace,
"mcm.gardener.cloud/role": "node",
Expand Down
8 changes: 6 additions & 2 deletions pkg/controller/worker/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var _ = Describe("Machines", func() {
shootVersion := "1.2.3"
cloudProfileName := "test-profile"
ubuntuSourceURL := "https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img"
sshPublicKey := []byte("ssh-rsa AAAAB3...")

images := []apiv1alpha1.MachineImages{
{
Expand Down Expand Up @@ -164,7 +165,7 @@ var _ = Describe("Machines", func() {
Zones: []string{},
},
},
SSHPublicKey: []byte{},
SSHPublicKey: sshPublicKey,
},
}

Expand Down Expand Up @@ -210,6 +211,7 @@ var _ = Describe("Machines", func() {
"8Gi",
"2",
"4096Mi",
sshPublicKey,
)

machineClass2 := generateMachineClass(
Expand All @@ -218,6 +220,7 @@ var _ = Describe("Machines", func() {
"8Gi",
"300m",
"8192Mi",
sshPublicKey,
)

chartApplier.
Expand Down Expand Up @@ -353,7 +356,7 @@ func generateKubeVirtSecret(c *mockclient.MockClient) {
})
}

func generateMachineClass(classTemplate map[string]interface{}, name, pvcSize, cpu, memory string) map[string]interface{} {
func generateMachineClass(classTemplate map[string]interface{}, name, pvcSize, cpu, memory string, sshPublicKey []byte) map[string]interface{} {
out := make(map[string]interface{})

for k, v := range classTemplate {
Expand All @@ -364,6 +367,7 @@ func generateMachineClass(classTemplate map[string]interface{}, name, pvcSize, c
out["pvcSize"] = resource.MustParse(pvcSize)
out["cpus"] = resource.MustParse(cpu)
out["memory"] = resource.MustParse(memory)
out["sshKeys"] = []string{string(sshPublicKey)}

return out
}
Expand Down

0 comments on commit 7c12b1b

Please sign in to comment.