@@ -11,14 +11,14 @@ import (
1111 "github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scope"
1212)
1313
14- // reconcileCloudInit
15- func reconcileCloudInit (s * Service , vmid int , bootstrap string ) error {
16- vmName := s .scope .Name ()
17- storageName := s .scope .GetStorage ().Name
18- cloudInit := s .scope .GetCloudInit ()
14+ const (
15+ userSnippetPathFormat = "snippets/%s-user.yml"
16+ )
1917
18+ // reconcileCloudInit
19+ func (s * Service ) reconcileCloudInit (bootstrap string ) error {
2020 // user
21- if err := reconcileCloudInitUser (vmid , vmName , storageName , bootstrap , * cloudInit . User , s . remote ); err != nil {
21+ if err := s . reconcileCloudInitUser (bootstrap ); err != nil {
2222 return err
2323 }
2424 return nil
@@ -27,7 +27,8 @@ func reconcileCloudInit(s *Service, vmid int, bootstrap string) error {
2727// delete CloudConfig
2828func (s * Service ) deleteCloudConfig () error {
2929 storageName := s .scope .GetStorage ().Name
30- volumeID := fmt .Sprintf ("%s:snippets/%s-user.yml" , storageName , s .scope .Name ())
30+ path := userSnippetPath (s .scope .Name ())
31+ volumeID := fmt .Sprintf ("%s:%s" , storageName , path )
3132
3233 node , err := s .client .Node (s .scope .NodeName ())
3334 if err != nil {
@@ -48,14 +49,17 @@ func (s *Service) deleteCloudConfig() error {
4849 return content .DeleteVolume ()
4950}
5051
51- func reconcileCloudInitUser (vmid int , vmName , storageName , bootstrap string , config infrav1.User , ssh scope.SSHClient ) error {
52- base := baseUserData (vmName )
52+ func (s * Service ) reconcileCloudInitUser (bootstrap string ) error {
53+ vmName := s .scope .Name ()
54+ storagePath := s .scope .GetStorage ().Path
55+ config := s .scope .GetCloudInit ().User
5356
5457 bootstrapConfig , err := cloudinit .ParseUser (bootstrap )
5558 if err != nil {
5659 return err
5760 }
58- additional , err := cloudinit .MergeUsers (config , base )
61+ base := baseUserData (vmName )
62+ additional , err := cloudinit .MergeUsers (* config , base )
5963 if err != nil {
6064 return err
6165 }
@@ -71,15 +75,18 @@ func reconcileCloudInitUser(vmid int, vmName, storageName, bootstrap string, con
7175 klog .Info (configYaml )
7276
7377 // to do: should be set via API
74- // to do: storage path
75- out , err := ssh .RunWithStdin (fmt .Sprintf ("tee /var/lib/vz/%s/snippets/%s-user.yml" , storageName , vmName ), configYaml )
78+ out , err := s .remote .RunWithStdin (fmt .Sprintf ("tee %s/%s" , storagePath , userSnippetPath (vmName )), configYaml )
7679 if err != nil {
7780 return errors .Errorf ("ssh command error : %s : %v" , out , err )
7881 }
7982
8083 return nil
8184}
8285
86+ func userSnippetPath (vmName string ) string {
87+ return fmt .Sprintf (userSnippetPathFormat , vmName )
88+ }
89+
8390// DEPRECATED : cicustom should be set via API
8491func ApplyCICustom (vmid int , vmName , storageName , ciType string , ssh scope.SSHClient ) error {
8592 if ! cloudinit .IsValidType (ciType ) {
0 commit comments