-
Notifications
You must be signed in to change notification settings - Fork 217
/
lvm_operator.go
217 lines (185 loc) · 8.1 KB
/
lvm_operator.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package lvm
import (
"context"
"fmt"
"github.com/go-openapi/swag"
"github.com/kelseyhightower/envconfig"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/operators/api"
operatorscommon "github.com/openshift/assisted-service/internal/operators/common"
"github.com/openshift/assisted-service/models"
logutil "github.com/openshift/assisted-service/pkg/log"
"github.com/sirupsen/logrus"
)
// operator is an ODF LVM OLM operator plugin; it implements api.Operator
type operator struct {
log logrus.FieldLogger
Config *Config
}
const defaultStorageClassName = "lvms-" + defaultDeviceName
var Operator = models.MonitoredOperator{
Name: "lvm",
OperatorType: models.OperatorTypeOlm,
Namespace: "openshift-storage",
SubscriptionName: "",
TimeoutSeconds: 30 * 60,
}
// NewLvmOperator creates new LvmOperator
func NewLvmOperator(log logrus.FieldLogger) *operator {
cfg := Config{}
err := envconfig.Process(common.EnvConfigPrefix, &cfg)
if err != nil {
log.Fatal(err.Error())
}
return newLvmOperatorWithConfig(log, &cfg)
}
// newOdfOperatorWithConfig creates new ODFOperator with given configuration
func newLvmOperatorWithConfig(log logrus.FieldLogger, config *Config) *operator {
return &operator{
log: log,
Config: config,
}
}
// GetName reports the name of an operator this Operator manages
func (o *operator) GetName() string {
return Operator.Name
}
func (o *operator) GetFullName() string {
return "Logical Volume Management"
}
func (o *operator) StorageClassName() string {
return defaultStorageClassName
}
// GetDependencies provides a list of dependencies of the Operator
func (o *operator) GetDependencies(cluster *common.Cluster) ([]string, error) {
return make([]string, 0), nil
}
// GetClusterValidationID returns cluster validation ID for the Operator
func (o *operator) GetClusterValidationID() string {
return string(models.ClusterValidationIDLvmRequirementsSatisfied)
}
// GetHostValidationID returns host validation ID for the Operator
func (o *operator) GetHostValidationID() string {
return string(models.HostValidationIDLvmRequirementsSatisfied)
}
// ValidateCluster always return "valid" result
func (o *operator) ValidateCluster(_ context.Context, cluster *common.Cluster) (api.ValidationResult, error) {
if ok, _ := common.BaseVersionLessThan(LvmoMinOpenshiftVersion, cluster.OpenshiftVersion); ok {
message := fmt.Sprintf("Logical Volume Manager is only supported for openshift versions %s and above", LvmoMinOpenshiftVersion)
return api.ValidationResult{Status: api.Failure, ValidationId: o.GetClusterValidationID(), Reasons: []string{message}}, nil
}
if swag.StringValue(cluster.HighAvailabilityMode) == models.ClusterHighAvailabilityModeFull {
if ok, _ := common.BaseVersionLessThan(LvmMinMultiNodeSupportVersion, cluster.OpenshiftVersion); ok {
message := fmt.Sprintf("Logical Volume Manager is only supported for highly available openshift with version %s or above", LvmMinMultiNodeSupportVersion)
return api.ValidationResult{Status: api.Failure, ValidationId: o.GetHostValidationID(), Reasons: []string{message}}, nil
}
}
return api.ValidationResult{Status: api.Success, ValidationId: o.GetClusterValidationID()}, nil
}
// ValidateHost always return "valid" result
func (o *operator) ValidateHost(ctx context.Context, cluster *common.Cluster, host *models.Host, additionalOperatorRequirements *models.ClusterHostRequirementsDetails) (api.ValidationResult, error) {
if host.Inventory == "" {
message := "Missing Inventory in the host"
return api.ValidationResult{Status: api.Pending, ValidationId: o.GetHostValidationID(), Reasons: []string{message}}, nil
}
inventory, err := common.UnmarshalInventory(host.Inventory)
if err != nil {
message := "Failed to get inventory from host"
return api.ValidationResult{Status: api.Failure, ValidationId: o.GetHostValidationID(), Reasons: []string{message}}, err
}
minDiskSizeGb := int64(0)
if additionalOperatorRequirements != nil {
minDiskSizeGb = additionalOperatorRequirements.DiskSizeGb
}
diskCount, _ := operatorscommon.NonInstallationDiskCount(inventory.Disks, host.InstallationDiskID, minDiskSizeGb)
role := common.GetEffectiveRole(host)
areSchedulable := common.ShouldMastersBeSchedulable(&cluster.Cluster)
minSizeMessage := ""
if minDiskSizeGb > 0 {
minSizeMessage = fmt.Sprintf(" of %dGB minimum", minDiskSizeGb)
}
message := fmt.Sprintf("Logical Volume Manager requires at least one non-installation HDD/SSD disk%s on the host", minSizeMessage)
if role == models.HostRoleWorker || areSchedulable {
if diskCount == 0 {
return api.ValidationResult{Status: api.Failure, ValidationId: o.GetHostValidationID(), Reasons: []string{message}}, nil
}
} else {
if role == models.HostRoleAutoAssign {
status := "For Logical Volume Manager Standard Mode, host role must be assigned to master or worker."
return api.ValidationResult{Status: api.Failure, ValidationId: o.GetHostValidationID(), Reasons: []string{status}}, nil
}
}
return api.ValidationResult{Status: api.Success, ValidationId: o.GetHostValidationID()}, nil
}
// GenerateManifests generates manifests for the operator
func (o *operator) GenerateManifests(cluster *common.Cluster) (map[string][]byte, []byte, error) {
return Manifests(cluster)
}
// GetProperties provides description of operator properties: none required
func (o *operator) GetProperties() models.OperatorProperties {
return models.OperatorProperties{}
}
// GetMonitoredOperator returns MonitoredOperator corresponding to the LSO
func (o *operator) GetMonitoredOperator() *models.MonitoredOperator {
return &Operator
}
// GetHostRequirements provides operator's requirements towards the host
func (o *operator) GetHostRequirements(ctx context.Context, cluster *common.Cluster, host *models.Host) (*models.ClusterHostRequirementsDetails, error) {
log := logutil.FromContext(ctx, o.log)
preflightRequirements, err := o.GetPreflightRequirements(ctx, cluster)
if err != nil {
log.WithError(err).Errorf("Cannot retrieve preflight requirements for host %s", host.ID)
return nil, err
}
role := common.GetEffectiveRole(host)
areSchedulable := common.ShouldMastersBeSchedulable(&cluster.Cluster)
if role == models.HostRoleMaster && !areSchedulable {
return &models.ClusterHostRequirementsDetails{
CPUCores: 0,
RAMMib: 0,
}, nil
}
return preflightRequirements.Requirements.Master.Quantitative, nil
}
// GetPreflightRequirements returns operator hardware requirements that can be determined with cluster data only
func (o *operator) GetPreflightRequirements(context context.Context, cluster *common.Cluster) (*models.OperatorHardwareRequirements, error) {
dependecies, err := o.GetDependencies(cluster)
if err != nil {
return &models.OperatorHardwareRequirements{}, err
}
memoryRequirements := o.Config.LvmMemoryPerHostMiB
if ok, _ := common.BaseVersionLessThan(LvmsMinOpenshiftVersion_ForNewResourceRequirements, cluster.OpenshiftVersion); ok {
memoryRequirements = o.Config.LvmMemoryPerHostMiBBefore4_13
}
if ok, _ := common.BaseVersionGreaterOrEqual(LvmNewResourcesOpenshiftVersion4_16, cluster.OpenshiftVersion); ok {
memoryRequirements = o.Config.LvmMemoryPerHostMiBFrom4_16
}
requirementMessage := []string{
"At least 1 non-boot disk per host",
fmt.Sprintf("%d MiB of additional RAM", memoryRequirements),
fmt.Sprintf("%d additional CPUs for each non-boot disk", o.Config.LvmCPUPerHost),
}
return &models.OperatorHardwareRequirements{
OperatorName: o.GetName(),
Dependencies: dependecies,
Requirements: &models.HostTypeHardwareRequirementsWrapper{
Master: &models.HostTypeHardwareRequirements{
Qualitative: requirementMessage,
Quantitative: &models.ClusterHostRequirementsDetails{
CPUCores: o.Config.LvmCPUPerHost,
RAMMib: memoryRequirements,
},
},
Worker: &models.HostTypeHardwareRequirements{
Qualitative: requirementMessage,
Quantitative: &models.ClusterHostRequirementsDetails{
CPUCores: o.Config.LvmCPUPerHost,
RAMMib: memoryRequirements,
},
},
},
}, nil
}
func (o *operator) GetFeatureSupportID() models.FeatureSupportLevelID {
return models.FeatureSupportLevelIDLVM
}