Skip to content

Commit 37e2c28

Browse files
authored
Merge pull request #889 from paynejacob/issue-874
2 parents 2c78ba4 + ba9745f commit 37e2c28

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
@@ -112,6 +112,26 @@ func clusterV2RKEConfigMachinePoolFields() map[string]*schema.Schema {
112112
Optional: true,
113113
Description: "Machine pool worker role",
114114
},
115+
"node_startup_timeout_seconds": {
116+
Type: schema.TypeInt,
117+
Optional: true,
118+
Description: "seconds a new node has to become active before it is replaced",
119+
},
120+
"unhealthy_node_timeout_seconds": {
121+
Type: schema.TypeInt,
122+
Optional: true,
123+
Description: "seconds an unhealthy node has to become active before it is replaced",
124+
},
125+
"max_unhealthy": {
126+
Type: schema.TypeString,
127+
Optional: true,
128+
Description: "max unhealthy nodes for automated replacement to be allowed",
129+
},
130+
"unhealthy_range": {
131+
Type: schema.TypeString,
132+
Optional: true,
133+
Description: "range of unhealthy nodes for automated replacement to be allowed",
134+
},
115135
}
116136

117137
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
@@ -75,6 +77,19 @@ func flattenClusterV2RKEConfigMachinePools(p []provisionv1.RKEMachinePool) []int
7577
}
7678
obj["worker_role"] = in.WorkerRole
7779
out[i] = obj
80+
81+
if in.NodeStartupTimeout != nil {
82+
obj["node_startup_timeout_seconds"] = int(in.NodeStartupTimeout.Seconds())
83+
}
84+
if in.UnhealthyNodeTimeout != nil {
85+
obj["unhealthy_node_timeout_seconds"] = int(in.UnhealthyNodeTimeout.Seconds())
86+
}
87+
if in.MaxUnhealthy != nil {
88+
obj["max_unhealthy"] = *in.MaxUnhealthy
89+
}
90+
if in.UnhealthyRange != nil {
91+
obj["unhealthy_range"] = *in.UnhealthyRange
92+
}
7893
}
7994

8095
return out
@@ -173,6 +188,21 @@ func expandClusterV2RKEConfigMachinePools(p []interface{}) []provisionv1.RKEMach
173188
if v, ok := in["worker_role"].(bool); ok {
174189
obj.WorkerRole = v
175190
}
191+
if v, ok := in["node_startup_timeout_seconds"].(int); ok && v > 0 {
192+
d := metav1.Duration{Duration: time.Duration(v) * time.Second}
193+
obj.NodeStartupTimeout = &d
194+
}
195+
if v, ok := in["unhealthy_node_timeout_seconds"].(int); ok && v > 0 {
196+
d := metav1.Duration{Duration: time.Duration(v) * time.Second}
197+
obj.UnhealthyNodeTimeout = &d
198+
}
199+
if v, ok := in["max_unhealthy"].(string); ok && len(v) > 0 {
200+
obj.MaxUnhealthy = &v
201+
}
202+
if v, ok := in["unhealthy_range"].(string); ok && len(v) > 0 {
203+
obj.UnhealthyRange = &v
204+
}
205+
176206
out[i] = obj
177207
}
178208

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"
@@ -59,10 +61,14 @@ func init() {
5961
"label_one": "one",
6062
"label_two": "two",
6163
},
62-
Quantity: &quantity,
63-
Paused: true,
64-
RollingUpdate: testClusterV2RKEConfigMachinePoolRollingUpdateConf,
65-
WorkerRole: true,
64+
Quantity: &quantity,
65+
Paused: true,
66+
RollingUpdate: testClusterV2RKEConfigMachinePoolRollingUpdateConf,
67+
WorkerRole: true,
68+
NodeStartupTimeout: metav1DurationPtr(600),
69+
UnhealthyNodeTimeout: metav1DurationPtr(60),
70+
MaxUnhealthy: stringPtr("2"),
71+
UnhealthyRange: stringPtr("[2,5]"),
6672
},
6773
}
6874
testClusterV2RKEConfigMachinePoolsConf[0].CloudCredentialSecretName = "cloud_credential_secret_name"
@@ -99,7 +105,11 @@ func init() {
99105
"effect": "recipient",
100106
},
101107
},
102-
"worker_role": true,
108+
"worker_role": true,
109+
"node_startup_timeout_seconds": 600,
110+
"unhealthy_node_timeout_seconds": 60,
111+
"max_unhealthy": "2",
112+
"unhealthy_range": "[2,5]",
103113
},
104114
}
105115
}
@@ -229,3 +239,11 @@ func TestExpandClusterV2RKEConfigMachinePools(t *testing.T) {
229239
}
230240
}
231241
}
242+
243+
func stringPtr(s string) *string {
244+
return &s
245+
}
246+
247+
func metav1DurationPtr(seconds int64) *metav1.Duration {
248+
return &metav1.Duration{Duration: time.Duration(seconds) * time.Second}
249+
}

0 commit comments

Comments
 (0)