-
Notifications
You must be signed in to change notification settings - Fork 15
/
constraints.go
49 lines (43 loc) · 1.43 KB
/
constraints.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
package cke
import "errors"
// Constraints is a set of conditions that a cluster must satisfy
type Constraints struct {
ControlPlaneCount int `json:"control-plane-count"`
MinimumWorkers int `json:"minimum-workers"`
MaximumWorkers int `json:"maximum-workers"`
RebootMaximumUnreachable int `json:"maximum-unreachable-nodes-for-reboot"`
MaximumRepairs int `json:"maximum-repair-queue-entries"`
RepairRebootingSeconds int `json:"wait-seconds-to-repair-rebooting"`
}
// Check checks the cluster satisfies the constraints
func (c *Constraints) Check(cluster *Cluster) error {
cpCount := 0
nodeCount := len(cluster.Nodes)
for _, n := range cluster.Nodes {
if n.ControlPlane {
cpCount++
}
}
if cpCount != c.ControlPlaneCount {
return errors.New("number of control planes is not equal to the constraint")
}
workerCount := nodeCount - cpCount
if c.MaximumWorkers != 0 && workerCount > c.MaximumWorkers {
return errors.New("number of worker nodes exceeds the maximum")
}
if workerCount < c.MinimumWorkers {
return errors.New("number of worker nodes is less than the minimum")
}
return nil
}
// DefaultConstraints returns the default constraints
func DefaultConstraints() *Constraints {
return &Constraints{
ControlPlaneCount: 1,
MinimumWorkers: 1,
MaximumWorkers: 0,
RebootMaximumUnreachable: 0,
MaximumRepairs: 0,
RepairRebootingSeconds: 0,
}
}