@@ -11,27 +11,55 @@ import (
11
11
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scope"
12
12
)
13
13
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
+ )
19
17
18
+ // reconcileCloudInit
19
+ func (s * Service ) reconcileCloudInit (bootstrap string ) error {
20
20
// user
21
- if err := reconcileCloudInitUser (vmid , vmName , storageName , bootstrap , * cloudInit . User , s . remote ); err != nil {
21
+ if err := s . reconcileCloudInitUser (bootstrap ); err != nil {
22
22
return err
23
23
}
24
24
return nil
25
25
}
26
26
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
29
56
30
57
bootstrapConfig , err := cloudinit .ParseUser (bootstrap )
31
58
if err != nil {
32
59
return err
33
60
}
34
- additional , err := cloudinit .MergeUsers (config , base )
61
+ base := baseUserData (vmName )
62
+ additional , err := cloudinit .MergeUsers (* config , base )
35
63
if err != nil {
36
64
return err
37
65
}
@@ -47,15 +75,18 @@ func reconcileCloudInitUser(vmid int, vmName, storageName, bootstrap string, con
47
75
klog .Info (configYaml )
48
76
49
77
// 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 )
52
79
if err != nil {
53
80
return errors .Errorf ("ssh command error : %s : %v" , out , err )
54
81
}
55
82
56
83
return nil
57
84
}
58
85
86
+ func userSnippetPath (vmName string ) string {
87
+ return fmt .Sprintf (userSnippetPathFormat , vmName )
88
+ }
89
+
59
90
// DEPRECATED : cicustom should be set via API
60
91
func ApplyCICustom (vmid int , vmName , storageName , ciType string , ssh scope.SSHClient ) error {
61
92
if ! cloudinit .IsValidType (ciType ) {
0 commit comments