Skip to content

Commit ba9745f

Browse files
committed
added support for self healing node pool fields
1 parent b875ecd commit ba9745f

3 files changed

Lines changed: 73 additions & 5 deletions

rancher2/schema_cluster_v2_rke_config_machine_pool.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ func clusterV2RKEConfigMachinePoolFields() map[string]*schema.Schema {
106106
Optional: true,
107107
Description: "Machine pool worker role",
108108
},
109+
"node_startup_timeout_seconds": {
110+
Type: schema.TypeInt,
111+
Optional: true,
112+
Description: "seconds a new node has to become active before it is replaced",
113+
},
114+
"unhealthy_node_timeout_seconds": {
115+
Type: schema.TypeInt,
116+
Optional: true,
117+
Description: "seconds an unhealthy node has to become active before it is replaced",
118+
},
119+
"max_unhealthy": {
120+
Type: schema.TypeString,
121+
Optional: true,
122+
Description: "max unhealthy nodes for automated replacement to be allowed",
123+
},
124+
"unhealthy_range": {
125+
Type: schema.TypeString,
126+
Optional: true,
127+
Description: "range of unhealthy nodes for automated replacement to be allowed",
128+
},
109129
}
110130

111131
for k, v := range commonAnnotationLabelFields() {

rancher2/structure_cluster_v2_rke_config_machine_pool.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package rancher2
33
import (
44
provisionv1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1"
55
corev1 "k8s.io/api/core/v1"
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
67
"k8s.io/apimachinery/pkg/util/intstr"
8+
"time"
79
)
810

911
// Flatteners
@@ -74,6 +76,19 @@ func flattenClusterV2RKEConfigMachinePools(p []provisionv1.RKEMachinePool) []int
7476
}
7577
obj["worker_role"] = in.WorkerRole
7678
out[i] = obj
79+
80+
if in.NodeStartupTimeout != nil {
81+
obj["node_startup_timeout_seconds"] = int(in.NodeStartupTimeout.Seconds())
82+
}
83+
if in.UnhealthyNodeTimeout != nil {
84+
obj["unhealthy_node_timeout_seconds"] = int(in.UnhealthyNodeTimeout.Seconds())
85+
}
86+
if in.MaxUnhealthy != nil {
87+
obj["max_unhealthy"] = *in.MaxUnhealthy
88+
}
89+
if in.UnhealthyRange != nil {
90+
obj["unhealthy_range"] = *in.UnhealthyRange
91+
}
7792
}
7893

7994
return out
@@ -169,6 +184,21 @@ func expandClusterV2RKEConfigMachinePools(p []interface{}) []provisionv1.RKEMach
169184
if v, ok := in["worker_role"].(bool); ok {
170185
obj.WorkerRole = v
171186
}
187+
if v, ok := in["node_startup_timeout_seconds"].(int); ok && v > 0 {
188+
d := metav1.Duration{Duration: time.Duration(v) * time.Second}
189+
obj.NodeStartupTimeout = &d
190+
}
191+
if v, ok := in["unhealthy_node_timeout_seconds"].(int); ok && v > 0 {
192+
d := metav1.Duration{Duration: time.Duration(v) * time.Second}
193+
obj.UnhealthyNodeTimeout = &d
194+
}
195+
if v, ok := in["max_unhealthy"].(string); ok && len(v) > 0 {
196+
obj.MaxUnhealthy = &v
197+
}
198+
if v, ok := in["unhealthy_range"].(string); ok && len(v) > 0 {
199+
obj.UnhealthyRange = &v
200+
}
201+
172202
out[i] = obj
173203
}
174204

rancher2/structure_cluster_v2_rke_config_machine_pool_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package rancher2
22

33
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
45
"reflect"
56
"testing"
7+
"time"
68

79
provisionv1 "github.com/rancher/rancher/pkg/apis/provisioning.cattle.io/v1"
810
corev1 "k8s.io/api/core/v1"
@@ -58,10 +60,14 @@ func init() {
5860
"label_one": "one",
5961
"label_two": "two",
6062
},
61-
Quantity: &quantity,
62-
Paused: true,
63-
RollingUpdate: testClusterV2RKEConfigMachinePoolRollingUpdateConf,
64-
WorkerRole: true,
63+
Quantity: &quantity,
64+
Paused: true,
65+
RollingUpdate: testClusterV2RKEConfigMachinePoolRollingUpdateConf,
66+
WorkerRole: true,
67+
NodeStartupTimeout: metav1DurationPtr(600),
68+
UnhealthyNodeTimeout: metav1DurationPtr(60),
69+
MaxUnhealthy: stringPtr("2"),
70+
UnhealthyRange: stringPtr("[2,5]"),
6571
},
6672
}
6773
testClusterV2RKEConfigMachinePoolsConf[0].CloudCredentialSecretName = "cloud_credential_secret_name"
@@ -97,7 +103,11 @@ func init() {
97103
"effect": "recipient",
98104
},
99105
},
100-
"worker_role": true,
106+
"worker_role": true,
107+
"node_startup_timeout_seconds": 600,
108+
"unhealthy_node_timeout_seconds": 60,
109+
"max_unhealthy": "2",
110+
"unhealthy_range": "[2,5]",
101111
},
102112
}
103113
}
@@ -227,3 +237,11 @@ func TestExpandClusterV2RKEConfigMachinePools(t *testing.T) {
227237
}
228238
}
229239
}
240+
241+
func stringPtr(s string) *string {
242+
return &s
243+
}
244+
245+
func metav1DurationPtr(seconds int64) *metav1.Duration {
246+
return &metav1.Duration{Duration: time.Duration(seconds) * time.Second}
247+
}

0 commit comments

Comments
 (0)