Skip to content

Commit ec02d57

Browse files
authored
Merge pull request #48 from sp-yduck/proxmox-go
proxmox sdk / latest ccm
2 parents 006acd9 + 9c45a4d commit ec02d57

File tree

16 files changed

+168
-226
lines changed

16 files changed

+168
-226
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ clusterctl init --infrastructure=proxmox:v0.2.2 --config https://raw.githubuserc
2424
2. Create your first workload cluster
2525
```sh
2626
# export env variables
27-
export CONTROLPLANE_HOST=X.X.X.X # control-plane vip
28-
export PROXMOX_URL=X.X.X.X:8006
29-
export PROXMOX_PASSWORD=password
30-
export PROXMOX_USER=user@pam
27+
export CONTROLPLANE_HOST=X.X.X.X # control-plane vip
28+
export PROXMOX_URL=https://X.X.X.X:8006/api2/json
29+
# export PROXMOX_PASSWORD=password # (optional)
30+
# export PROXMOX_USER=user@pam # (optional)
31+
export PROXMOX_TOKENID='root@pam!api-token-id' # (optional)
32+
export PROXMOX_SECRET=aaaaaaaa-bbbb-cccc-dddd-ee12345678 # (optional)
3133
export NODE_URL=node.ssh.url:22
3234
export NODE_USER=node-ssh-user
3335
export NODE_PASSWORD=node-ssh-password
3436

35-
# generate manifests (available flags: --target-namespace, --kubernetes-version, --controlplane-machine-count, --worker-machine-count)
36-
clusterctl generate cluster cappx-test --worker-machine-count=3 --infrastructure=proxmox:v0.2.2 --config https://raw.githubusercontent.com/sp-yduck/cluster-api-provider-proxmox/main/clusterctl.yaml > cappx-test.yaml
37+
# generate manifests (available flags: --target-namespace, --kubernetes-version, --control-plane-machine-count, --worker-machine-count)
38+
clusterctl generate cluster cappx-test --control-plane-machine-count=3 --infrastructure=proxmox:v0.2.2 --config https://raw.githubusercontent.com/sp-yduck/cluster-api-provider-proxmox/main/clusterctl.yaml > cappx-test.yaml
3739

3840
# inspect and edit
3941
vi cappx-test.yaml

api/v1beta1/type.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/sp-yduck/proxmox/pkg/service/node/vm"
7+
"github.com/sp-yduck/proxmox-go/api"
88
)
99

1010
// ServerRef is used for configuring Proxmox client
@@ -127,7 +127,7 @@ type Storage struct {
127127
type InstanceStatus string
128128

129129
var (
130-
InstanceStatusPaused = InstanceStatus(vm.ProcessStatusPaused)
131-
InstanceStatusRunning = InstanceStatus(vm.ProcessStatusRunning)
132-
InstanceStatusStopped = InstanceStatus(vm.ProcessStatusStopped)
130+
InstanceStatusPaused = InstanceStatus(api.ProcessStatusPaused)
131+
InstanceStatusRunning = InstanceStatus(api.ProcessStatusRunning)
132+
InstanceStatusStopped = InstanceStatus(api.ProcessStatusStopped)
133133
)

cloud/interfaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cloud
33
import (
44
"context"
55

6-
"github.com/sp-yduck/proxmox/pkg/service"
6+
"github.com/sp-yduck/proxmox-go/proxmox"
77
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
88

99
infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
@@ -16,7 +16,7 @@ type Reconciler interface {
1616
}
1717

1818
type Client interface {
19-
CloudClient() *service.Service
19+
CloudClient() *proxmox.Service
2020
RemoteClient() *scope.SSHClient
2121
}
2222

cloud/scope/clients.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ import (
2020
"context"
2121

2222
"github.com/pkg/errors"
23-
"github.com/sp-yduck/proxmox/pkg/service"
23+
"github.com/sp-yduck/proxmox-go/proxmox"
2424
corev1 "k8s.io/api/core/v1"
2525
"sigs.k8s.io/controller-runtime/pkg/client"
2626

2727
infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
2828
)
2929

3030
type ProxmoxServices struct {
31-
Compute *service.Service
31+
Compute *proxmox.Service
3232
Remote *SSHClient
3333
}
3434

35-
func newComputeService(ctx context.Context, serverRef infrav1.ServerRef, crClient client.Client) (*service.Service, error) {
35+
func newComputeService(ctx context.Context, serverRef infrav1.ServerRef, crClient client.Client) (*proxmox.Service, error) {
3636
secretRef := serverRef.SecretRef
3737
if secretRef == nil {
3838
return nil, errors.New("failed to get proxmox client form nil secretRef")
@@ -44,16 +44,14 @@ func newComputeService(ctx context.Context, serverRef infrav1.ServerRef, crClien
4444
return nil, err
4545
}
4646

47-
proxmoxUser, ok := secret.Data["PROXMOX_USER"]
48-
if !ok {
49-
return nil, errors.Errorf("failed to fetch PROXMOX_USER from Secret : %v", key)
50-
}
51-
proxmoxPassword, ok := secret.Data["PROXMOX_PASSWORD"]
52-
if !ok {
53-
return nil, errors.Errorf("failed to fetch PROXMOX_PASSWORD from Secret : %v", key)
47+
authConfig := proxmox.AuthConfig{
48+
Username: string(secret.Data["PROXMOX_USER"]),
49+
Password: string(secret.Data["PROXMOX_PASSWORD"]),
50+
TokenID: string(secret.Data["PROXMOX_TOKENID"]),
51+
Secret: string(secret.Data["PROXMOX_SECRET"]),
5452
}
5553

56-
return service.NewServiceWithLogin(serverRef.Endpoint, string(proxmoxUser), string(proxmoxPassword))
54+
return proxmox.NewService(serverRef.Endpoint, authConfig, true)
5755
}
5856

5957
func newRemoteClient(ctx context.Context, secretRef *infrav1.ObjectReference, crClient client.Client) (*SSHClient, error) {

cloud/scope/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import (
2020
"context"
2121

2222
"github.com/pkg/errors"
23+
"github.com/sp-yduck/proxmox-go/proxmox"
2324
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2425
"sigs.k8s.io/cluster-api/util/patch"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
2627

2728
infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
28-
"github.com/sp-yduck/proxmox/pkg/service"
2929
)
3030

3131
type ClusterScopeParams struct {
@@ -110,7 +110,7 @@ func (s *ClusterScope) Storage() infrav1.Storage {
110110
return s.ProxmoxCluster.Spec.Storage
111111
}
112112

113-
func (s *ClusterScope) CloudClient() *service.Service {
113+
func (s *ClusterScope) CloudClient() *proxmox.Service {
114114
return s.ProxmoxServices.Compute
115115
}
116116

cloud/scope/machine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/pkg/errors"
23+
"github.com/sp-yduck/proxmox-go/proxmox"
2324
corev1 "k8s.io/api/core/v1"
2425
"k8s.io/apimachinery/pkg/types"
2526
"k8s.io/utils/pointer"
@@ -31,7 +32,6 @@ import (
3132

3233
infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
3334
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/providerid"
34-
"github.com/sp-yduck/proxmox/pkg/service"
3535
)
3636

3737
type MachineScopeParams struct {
@@ -78,7 +78,7 @@ type MachineScope struct {
7878
ClusterGetter *ClusterScope
7979
}
8080

81-
func (m *MachineScope) CloudClient() *service.Service {
81+
func (m *MachineScope) CloudClient() *proxmox.Service {
8282
return m.ClusterGetter.CloudClient()
8383
}
8484

cloud/services/compute/instance/cloudinit.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package instance
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/pkg/errors"
@@ -24,28 +25,21 @@ func (s *Service) reconcileCloudInit(bootstrap string) error {
2425
}
2526

2627
// delete CloudConfig
27-
func (s *Service) deleteCloudConfig() error {
28+
func (s *Service) deleteCloudConfig(ctx context.Context) error {
2829
storageName := s.scope.GetStorage().Name
2930
path := userSnippetPath(s.scope.Name())
3031
volumeID := fmt.Sprintf("%s:%s", storageName, path)
3132

32-
node, err := s.client.Node(s.scope.NodeName())
33+
node, err := s.client.Node(ctx, s.scope.NodeName())
3334
if err != nil {
3435
return err
3536
}
36-
storage, err := node.Storage(storageName)
37+
storage, err := s.client.Storage(ctx, storageName)
3738
if err != nil {
3839
return err
3940
}
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()
41+
storage.Node = node.Node
42+
return storage.DeleteVolume(ctx, volumeID)
4943
}
5044

5145
func (s *Service) reconcileCloudInitUser(bootstrap string) error {

cloud/services/compute/instance/image.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"strings"
88

99
"github.com/pkg/errors"
10-
"github.com/sp-yduck/proxmox/pkg/service/node/vm"
10+
"github.com/sp-yduck/proxmox-go/proxmox"
1111
"sigs.k8s.io/controller-runtime/pkg/log"
1212

1313
infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
1414
"github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scope"
1515
)
1616

1717
// reconcileBootDevice
18-
func (s *Service) reconcileBootDevice(ctx context.Context, vm *vm.VirtualMachine) error {
18+
func (s *Service) reconcileBootDevice(ctx context.Context, vm *proxmox.VirtualMachine) error {
1919
vmid := s.scope.GetVMID()
2020
storage := s.scope.GetStorage()
2121
image := s.scope.GetImage()
@@ -24,12 +24,12 @@ func (s *Service) reconcileBootDevice(ctx context.Context, vm *vm.VirtualMachine
2424
log.Info(fmt.Sprintf("%v", hardware))
2525

2626
// os image
27-
if err := SetCloudImage(ctx, *vmid, storage, image, s.remote); err != nil {
27+
if err := setCloudImage(ctx, *vmid, storage, image, s.remote); err != nil {
2828
return err
2929
}
3030

3131
// volume
32-
if err := vm.ResizeVolume("scsi0", hardware.Disk); err != nil {
32+
if err := vm.ResizeVolume(ctx, "scsi0", hardware.Disk); err != nil {
3333
return err
3434
}
3535

@@ -38,7 +38,7 @@ func (s *Service) reconcileBootDevice(ctx context.Context, vm *vm.VirtualMachine
3838

3939
// setCloudImage downloads OS image into Proxmox node
4040
// and then sets it to specified storage
41-
func SetCloudImage(ctx context.Context, vmid int, storage infrav1.Storage, image infrav1.Image, ssh scope.SSHClient) error {
41+
func setCloudImage(ctx context.Context, vmid int, storage infrav1.Storage, image infrav1.Image, ssh scope.SSHClient) error {
4242
log := log.FromContext(ctx)
4343
log.Info("setting cloud image")
4444

0 commit comments

Comments
 (0)