Skip to content

Commit 67a0867

Browse files
authored
Merge pull request #31 from sp-yduck/dot-github
update
2 parents 661e963 + e188877 commit 67a0867

File tree

5 files changed

+22
-46
lines changed

5 files changed

+22
-46
lines changed

.github/workflows/golangci-lint.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ jobs:
2020
- name: golangci-lint
2121
uses: golangci/golangci-lint-action@v3.4.0
2222
with:
23-
version: v1.52.2
23+
version: v1.52.2
24+
args: --timeout 5m

cloud/scope/machine.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (m *MachineScope) GetBiosUUID() *string {
147147
if err != nil {
148148
return nil
149149
}
150-
return pointer.StringPtr(parsed.ID())
150+
return pointer.String(parsed.ID())
151151
}
152152

153153
func (m *MachineScope) GetProviderID() string {
@@ -194,7 +194,7 @@ func (m *MachineScope) SetProviderID(uuid string) error {
194194
if err != nil {
195195
return err
196196
}
197-
m.ProxmoxMachine.Spec.ProviderID = pointer.StringPtr(providerid.String())
197+
m.ProxmoxMachine.Spec.ProviderID = pointer.String(providerid.String())
198198
return nil
199199
}
200200

@@ -207,7 +207,7 @@ func (m *MachineScope) SetReady() {
207207
}
208208

209209
func (m *MachineScope) SetFailureMessage(v error) {
210-
m.ProxmoxMachine.Status.FailureMessage = pointer.StringPtr(v.Error())
210+
m.ProxmoxMachine.Status.FailureMessage = pointer.String(v.Error())
211211
}
212212

213213
func (m *MachineScope) SetFailureReason(v capierrors.MachineStatusError) {

cloud/services/compute/instance/qemu.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"fmt"
66
"math/rand"
7-
"net/url"
8-
"strings"
97
"time"
108

119
"github.com/pkg/errors"
@@ -141,12 +139,3 @@ func generateVMOptions(vmName, storageName string, network infrav1.Network, hard
141139
}
142140
return vmoptions
143141
}
144-
145-
// URL encodes the ssh keys
146-
func sshKeyUrlEncode(keys string) (encodedKeys string) {
147-
encodedKeys = url.PathEscape(keys + "\n")
148-
encodedKeys = strings.Replace(encodedKeys, "+", "%2B", -1)
149-
encodedKeys = strings.Replace(encodedKeys, "@", "%40", -1)
150-
encodedKeys = strings.Replace(encodedKeys, "=", "%3D", -1)
151-
return
152-
}

cloud/services/compute/instance/reconcile.go

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"regexp"
7-
"strconv"
87
"strings"
98

109
"github.com/pkg/errors"
@@ -37,7 +36,9 @@ func (s *Service) Reconcile(ctx context.Context) error {
3736
}
3837

3938
log.Info(fmt.Sprintf("Reconciled instance: bios-uuid=%s", *uuid))
40-
s.scope.SetProviderID(*uuid)
39+
if err := s.scope.SetProviderID(*uuid); err != nil {
40+
return err
41+
}
4142
s.scope.SetInstanceStatus(infrav1.InstanceStatus(instance.Status))
4243
// s.scope.SetAddresses()
4344
return nil
@@ -127,7 +128,7 @@ func getBiosUUID(vm *vm.VirtualMachine) (*string, error) {
127128
if err != nil {
128129
return nil, err
129130
}
130-
return pointer.StringPtr(uuid), nil
131+
return pointer.String(uuid), nil
131132
}
132133

133134
func convertSMBiosToUUID(smbios string) (string, error) {
@@ -140,29 +141,6 @@ func convertSMBiosToUUID(smbios string) (string, error) {
140141
return strings.Split(match, "=")[1], nil
141142
}
142143

143-
// will be abolished
144-
func (s *Service) getInstanceFromInstanceID(instanceID string) (*vm.VirtualMachine, error) {
145-
vmid, err := strconv.Atoi(instanceID)
146-
if err != nil {
147-
return nil, err
148-
}
149-
nodes, err := s.client.Nodes()
150-
if err != nil {
151-
return nil, err
152-
}
153-
if len(nodes) == 0 {
154-
return nil, errors.New("proxmox nodes not found")
155-
}
156-
for _, node := range nodes {
157-
vm, err := node.VirtualMachine(vmid)
158-
if err != nil {
159-
continue
160-
}
161-
return vm, nil
162-
}
163-
return nil, api.ErrNotFound
164-
}
165-
166144
func (s *Service) getInstanceFromBiosUUID(uuid string) (*vm.VirtualMachine, error) {
167145
nodes, err := s.client.Nodes()
168146
if err != nil {

cloud/services/compute/storage/reconcile.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package storage
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67

78
"github.com/sp-yduck/proxmox/pkg/api"
@@ -28,11 +29,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
2829
}
2930

3031
func (s *Service) Delete(ctx context.Context) error {
31-
// return s.deleteStorage(ctx)
32-
// not worthy to delete Storage
33-
// since deleting Storage will block vm deletion
34-
// and does not delete actual content in the node
35-
return nil
32+
return s.deleteStorage(ctx)
3633
}
3734

3835
// createOrGetStorage gets Proxmox Storage for VMs
@@ -77,6 +74,17 @@ func (s *Service) deleteStorage(ctx context.Context) error {
7774
log.Info(err.Error())
7875
continue
7976
}
77+
78+
// check if storage is empty
79+
contents, err := storage.Contents()
80+
if err != nil {
81+
return err
82+
}
83+
if len(contents) > 0 {
84+
return errors.New("Storage must be empty to be deleted")
85+
}
86+
87+
// delete
8088
if _, err := storage.Delete(); err != nil {
8189
log.Info(err.Error())
8290
return err

0 commit comments

Comments
 (0)