Skip to content

Commit 8fc284c

Browse files
committed
fix storage reconciler
1 parent 99ee374 commit 8fc284c

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

cloud/interfaces.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ type ClusterGetter interface {
3838
// FailureDomains() clusterv1.FailureDomains
3939
ControlPlaneEndpoint() clusterv1.APIEndpoint
4040
Storage() infrav1.Storage
41+
LoadBalancer() infrav1.LoadBalancer
4142
}
4243

4344
type ClusterSettter interface {
4445
SetControlPlaneEndpoint(endpoint clusterv1.APIEndpoint)
46+
SetStorage(storage infrav1.Storage)
4547
}
4648

4749
// MachineGetter is an interface which can get machine information.

cloud/scope/cluster.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ func (s *ClusterScope) Storage() infrav1.Storage {
9797
return s.ProxmoxCluster.Spec.Storage
9898
}
9999

100+
func (s *ClusterScope) LoadBalancer() infrav1.LoadBalancer {
101+
return s.ProxmoxCluster.Spec.LoadBalancer
102+
}
103+
100104
func (s *ClusterScope) CloudClient() *service.Service {
101105
return s.ProxmoxServices.Compute
102106
}
@@ -117,6 +121,10 @@ func (s *ClusterScope) SetControlPlaneEndpoint(endpoint clusterv1.APIEndpoint) {
117121
s.ProxmoxCluster.Spec.ControlPlaneEndpoint = endpoint
118122
}
119123

124+
func (s *ClusterScope) SetStorage(storage infrav1.Storage) {
125+
s.ProxmoxCluster.Spec.Storage = storage
126+
}
127+
120128
// PatchObject persists the cluster configuration and status.
121129
func (s *ClusterScope) PatchObject() error {
122130
return s.patchHelper.Patch(context.TODO(), s.ProxmoxCluster)

cloud/services/compute/storage/reconcile.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,49 @@ func (s *Service) Delete(ctx context.Context) error {
3131
func (s *Service) createOrGetStorage(ctx context.Context) error {
3232
log := log.FromContext(ctx)
3333
log.Info("Reconciling vm storage")
34-
if err := s.getStorage(); err != nil {
34+
35+
opts := generateVMStorageOptions(s.scope)
36+
if err := s.getStorage(opts.Storage); err != nil {
3537
if api.IsNotFound(err) {
36-
if err := s.createStorage(); err != nil {
38+
if err := s.createStorage(opts); err != nil {
3739
return err
3840
}
3941
}
4042
return err
4143
}
44+
45+
s.scope.SetStorage(infrav1.Storage{Name: opts.Storage, Path: opts.Path})
4246
return nil
4347
}
4448

45-
func (s *Service) getStorage() error {
46-
storageSpec := s.scope.Storage()
47-
if _, err := s.client.Storage(storageSpec.Name); err != nil {
49+
func (s *Service) getStorage(name string) error {
50+
if _, err := s.client.Storage(name); err != nil {
4851
return err
4952
}
5053
return nil
5154
}
5255

53-
func (s *Service) createStorage() error {
54-
storageSpec := s.scope.Storage()
55-
opts := storage.StorageCreateOptions{
56-
Content: "images,snippets",
57-
Mkdir: true,
58-
Path: generateStoragePath(storageSpec),
59-
}
60-
if _, err := s.client.CreateStorage(storageSpec.Name, "dif", opts); err != nil {
56+
func (s *Service) createStorage(options storage.StorageCreateOptions) error {
57+
if _, err := s.client.CreateStorage(options.Storage, options.StorageType, options); err != nil {
6158
return err
6259
}
6360
return nil
6461
}
6562

66-
func generateStoragePath(storage infrav1.Storage) string {
67-
if storage.Path == "" {
68-
return fmt.Sprintf("%s/%s", defaultBasePath, storage.Name)
69-
}
70-
return storage.Path
71-
}
72-
73-
func defaultVMStorageOptions(name string) storage.StorageCreateOptions {
63+
func generateVMStorageOptions(scope Scope) storage.StorageCreateOptions {
64+
storageSpec := scope.Storage()
7465
options := storage.StorageCreateOptions{
75-
Content: "images,snippets",
76-
Mkdir: true,
77-
Path: defaultBasePath + "/" + name,
66+
Storage: storageSpec.Name,
67+
StorageType: "dir",
68+
Content: "images,snippets",
69+
Mkdir: true,
70+
Path: storageSpec.Path,
71+
}
72+
if options.Storage == "" {
73+
options.Storage = fmt.Sprintf("local-dir-%s", scope.Name())
74+
}
75+
if options.Path == "" {
76+
options.Path = fmt.Sprintf("%s/%s", defaultBasePath, options.Storage)
7877
}
7978
return options
8079
}

0 commit comments

Comments
 (0)