Skip to content

Commit 6413f92

Browse files
committed
fix #13 : delete snippets
1 parent d6f4290 commit 6413f92

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

cloud/services/compute/instance/cloudinit.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ func reconcileCloudInit(s *Service, vmid int, bootstrap string) error {
2424
return nil
2525
}
2626

27+
// delete CloudConfig
28+
func (s *Service) deleteCloudConfig() error {
29+
storageName := s.scope.GetStorage().Name
30+
volumeID := fmt.Sprintf("%s:snippets/%s-user.yml", storageName, s.scope.Name())
31+
32+
node, err := s.client.Node(s.scope.NodeName())
33+
if err != nil {
34+
return err
35+
}
36+
storage, err := node.Storage(storageName)
37+
if err != nil {
38+
return err
39+
}
40+
content, err := storage.GetContent(volumeID)
41+
if IsNotFound(err) { // return nil if it's already deleted
42+
return nil
43+
}
44+
if err != nil {
45+
return err
46+
}
47+
48+
return content.DeleteVolume()
49+
}
50+
2751
func reconcileCloudInitUser(vmid int, vmName, storageName, bootstrap string, config infrav1.User, ssh scope.SSHClient) error {
2852
base := baseUserData(vmName)
2953

cloud/services/compute/instance/reconcile.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ func (s *Service) Delete(ctx context.Context) error {
6161
if err := EnsureStoppedOrPaused(*instance); err != nil {
6262
return err
6363
}
64+
65+
// delete cloud-config file
66+
if err := s.deleteCloudConfig(); err != nil {
67+
return err
68+
}
69+
70+
// delete qemu
6471
return instance.Delete()
6572
}
6673

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ require (
77
github.com/onsi/ginkgo/v2 v2.9.2
88
github.com/onsi/gomega v1.27.5
99
github.com/pkg/errors v0.9.1
10-
github.com/sp-yduck/proxmox v0.0.0-20230627144956-64b565d07db7
10+
github.com/sp-yduck/proxmox v0.0.0-20230702124708-d086ca37fd8f
1111
golang.org/x/crypto v0.9.0
1212
gopkg.in/yaml.v3 v3.0.1
1313
k8s.io/api v0.26.1
1414
k8s.io/apimachinery v0.26.1
1515
k8s.io/client-go v0.26.1
16+
k8s.io/klog/v2 v2.80.1
1617
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
1718
sigs.k8s.io/cluster-api v1.4.1
1819
sigs.k8s.io/controller-runtime v0.14.5
@@ -72,7 +73,6 @@ require (
7273
gopkg.in/yaml.v2 v2.4.0 // indirect
7374
k8s.io/apiextensions-apiserver v0.26.1 // indirect
7475
k8s.io/component-base v0.26.1 // indirect
75-
k8s.io/klog/v2 v2.80.1 // indirect
7676
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
7777
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
7878
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5g
288288
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
289289
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
290290
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
291-
github.com/sp-yduck/proxmox v0.0.0-20230627144956-64b565d07db7 h1:y2VI0xIOh35Dl3vKdbns6TVwe6ReSw4Akyr5qUVyUWU=
292-
github.com/sp-yduck/proxmox v0.0.0-20230627144956-64b565d07db7/go.mod h1:VIKtGZXlx0nO9Y+K2vJ4z3rJLkZ3v0OvTnKbO22EnL4=
291+
github.com/sp-yduck/proxmox v0.0.0-20230702124708-d086ca37fd8f h1:n32eSWqWLtjk+jb4B1Ok+W5KoAxuYuouEkXjumqySXI=
292+
github.com/sp-yduck/proxmox v0.0.0-20230702124708-d086ca37fd8f/go.mod h1:VIKtGZXlx0nO9Y+K2vJ4z3rJLkZ3v0OvTnKbO22EnL4=
293293
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
294294
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
295295
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=

0 commit comments

Comments
 (0)