Skip to content

Commit aca21d2

Browse files
authored
Merge pull request #75 from sp-yduck/feature/cloud-init-ssh
fix #73 #74
2 parents 618878a + 168ba64 commit aca21d2

File tree

8 files changed

+233
-55
lines changed

8 files changed

+233
-55
lines changed

api/v1beta1/cloudinit_types.go

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,59 @@
11
package v1beta1
22

3-
// CloudInit is passed through raw yaml file not Proxmox API
4-
// so you can configure more detailed configs
3+
// CloudInit is passed to disk directly as raw yaml file
4+
// not via Proxmox API so you can configure more detailed configs
55
type CloudInit struct {
66
User *User `json:"user,omitempty"`
77
}
88

99
type User struct {
10-
GrowPart GrowPart `yaml:"growpart,omitempty" json:"-"`
11-
HostName string `yaml:"hostname,omitempty" json:"-"`
12-
ManageEtcHosts bool `yaml:"manage_etc_hosts,omitempty" json:"-"`
13-
User string `yaml:"user,omitempty" json:"user,omitempty"`
14-
ChPasswd ChPasswd `yaml:"chpasswd,omitempty" json:"-"`
15-
Users []string `yaml:"users,omitempty" json:"-"`
16-
Password string `yaml:"password,omitempty" json:"password,omitempty"`
17-
Packages []string `yaml:"packages,omitempty" json:"packages,omitempty"`
18-
PackageUpgrade bool `yaml:"package_upgrade,omitempty" json:"-"`
19-
WriteFiles []WriteFiles `yaml:"write_files,omitempty" json:"writeFiles,omitempty"`
20-
RunCmd []string `yaml:"runcmd,omitempty" json:"runCmd,omitempty"`
10+
BootCmd []string `yaml:"bootcmd,omitempty" json:"bootcmd,omitempty"`
11+
CACerts CACert `yaml:"ca_certs,omitempty" json:"ca_certs,omitempty"`
12+
ChPasswd ChPasswd `yaml:"chpasswd,omitempty" json:"chpasswd,omitempty"`
13+
HostName string `yaml:"hostname,omitempty" json:"-"`
14+
ManageEtcHosts bool `yaml:"manage_etc_hosts,omitempty" json:"manage_etc_hosts,omitempty"`
15+
NoSSHFingerprints bool `yaml:"no_ssh_fingerprints,omitempty" json:"no_ssh_fingerprints,omitempty"`
16+
Packages []string `yaml:"packages,omitempty" json:"packages,omitempty"`
17+
PackageUpdate bool `yaml:"package_update,omitempty" json:"package_update,omitempty"`
18+
PackageUpgrade bool `yaml:"package_upgrade,omitempty" json:"package_upgrade,omitempty"`
19+
Password string `yaml:"password,omitempty" json:"password,omitempty"`
20+
RunCmd []string `yaml:"runcmd,omitempty" json:"runCmd,omitempty"`
21+
SSH SSH `yaml:"ssh,omitempty" json:"ssh,omitempty"`
22+
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty" json:"ssh_authorized_keys,omitempty"`
23+
SSHKeys SSHKeys `yaml:"ssh_keys,omitempty" json:"ssh_keys,omitempty"`
24+
SSHPWAuth bool `yaml:"ssh_pwauth,omitempty" json:"ssh_pwauth,omitempty"`
25+
User string `yaml:"user,omitempty" json:"user,omitempty"`
26+
Users []string `yaml:"users,omitempty" json:"-"`
27+
WriteFiles []WriteFiles `yaml:"write_files,omitempty" json:"writeFiles,omitempty"`
2128
}
2229

23-
type GrowPart struct {
24-
Mode string `yaml:"mode,omitempty" json:"-"`
25-
Devices []string `yaml:"devices,omitempty" json:"-"`
26-
IgnoreGrowrootDisabled bool `yaml:"ignore_growroot_disabled,omitempty" json:"-"`
30+
type CACert struct {
31+
RemoveDefaults bool `yaml:"remove_defaults,omitempty" json:"remove_defaults,omitempty"`
32+
Trusted []string `yaml:"trusted,omitempty" json:"trusted,omitempty"`
2733
}
2834

2935
type ChPasswd struct {
30-
Expire string `yaml:"expire,omitempty" json:"-"`
36+
Expire string `yaml:"expire,omitempty" json:"expire,omitempty"`
37+
}
38+
39+
type SSH struct {
40+
EmitKeysToConsole bool `yaml:"emit_keys_to_console,omitempty" json:"emit_keys_to_console,omitempty"`
41+
}
42+
43+
type SSHKeys struct {
44+
RSAPrivate string `yaml:"rsa_private,omitempty" json:"rsa_private,omitempty"`
45+
RSAPublic string `yaml:"rsa_public,omitempty" json:"rsa_public,omitempty"`
46+
DSAPrivate string `yaml:"dsa_private,omitempty" json:"dsa_private,omitempty"`
47+
DSAPublic string `yaml:"dsa_public,omitempty" json:"dsa_public,omitempty"`
48+
ECDSAPrivate string `yaml:"ecdsa_private,omitempty" json:"ecdsa_private,omitempty"`
49+
EDSCAPublic string `yaml:"ecdsa_public,omitempty" json:"ecdsa_public,omitempty"`
3150
}
3251

3352
type WriteFiles struct {
53+
Encoding string `yaml:"encoding,omitempty" json:"encoding,omitempty"`
3454
Path string `yaml:"path,omitempty" json:"path,omitempty"`
3555
Owner string `yaml:"owner,omitempty" json:"owner,omitempty"`
3656
Permissions string `yaml:"permissions,omitempty" json:"permissions,omitempty"`
57+
Defer bool `yaml:"defer,omitempty" json:"defer,omitempty"`
3758
Content string `yaml:"content,omitempty" json:"content,omitempty"`
3859
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 71 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/providerid/providerid_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestNew(t *testing.T) {
1313

1414
uuid = "asdf"
1515
providerID, err = New(uuid)
16-
if err != nil {
16+
if err != nil || providerID.String() != "proxmox://asdf" {
1717
t.Errorf("failed to create providerID: %v", err)
1818
}
1919
}

cloud/scope/clients_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ var _ = Describe("newComputeService", func() {
5656
secret := &corev1.Secret{}
5757
secret.SetNamespace("default")
5858
secret.SetName("foo")
59-
k8sClient.Create(context.TODO(), secret)
59+
err := k8sClient.Create(context.TODO(), secret)
60+
Expect(err).To(BeNil())
6061
})
6162

6263
It("Should return proper error", func() {

cloud/scope/suite_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ import (
2020
)
2121

2222
var (
23-
cfg *rest.Config
24-
k8sClient client.Client
25-
testEnv *envtest.Environment
26-
proxmoxUser string
27-
proxmoxPassword string
23+
cfg *rest.Config
24+
k8sClient client.Client
25+
testEnv *envtest.Environment
2826
)
2927

3028
func TestScopes(t *testing.T) {

cloud/services/compute/instance/image.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ func (s *Service) setCloudImage(ctx context.Context) error {
5555
// download image
5656
ok, _ := isChecksumOK(vnc, image, rawImageFilePath)
5757
if !ok { // if checksum is ok, it means the image is already there. skip installing
58+
out, _, err := vnc.Exec(ctx, fmt.Sprintf("mkdir -p %s && mkdir -p %s", etcCAPPX, rawImageDirPath))
59+
if err != nil {
60+
return errors.Errorf("failed to create dir %s: %s : %v", rawImageDirPath, out, err)
61+
}
5862
log.Info("downloading node image. this will take few mins.")
59-
out, _, err := vnc.Exec(ctx, fmt.Sprintf("wget %s -O %s", image.URL, rawImageFilePath))
63+
out, _, err = vnc.Exec(ctx, fmt.Sprintf("wget %s -O %s", image.URL, rawImageFilePath))
6064
if err != nil {
6165
return errors.Errorf("failed to download image: %s : %v", out, err)
6266
}

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@ spec:
6565
properties:
6666
user:
6767
properties:
68+
bootcmd:
69+
items:
70+
type: string
71+
type: array
72+
ca_certs:
73+
properties:
74+
remove_defaults:
75+
type: boolean
76+
trusted:
77+
items:
78+
type: string
79+
type: array
80+
type: object
81+
chpasswd:
82+
properties:
83+
expire:
84+
type: string
85+
type: object
86+
manage_etc_hosts:
87+
type: boolean
88+
no_ssh_fingerprints:
89+
type: boolean
90+
package_update:
91+
type: boolean
92+
package_upgrade:
93+
type: boolean
6894
packages:
6995
items:
7096
type: string
@@ -75,13 +101,43 @@ spec:
75101
items:
76102
type: string
77103
type: array
104+
ssh:
105+
properties:
106+
emit_keys_to_console:
107+
type: boolean
108+
type: object
109+
ssh_authorized_keys:
110+
items:
111+
type: string
112+
type: array
113+
ssh_keys:
114+
properties:
115+
dsa_private:
116+
type: string
117+
dsa_public:
118+
type: string
119+
ecdsa_private:
120+
type: string
121+
ecdsa_public:
122+
type: string
123+
rsa_private:
124+
type: string
125+
rsa_public:
126+
type: string
127+
type: object
128+
ssh_pwauth:
129+
type: boolean
78130
user:
79131
type: string
80132
writeFiles:
81133
items:
82134
properties:
83135
content:
84136
type: string
137+
defer:
138+
type: boolean
139+
encoding:
140+
type: string
85141
owner:
86142
type: string
87143
path:

0 commit comments

Comments
 (0)