forked from rook/rook
-
Notifications
You must be signed in to change notification settings - Fork 9
/
cluster.go
101 lines (87 loc) · 3.03 KB
/
cluster.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
/*
Copyright 2019 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1
import (
"fmt"
)
const (
DeploymentRtlfs = "rtlfs"
DeploymentRtrd = "rtrd"
DeploymentAutoRtlfs = "autoRtlfs"
)
type ClusterDeploymentConfig struct {
DeploymentType string //rtlfs, rtrd, autortlfs
TransportKey string //rtlfs or rtrd
Directories []RtlfsDevice //cluster wide directories
DevConfig map[string]DevicesConfig
NeedPrivileges bool
}
// GetRtlfsDevices returns array of Rtlfs devices in cluster,
// Rtlfs devices must be the same over the cluster configuration,
// so we can get first non gateway deviceConfig
func (deploymentConfig *ClusterDeploymentConfig) GetRtlfsDevices() []RtlfsDevice {
rtlfsDevices := make([]RtlfsDevice, 0)
for _, devConfig := range deploymentConfig.DevConfig {
if !devConfig.IsGatewayNode {
return devConfig.Rtlfs.Devices
}
}
return rtlfsDevices
}
func (deploymentConfig *ClusterDeploymentConfig) CompatibleWith(newConfig ClusterDeploymentConfig) (bool, error) {
if deploymentConfig.DeploymentType != newConfig.DeploymentType {
return false, fmt.Errorf("DeploymentType `%s` != `%s` for updated cluster configuration", deploymentConfig.DeploymentType, newConfig.DeploymentType)
}
if deploymentConfig.TransportKey != newConfig.TransportKey {
return false, fmt.Errorf("TransportKey `%s` != `%s` for updated cluster configuration", deploymentConfig.TransportKey, newConfig.TransportKey)
}
return true, nil
}
// NodesDifference produces A\B for set of node names
// In case of
// A: existing cluster configuration
// B: updated cluster configuration
// A\B -> nodes to delete from cluster
// B\A -> nodes to add to cluster
func (deploymentConfig *ClusterDeploymentConfig) NodesDifference(B ClusterDeploymentConfig) []string {
difference := make([]string, 0)
for nodeName := range deploymentConfig.DevConfig {
if _, ok := B.DevConfig[nodeName]; !ok {
difference = append(difference, nodeName)
}
}
return difference
}
type DevicesConfig struct {
Rtrd RTDevices
RtrdSlaves []RTDevices
Rtlfs RtlfsDevices
Zone int
IsGatewayNode bool
}
// GetRtrdDeviceCount returns all rtrd's devices count on specific node
func (dc *DevicesConfig) GetRtrdDeviceCount() int {
count := len(dc.Rtrd.Devices)
if count > 0 {
for _, rtrdSlave := range dc.RtrdSlaves {
count += len(rtrdSlave.Devices)
}
}
return count
}
type DevicesResurrectOptions struct {
NeedToResurrect bool
NeedToZap bool
NeedToWait bool
SlaveContainers int
}