@@ -11,27 +11,55 @@ 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
2525}
2626
27- func reconcileCloudInitUser (vmid int , vmName , storageName , bootstrap string , config infrav1.User , ssh scope.SSHClient ) error {
28- base := baseUserData (vmName )
27+ // delete CloudConfig
28+ func (s * Service ) deleteCloudConfig () error {
29+ storageName := s .scope .GetStorage ().Name
30+ path := userSnippetPath (s .scope .Name ())
31+ volumeID := fmt .Sprintf ("%s:%s" , storageName , path )
32+
33+ node , err := s .client .Node (s .scope .NodeName ())
34+ if err != nil {
35+ return err
36+ }
37+ storage , err := node .Storage (storageName )
38+ if err != nil {
39+ return err
40+ }
41+ content , err := storage .GetContent (volumeID )
42+ if IsNotFound (err ) { // return nil if it's already deleted
43+ return nil
44+ }
45+ if err != nil {
46+ return err
47+ }
48+
49+ return content .DeleteVolume ()
50+ }
51+
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
2956
3057 bootstrapConfig , err := cloudinit .ParseUser (bootstrap )
3158 if err != nil {
3259 return err
3360 }
34- additional , err := cloudinit .MergeUsers (config , base )
61+ base := baseUserData (vmName )
62+ additional , err := cloudinit .MergeUsers (* config , base )
3563 if err != nil {
3664 return err
3765 }
@@ -47,15 +75,18 @@ func reconcileCloudInitUser(vmid int, vmName, storageName, bootstrap string, con
4775 klog .Info (configYaml )
4876
4977 // to do: should be set via API
50- // to do: storage path
51- 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 )
5279 if err != nil {
5380 return errors .Errorf ("ssh command error : %s : %v" , out , err )
5481 }
5582
5683 return nil
5784}
5885
86+ func userSnippetPath (vmName string ) string {
87+ return fmt .Sprintf (userSnippetPathFormat , vmName )
88+ }
89+
5990// DEPRECATED : cicustom should be set via API
6091func ApplyCICustom (vmid int , vmName , storageName , ciType string , ssh scope.SSHClient ) error {
6192 if ! cloudinit .IsValidType (ciType ) {
0 commit comments