This repository has been archived by the owner on Feb 3, 2022. It is now read-only.
/
volume.go
56 lines (45 loc) · 1.63 KB
/
volume.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package scope
import (
"github.com/pkg/errors"
"sigs.k8s.io/cluster-api/util/patch"
infrav1 "github.com/simonswine/cluster-api-provider-hcloud/api/v1alpha3"
)
// ClusterScopeParams defines the input parameters used to create a new Scope.
type VolumeScopeParams struct {
ClusterScopeParams
HcloudVolume *infrav1.HcloudVolume
}
// NewClusterScope creates a new Scope from the supplied parameters.
// This is meant to be called for each reconcile iteration.
func NewVolumeScope(params VolumeScopeParams) (*VolumeScope, error) {
if params.HcloudVolume == nil {
return nil, errors.New("failed to generate new scope from nil HcloudVolume")
}
cs, err := NewClusterScope(params.ClusterScopeParams)
if err != nil {
return nil, errors.Wrap(err, "failed to init patch helper")
}
cs.patchHelper, err = patch.NewHelper(params.HcloudVolume, params.Client)
if err != nil {
return nil, errors.Wrap(err, "failed to init patch helper")
}
return &VolumeScope{
ClusterScope: *cs,
HcloudVolume: params.HcloudVolume,
}, nil
}
// ClusterScope defines the basic context for an actuator to operate upon.
type VolumeScope struct {
ClusterScope
HcloudVolume *infrav1.HcloudVolume
}
// Close closes the current scope persisting the cluster configuration and status.
func (s *VolumeScope) Close() error {
return s.patchHelper.Patch(s.Ctx, s.HcloudVolume)
}
func (s *VolumeScope) GetSpecLocations() []infrav1.HcloudLocation {
return []infrav1.HcloudLocation{s.HcloudVolume.Spec.Location}
}
func (s *VolumeScope) SetStatusLocations(location []infrav1.HcloudLocation, networkZone infrav1.HcloudNetworkZone) {
s.HcloudVolume.Status.Location = location[0]
}